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

    • 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. ...
    • What data type does a client receive when calling for order updates or data updates from Websocket?

      When working with FYERS' WebSocket API, it's important to understand the structure of the data being returned. Both the market data stream and order updates follow a consistent format to simplify integration and parsing. Data format received from ...
    • How is FYERS API useful?

      If you are building a trading/investing platform, FYERS API will solve the execution piece by enabling users to place orders and trade through us. You can also use the APIs to enable trading strategies with execution, manage portfolios and more. ...
    • Can I place Basket Orders through FYERS API?

      Yes, you can place basket orders through FYERS API. You can place up to 10 orders in 1 API call. These orders will be placed sequentially and the response of all the orders will be provided to you as a response in the same order. You can refer to the ...
    • How do the History API and the Quotes API differ in terms of the data they provide?

      The key difference between the History API and the Quotes API lies in the type of data they offer. The History API is designed to provide historical data, useful for analysis and back-testing. In contrast, the Quotes API delivers real-time data, ...