Home › Forums › General Questions › How can I connect the JSON Bridge with Python code?
How can I connect the JSON Bridge with Python code?
-
AuthorPosts
-
-
I am a developer and have built my own strategy in Python that monitors NIFTY.
I have already generated the JSON syntax from the AlgoDeltaβs JSON Bridge.
Now what I want is that whenever my Python code generates a Buy signal, the Buy JSON syntax should be sent to AlgoDelta, and whenever a Sell signal comes, the Sell JSON syntax should be sent automatically.
How can I achieve this?
-
Keymaster
Yes sir, you can definitely do that.
The JSON Bridge is designed exactly for this type of integration.
You simply need to generate your JSON syntax from the JSON Bridge and send the appropriate JSON payload to the JSON Bridge webhook whenever your strategy conditions are satisfied.
For example, suppose you have generated the following syntaxes.
Buy Signal Syntax:
{ "type": "strategy_order", "exit_on_opposite": true, "is_tgt": false, "is_sl": false, "is_trail_set": false, "position_size": "{{strategy.position_size}}", "transaction_type": "BUY", "script_type": "CE", "is_rollover": false, "option_selection": "ATM_BASED", "script": "NIFTY-N", "atm_gap": 0, "expiry_gap": 0, "expiry_type": "weekly", "product": "CARRYFORWARD", "quantity": 1 }Sell Signal Syntax:
{ "type": "strategy_order", "exit_on_opposite": true, "is_tgt": false, "is_sl": false, "is_trail_set": false, "position_size": "{{strategy.position_size}}", "transaction_type": "BUY", "script_type": "PE", "is_rollover": false, "option_selection": "ATM_BASED", "script": "NIFTY-N", "atm_gap": 0, "expiry_gap": 0, "expiry_type": "weekly", "product": "CARRYFORWARD", "quantity": 1 }Then you can integrate it with Python like below:Β
import requests WEBHOOK_URL = "https://apiv4.algodelta.com/api/v4/users/jsonbridge/webhook/212602030/0b73f099933" BUY_JSON = { "type": "strategy_order", "exit_on_opposite": True, "is_tgt": False, "is_sl": False, "is_trail_set": False, "position_size": "{{strategy.position_size}}", "transaction_type": "BUY", "script_type": "CE", "is_rollover": False, "option_selection": "ATM_BASED", "script": "NIFTY-N", "atm_gap": 0, "expiry_gap": 0, "expiry_type": "weekly", "product": "CARRYFORWARD", "quantity": 1 } SELL_JSON = { "type": "strategy_order", "exit_on_opposite": True, "is_tgt": False, "is_sl": False, "is_trail_set": False, "position_size": "{{strategy.position_size}}", "transaction_type": "BUY", "script_type": "PE", "is_rollover": False, "option_selection": "ATM_BASED", "script": "NIFTY-N", "atm_gap": 0, "expiry_gap": 0, "expiry_type": "weekly", "product": "CARRYFORWARD", "quantity": 1 } def send_signal(payload): response = requests.post( WEBHOOK_URL, json=payload ) print(response.status_code) print(response.text) if buy_signal: send_signal(BUY_JSON) elif sell_signal: send_signal(SELL_JSON)That’s it.
Now whenever your Python strategy generates a Buy signal, the Call Option syntax will be executed automatically.
Similarly, whenever a Sell signal is generated, the Put Option syntax will be sent to AlgoDelta and executed.
This is one of the easiest ways to integrate your Python strategies directly with AlgoDelta’s JSON Bridge.
-
-
AuthorPosts
