Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    New Feature Announcement: Enhanced Real-Time Market Data with our Market Data API!

    General Discussion
    0
    13
    774
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      admin last edited by admin

      Introducing our new Live Market Data API, a powerful addition to our SmartAPI product. This API offers three distinct modes: Full, OHLC, and LTP. The Full Market Data Mode enables clients to fetch real-time data for a specific symbol, including Last Traded Price (LTP), open, high, low, close prices, last trade quantity, exchange feed time, exchange trade time, net change, percent change, average price, trade volume, open interest, lower circuit, upper circuit, total buying quantity, total selling quantity, 52-week low, 52-week high, and depth information for best five buy and sell orders. With these comprehensive features, clients gain valuable market data for realtime trading and investment decisions.

      API Overview:

      Endpoint: https://apiconnect.angelbroking.com/rest/secure/angelbroking/market/v1/quote/

      Request Type: POST

      Key Features:

      • LTP Mode: Get the latest last trade price for a specified exchange and symbol.

      • OHLC Mode: Retrieve the open, high, low, and close prices for a given exchange and symbol.

      • FULL Mode: Access a comprehensive set of data for a specified exchange and symbol. This mode includes various data points such as Last Traded Price (LTP), open, high, low, close prices, last trade quantity, exchange feed time, exchange trade time, net change, percent change, average price, trade volume, open interest, lower circuit, upper circuit, total buying quantity, total selling quantity, 52-week low, 52-week high, and depth information for best five buy and sell orders.

      • List of Supported Exchanges: All

      • Number of tokens supported in one request: This API currently supports a single token for a given exchange.

      Response Format:

      The response is a JSON object containing the requested stock market data. The response will be structured as follows:

      • A success boolean that indicates whether the request was successful.

      • A message string that describes the status of the request.

      • An errorCode string that provides specific error codes, if any.

      • A data object that contains the fetched market data and any unfetched data with errors

      Sample request (FULL Mode):

      {
        "mode": "FULL",
        "exchangeTokens": {
          "NSE": [
            "3045"
          ]
        }
      }
      

      Sample Response (FULL Mode):

      {
          "status": true,
          "message": "SUCCESS",
          "errorcode": "",
          "data": {
              "fetched": [
                  {
                      "exchange": "NSE",
                      "tradingSymbol": "SBIN-EQ",
                      "symbolToken": "3045",
                      "ltp": 568.2,
                      "open": 567.4,
                      "high": 569.35,
                      "low": 566.1,
                      "close": 567.4,
                      "lastTradeQty": 1,
                      "exchFeedTime": "21-Jun-2023 10:46:10",
                      "exchTradeTime": "21-Jun-2023 10:46:09",
                      "netChange": 0.8,
                      "percentChange": 0.14,
                      "avgPrice": 567.83,
                      "tradeVolume": 3556150,
                      "opnInterest": 0,
                      "lowerCircuit": 510.7,
                      "upperCircuit": 624.1,
                      "totBuyQuan": 839549,
                      "totSellQuan": 1284767,
                      "52WeekLow": 430.7,
                      "52WeekHigh": 629.55,
                      "depth": {
                          "buy": [
                              {
                                  "price": 568.2,
                                  "quantity": 511,
                                  "orders": 2
                              },
                              {
                                  "price": 568.15,
                                  "quantity": 411,
                                  "orders": 2
                              },
                              {
                                  "price": 568.1,
                                  "quantity": 31,
                                  "orders": 2
                              },
                              {
                                  "price": 568.05,
                                  "quantity": 1020,
                                  "orders": 8
                              },
                              {
                                  "price": 568.0,
                                  "quantity": 1704,
                                  "orders": 28
                              }
                          ],
                          "sell": [
                              {
                                  "price": 568.25,
                                  "quantity": 3348,
                                  "orders": 5
                              },
                              {
                                  "price": 568.3,
                                  "quantity": 4447,
                                  "orders": 13
                              },
                              {
                                  "price": 568.35,
                                  "quantity": 3768,
                                  "orders": 11
                              },
                              {
                                  "price": 568.4,
                                  "quantity": 8500,
                                  "orders": 40
                              },
                              {
                                  "price": 568.45,
                                  "quantity": 4814,
                                  "orders": 17
                              }
                          ]
                      }
                  }
              ],
              "unfetched": []
          }
      }
      

      Sample Request (OHLC Mode):

      {
        "mode": "OHLC",
        "exchangeTokens": {
          "NSE": [
            "3045"
          ]
        }
      }
      

      Sample Response (OHLC Mode):

      {
          "status": true,
          "message": "SUCCESS",
          "errorcode": "",
          "data": {
              "fetched": [
                  {
                      "exchange": "NSE",
                      "tradingSymbol": "SBIN-EQ",
                      "symbolToken": "3045",
                      "ltp": 571.8,
                      "open": 568.75,
                      "high": 568.75,
                      "low": 567.05,
                      "close": 566.5
                  }
              ],
              "unfetched": []
          }
      }
      

      Sample Request (LTP Mode):

      {
        "mode": "LTP",
        "exchangeTokens": {
          "NSE": [
            "3045"
          ]
        }
      }
      

      Sample Response (LTP Mode):

      {
          "status": true,
          "message": "SUCCESS",
          "errorcode": "",
          "data": {
              "fetched": [
                  {
                      "exchange": "NSE",
                      "tradingSymbol": "SBIN-EQ",
                      "symbolToken": "3045",
                      "ltp": 571.75
                  }
              ],
              "unfetched": []
          }
      }
      

      In case the requested data cannot be fetched, the API will provide a response indicating the inability to retrieve the information. Here's an example of the response in such a scenario:

      Sample Response (LTP Mode where data cannot be fetched):

      {
          "success": true,
          "message": "SUCCESS",
          "errorCode": "",
          "data": {
              "fetched": [],
              "unfetched": [
                  {
                      "exchange": "MCX",
                      "symbolToken": "",
                      "message": "Symbol token cannot be empty",
                      "errorCode": "AB4018"
                  }
              ]
          }
      }
      

      In order to ensure a seamless integration process, we have started updating our libraries for Python, Java, and Node.js. These updates will enhance compatibility and provide a smoother experience when incorporating the Live Market Data API into your applications. By keeping our libraries up to date, we aim to simplify the integration process and make it easier for developers to leverage the power of our API in their preferred programming languages.

      We invite you to actively participate in the forum thread dedicated to this new feature. Feel free to share your thoughts, ask questions, and provide feedback. Our dedicated support team and community members are available to assist you and engage in discussions related to the Market Data API.

      Note: Access the symbol data you need using this URL: https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json.

      Example for "SBIN-EQ":

      {"token":"3045","symbol":"SBIN-EQ","name":"SBIN","expiry":"","strike":"-1.000000","lotsize":"1","instrumenttype":"","exch_seg":"NSE","tick_size":"5.000000"}
      
      A 1 Reply Last reply Reply Quote 0
      • punit
        punit last edited by

        @admin Will it support all exchange segments? NFO, MCX ?

        1 Reply Last reply Reply Quote 0
        • A
          admin @admin last edited by admin

          @Ashok Yes, all exchanges are supported.

          V 1 Reply Last reply Reply Quote 0
          • V
            Vignesha @admin last edited by Vignesha

            @admin Thanks for the update... this seems to be a lot better...
            Is this being documented in the documentation? If not it would be better to do as I have not seen things like correlation_id in the new web_Socket_2 example script

            I guess its like a reference character of 10 digits provided by meself/customer that we can use to check the status of connection?

            Would be great if all this are explained and on how to get this

            AUTH_TOKEN = "Your Auth_Token"
            API_KEY = "Your Api_Key"
            CLIENT_CODE = "Your Client Code"
            FEED_TOKEN = "Your Feed_Token"
            correlation_id = "abc123"

            A 1 Reply Last reply Reply Quote 0
            • A
              admin @Vignesha last edited by

              Hi @Vignesha

              The correlation_id in the web_socket_2 example script is a 10-digit alphanumeric reference provided by the client. It helps track requests and error responses. You can generate a unique ID and include it in your API requests for easier tracking.

              Regarding the authentication and other mandatory headers, here's a summary:

              Authorization: This header expects a JWT authentication token obtained from the LoginbyPassword API.
              x-api-key: Your API key
              x-client-code: Your client code (Angel One trading account ID)
              x-feed-token: Feed token from the LoginbyPassword API for for subscribing to data feeds.

              For more details, refer to the WebSocket 2.0 documentation at https://smartapi.angelbroking.com/docs/WebSocket2.

              If you have further questions, please discuss them on the WebSocket 2.0 SDK release thread [https://smartapi.angelbroking.com/topic/3660/upgraded-smartapi-libraries-to-support-websocket-2-0-python-java-sdk-and-node-js-library].

              Let me know if you need any more assistance!

              V 1 Reply Last reply Reply Quote 0
              • V
                Vignesha @admin last edited by Vignesha

                @admin Really happy for the short turnaround... I can run the code now but getting only ping since its out of market hours... Will run it tomorrow and see how it works and update in the thread and hope the subscribe and unsubscribe inside the on_open() function works too 😃

                ####### Websocket V2 sample code #######
                
                from SmartApi.smartWebSocketV2 import SmartWebSocketV2
                from logzero import logger
                from cred import username, apikey, pwd, token
                import pyotp
                from SmartApi import SmartConnect
                import time
                
                
                obj = SmartConnect(api_key=apikey)
                data = obj.generateSession(username, pwd, pyotp.TOTP(token).now())
                print(data)
                refreshToken = data['data']['refreshToken']
                res = obj.getProfile(refreshToken)
                print(res['data']['exchanges'])
                
                AUTH_TOKEN = data['data']['jwtToken']
                API_KEY = apikey
                CLIENT_CODE = username
                FEED_TOKEN = obj.getfeedToken()
                correlation_id = "xxxxxxxxxx"
                
                
                action = 1
                mode =3
                token_list = [
                    {
                        "exchangeType": "5",
                        "tokens": ["234877"]
                    }
                ]
                
                sws = SmartWebSocketV2(AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN)
                
                
                def on_data(wsapp, message):
                    logger.info("Ticks: {}".format(message))
                    # close_connection()
                
                
                def on_open(wsapp):
                    logger.info("on open")
                    sws.subscribe(correlation_id, mode, token_list)
                    #sws.unsubscribe(correlation_id, mode, token_list)
                
                
                def on_error(wsapp, error):
                    logger.error(error)
                
                
                def on_close(wsapp):
                    logger.info("Close")
                
                
                def close_connection():
                    sws.close_connection()
                
                
                def subscribe():
                    sws.subscribe(correlation_id, mode, token_list)
                
                
                # Assign the callbacks.
                sws.on_open = on_open
                sws.on_data = on_data
                sws.on_error = on_error
                sws.on_close = on_close
                
                
                sws.connect()
                
                V 1 Reply Last reply Reply Quote 0
                • V
                  Vignesha @Vignesha last edited by

                  @admin tried with the same code but for nse stocks and it worked like a charm...
                  👏 👏

                  1 Reply Last reply Reply Quote 0
                  • P
                    Prasun Pal last edited by

                    @admin Thanks for the new API but the endpoint is not returning the expected data for the index. I tried the API on Nifty using the following payload but I couldn't get the open price, the open price was 0.

                    Payload

                    '{"mode":"OHCL","exchangeTokens":{"NSE":["26000"]}}'
                    

                    Response

                    close: 16483.85
                    exchange: 'NSE'
                    high: 0
                    low: 0
                    ltp: 19460.2
                    open: 0
                    symbolToken: '26000'
                    tradingSymbol: 'NIFTY'
                    

                    Is there anything I'm missing or is Smart API yet to support open prices for index scripts like Nifty?
                    Looking forward to your answer.

                    1 Reply Last reply Reply Quote 0
                    • M
                      Mastermind last edited by

                      https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json.

                      This link is returning null. there is no data received from this link. can some one help?

                      1 Reply Last reply Reply Quote 0
                      • M
                        muni7085 last edited by

                        @admin I am getting bad request error with Market Data API

                        <html>
                        <head><title>400 Bad Request</title></head>
                        <body bgcolor="white">
                        <center><h1>400 Bad Request</h1></center>
                        <hr><center>nginx/1.14.1</center>
                        </body>
                        </html>
                        

                        endpoint: https://apiconnect.angelbroking.com/rest/secure/angelbroking/market/v1/quote
                        method: post
                        payload:

                        payload = {
                            "mode": "LTP",
                            "exchangeTokens": {
                                "NSE": "3045"
                            }
                        }
                        payload=json.dumps(payload)
                        
                        connection=http.client.HTTPSConnection("apiconnect.angelbroking.com")
                        url="rest/secure/angelbroking/market/v1/quote/"
                        connection. Request("POST", url, body=json_data, headers=headers)
                        

                        language: python
                        Can anyone help with this?

                        1 Reply Last reply Reply Quote 0
                        • P
                          Pavan1414 last edited by

                          Hi @admin ,

                          we are not getting data from the past two days from the below mentioned endpoint.

                          Requesting you to please look into the issue and fix it ASAP.

                          https://apiconnect.angelbroking.com/rest/secure/angelbroking/market/v1/quote/

                          Thanks & Regards
                          Pavan Kumar Dakarapu

                          1 Reply Last reply Reply Quote 0
                          • S
                            sunnysingh123987 last edited by

                            hi @admin I am getting Internal Error and is unable to fetch any data using Market Data API. Here below are the details.
                            Language: Python
                            request:
                            smartAPi.getMarketData('FULL',{'NSE':['3045']})
                            response:
                            {'message': 'Internal Error', 'errorcode': 'AB2001', 'status': False, 'data': None}

                            Please Reply as soon as possible.

                            1 Reply Last reply Reply Quote 0
                            • V
                              venkatsai last edited by

                              For this OHLC which timeframe data is this ....?

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post