Understanding Multi-Leg Orders and Their Differences from Multi Order API

What is a Multi-Leg Order and how is it different from the Multi Order API (Bracket Order)?

A Multi-Leg Order is a feature that allows users to execute multiple legs simultaneously, providing hedging benefits and ensuring that all legs of the order are executed together. This differs from the Multi Order API, where each leg is sent to the exchange one by one. If any leg is rejected in the Multi Order API, the other legs can still be executed. However, in the Multi-Leg Order API, all legs are sent to the exchange simultaneously. If one leg is rejected, all legs are rejected, ensuring that either all legs are executed together or none at all.

Important Notes
  • Order Type: Currently, only limit orders are allowed.
  • Leg Limit: No more than three legs are permitted due to exchange limitations.
  • Order Validity: Immediate or Cancel (IOC).
  • Segment: Only the NFO (National Financial Organization) segment is allowed.
  • OrderTag: One OrderTag is used for all legs.
  • Order Book Differences: The order book will show differences between Order ID and OMS IDs with Leg1/Leg2/Leg3.
  • Exchange Order ID: All legs will have the same Exchange Order ID.
  • Brokerage Calculation: Brokerage will be calculated per leg.
  • Stream Key Requirement: All legs must belong to the same stream key; otherwise, the order will get rejected. For better clarity and to identify the stream key, refer to the explanation provided below:
  • Type 1 - Exact Symbol Search: When the user selects type 1 and inputs a symbol ticker, the stream is returned as a result.

  • Type 2 - Prefix Symbol Search: When the user selects type 2 and inputs a symbol ticker prefix and stream, all symbols under that stream with the given prefix are returned.

Note: For exiting the code, enter "exit" as an input.

You can use the below code for running the script:

  1. import requests

    import sys

    from collections import defaultdict

     

    from pytrie import StringTrie

     

     

    streamSymbolDict = defaultdict(list)

    symbolStreamDict = {}

     

    def prefixSearch(arr,prefix):

        trie=StringTrie()

        for key in arr:

            trie[key] = key

        result = trie.values(prefix)

        return result

     

    def SymbolStreamMap():

        response = requests.get("https://s3.ap-south-1.amazonaws.com/public.fyers.in/sym_details/NSE_FO_sym_master.json")")

        data = response.json()

        for symbolName in data:

            stream = data[symbolName]['stream']

            streamSymbolDict[stream].append(symbolName)

            symbolStreamDict[symbolName] = stream

     

    SymbolStreamMap()

     

    while True:

        searchType = input("Enter the type of search : ")

        if searchType == "exit":

            break

     

        symbolSearch = input("\n Enter the symbol : ")

        symbolSearch = symbolSearch.upper()

        if len(symbolSearch) > 4:

            if symbolSearch[:4] != "NSE:":

                symbolSearch = "NSE:" + symbolSearch

        else:

            symbolSearch = "NSE:" + symbolSearch

     

     

        if searchType == "1":

            if symbolSearch == "exit":

                break

            try:

                print(symbolStreamDict[symbolSearch])

            except KeyError:

                print("Enter a valid Symbol ticker for exact search",KeyError)

        if searchType == "2":

            inputStream = input("\n Enter the stream : ")

     

            if inputStream == "exit":

                continue

            if symbolSearch != "":

                try:

                    results = prefixSearch(streamSymbolDict[inputStream],symbolSearch)

                    print(results)

                except KeyError:

                    print("Enter a valid Symbol ticker for exact search",KeyError)

            else:

                results = streamSymbolDict[inputStream]

                print(results)

     print("Exiting application")


    • Related Articles

    • How to place a Bracket Order in FYERS 2.0 App?

      A bracket order is an intraday order which is one of the trending products in the capital markets. It helps you manage your risk and trade efficiently. You can place a bracket order in FYERS and keep a check on your trades on the charts effortlessly. ...
    • How to Place a Bracket Order on Fyers Web?

      Bracket Order (BO) is an innovative intraday trading product that allows traders to place the main order alongside a simultaneous stop-loss and target order. This ensures efficient trading and minimizes risks. Placing a bracket order on the Fyers ...
    • How to integrate FYERS API Bridge with front-end platforms?

      You can send Signals in FYERS API Bridge through an external program such as Amibroker/MT4/TradingView/Python/C# etc. Understanding How Signals Work: The FYERS API Bridge works based on “Signals”. A Signal is basically an indication (not decision) to ...
    • What functionalities does the order websocket in API v3 offer?

      The order websocket in API v3 is an advanced feature that provides access to a richer set of information related to trading. It includes updates on orders, trades, and positions, as well as alerts and EDIS (Exchange Data Interface System) details. ...
    • How to place a GTT order in Fyers App?

      A Good Till Trigger (GTT) order provides a strategic way to manage stock price fluctuations by setting up specific triggers for buying or selling. At FYERS, there are multiple types of GTT orders you can place: Single: This order lets you set a ...