How can I connect the JSON Bridge with Python code?

Asked by Radhesh Joshi · SOLVED
1 reply 810 views Jump to solution Reply
Radhesh Joshi Original Post
Strategy Builder

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?

Posted Jul 7
Reply

    1 Reply

    Support AlgoDelta
    Support AlgoDelta AlgoDelta Support ·

    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.

    Verified Solution
    • Appreciate the effort you put into explaining it with a real example. Now I can be able to connect the python code with the Json Bridge. Thanks! – Radhesh Joshi Jul 28
    Markdown supported · ```json for code blocks · paste or drop screenshots

    Be specific and kind. Never share API keys, passwords or personal account details.

    Welcome to the community

    Log in or create your account in under a minute.

    1. 1Mobile
    2. 2E-mail
    3. 3Password
    +91

    Have a password?

    By continuing you agree to the community guidelines. We’ll send a one-time code by SMS.