TradingView Broker Integration API
TradingView's REST spec for brokers (v1.22.0, 47 endpoints): authorization, accounts, orders, positions, quotes, depth and data integration.
Finance & banking#trading#brokers
Fork copies the collection into your workspace, without the publisher's secrets, so you can add your own key and send requests. Star saves it to your starred APIs (Account › Marketplace) and helps others find it.
Overview
What this is: the REST API a broker implements on its own servers so TradingView can connect to it. TradingView acts as the front end: its users log in to the broker, see accounts, orders and positions, and trade from TradingView charts. You do not call tradingview.com with it.
Using this collection: set baseUrl to your own implementation (it starts as TradingView's placeholder https://your-rest-implementation.com/api), call Authorize to get a token, put it in bearerToken, then test each endpoint against the spec. Folders: Authorization, Broker Configuration, Account, Trading, Market Data, Data Permissions, Data Integration.
Becoming a TradingView broker needs an agreement with TradingView: https://www.tradingview.com/brokerage-integration/
Overview
This API is to be implemented by the Brokers in order to connect their backend systems to TradingView, that acts as a frontend.
Check the info page for more info and use the contact form there if you have any questions.
Types of requests
There are two types of requests — client and server.
Client requests are executed at the browser. Server requests are initiated from the TradingView servers.
If your integration does not imply brokerage data stream connection to the TradingView website -
then there won't be any server requests.
Clients requests
The two possible ways of sending updates to the client's side are either done by making use of client regularly polling endpoints,
or by opening a streaming connection and pushing updates.
HTTP requests
From the browser TradingView requests the info (list of orders and positions, balance info, etc.) from the broker’s server.
The requests are sent periodically and the intervals can be set by using the /config endpoint.
After that, TradingView compares the new data with the previous answer and calculates the difference.
If the status of the order/position changes or new data appears - the user will see a notification and the changes
will display in the Account manager on the website.
Requests to the endpoints for placing/modifying orders, positions closing, etc. occur only after actions made by the user.
The /quotes endpoint retrieves the current bid/ask from the broker.
The /depth endpoint retrieves Level 2 market data.
HTTP streaming
If the integration uses HTTP streaming endpoints, the connections to them are established once at the start of a session.
The http-streaming consists of messages separated with line breaks.
The content of the messages must be in Compact JSON format, i.e. should not contain any line breaks, except a line break at the very end
which will act as a message separator.
There are four types of messages:
- Entities snapshot
- Entities updates
- Ping
- Error
Please refer to the streaming endpoints for more details.
Server requests
In case if a Broker provides any Forex or CFD trading access for its clients it will require connection
of its own market data at TradingView. In order to make it possible, you will need to implement the following endpoints -/symbol_info, /history and /streaming.
Data requests are sent from different TradingView servers. Usually, at least 4 servers are used.
The historical data is cached on TradingView servers and loaded to the client browser from our servers.
Restricting access to data
By default, the broker symbols will be available in the symbol search at TradingView and all the community
will have access to your data streams without any limitation. In order to limit the access to your data streams
please use the following endpoints - /groups and /permissions.
You can find more information about restricting access to the data in the description of these endpoints.
Change log
1.22.0 Added an optional side field (aggressor side) to trades in the /streaming endpoint.
1.21.0 Added time window and cursor pagination to the /executions and /ordersHistory endpoints.
Added new startTime, endTime and cursor query parameters and a new nextPageCursor field to the responses. The maxCount parameter limits the page size.
The instrument parameter of the /executions endpoint is no longer required.
Added new invalid_cursor error type.
1.20.0 Added new grossPnl, netPnl, swap and conversion fields to Execution in the /getExecutions endpoint's response.
1.19.0 Added support for unpaired exit levels.
Added new flag: supportUnpairedExitLevels.
1.18.0 Added a new digitalSignature field to the /modifyPosition and /modifyIndividualPosition endpoints.
1.17.0 Added new typespecs algorithmic.
1.16.0 Added OAuth 2.0 JWT Authorization.
1.15.0 Added new option type and new fields specific to options: lotsize, option-product, option-type, option-style, strike, underlying-symbol to the /symbol_info endpoint.
1.14.0 Added OAuth 2.0 Authorization Code Flow with PKCE, removed OAuth 2 Implicit Flow.
1.13.1 Added new dependantCustomFieldIds field and new customFields dependency to the /config endpoint.
1.13.0 Added new endpoint…
Endpoints 47
Authorization
- POSTAuthorize
/authorizeUsername and password authentication. - POSTLogout
/logoutSend logout if the supportLogout flag is set as true.
Broker Configuration
- GETConfiguration
/config?locale=ar_AEGet localized configuration. - GETMapping
/mappingReturn all broker instruments with corresponding TradingView instruments. It is required to add a Broker to TradingView.com. Please note that this endpoint…
Account
- GETAccounts
/accounts?locale=ar_AEGet a list of accounts owned by the user. - GETUser Info
/userInfo?locale=ar_AEGet detailed user-specific information. - POSTPromotion Report
/promotionReport?locale=ar_AEWill be sent to pass user-specific information with promotion details. - GETInstruments
/accounts/:accountId/instruments?locale=ar_AEGet the list of the instruments that are available for trading with the specified account. - GETState
/accounts/:accountId/state?locale=ar_AEGet account information. Consider using stream/state instead, as it can decrease the workload on the servers. - GETStream State
/accounts/:accountId/stream/state?locale=ar_AEStream account information. Unlike /stream/orders or /stream/positions the whole state object must be sent to the client every time an update occurs. - GETOrders
/accounts/:accountId/orders?locale=ar_AEGet current session orders for the account. It also includes working orders from previous sessions. Filled/cancelled/rejected orders should be included in the… - GETStream Orders
/accounts/:accountId/stream/orders?locale=ar_AEStream orders of the current session for the account. It also includes working orders from the previous sessions. A snapshot of all orders should be sent as… - GETPositions
/accounts/:accountId/positions?locale=ar_AEGet positions for an account. Consider using stream/positions instead, as it can decrease the workload on the servers. - GETStream Positions
/accounts/:accountId/stream/positions?locale=ar_AEStream positions for an account. A snapshot of all positions should be sent as the first message in the stream. After that the server must only send updates.… - GETNet Positions
/accounts/:accountId/netPositions?locale=ar_AEGet net positions for an account. - GETStream Net Positions
/accounts/:accountId/stream/netPositions?locale=ar_AEStream net positions for an account. A snapshot of all net positions should be sent as the first message in the stream. After that the server must only send… - GETIndividual Positions
/accounts/:accountId/individualPositions?locale=ar_AEGet individual positions for an account - GETStream Individual Positions
/accounts/:accountId/stream/individualPositions?locale=ar_AEStream individual positions for an account. A snapshot of all individual positions should be sent as the first message in the stream. After that the server… - GETBalances
/accounts/:accountId/balances?locale=ar_AEGet crypto balances for an account. Balances are displayed as the first table of the Account Summary tab. Used for crypto currencies only. - GETExecutions
/accounts/:accountId/executions?locale=ar_AEGet a list of executions (i.e. fills or trades) for an account. Executions are displayed on a chart and in the Account manager. The startTime, endTime,… - GETOrders History
/accounts/:accountId/ordersHistory?locale=ar_AEGet order history for an account. It is expected that returned orders will have a final status (rejected, filled, cancelled). The startTime, endTime, maxCount… - POSTGet Leverage
/accounts/:accountId/getLeverage?locale=ar_AERequest to this endpoint will be sent when the user opens the Order Ticket or changes any of the symbol, order type, side and any of the custom fields in the… - POSTSet Leverage
/accounts/:accountId/setLeverage?locale=ar_AEWill be sent when the user confirms changing the leverage. Additional "leverage" field will be added to the payload, the value of which was set by the user.… - POSTPreview Leverage
/accounts/:accountId/previewLeverage?locale=ar_AEWill be sent when the user is editing the leverage. Custom Order dialog fields defined in the /accounts are sent along with the standard fields in the order… - GETStream Notifications
/accounts/:accountId/stream/notifications?locale=ar_AEStream notifications for an account. This endpoint allows you to send notification messages which TV will display in the GUI. The messages are predefined and…
Trading
- POSTPlace Order
/accounts/:accountId/orders?locale=ar_AEPlace a new order. Custom Order dialog fields defined in the /accounts are sent along with the standard fields in the order object. - POSTCancel All Orders
/accounts/:accountId/orders/cancelAll?locale=ar_AECancel multiple existing orders at once. Either provide a list of orderIds to cancel specific orders, or provide a symbol to cancel all orders for that symbol. - PUTModify Order
/accounts/:accountId/orders/:orderId?locale=ar_AEModify an existing order. Custom Order dialog fields defined in the /accounts are sent along with the standard fields in the order object. - DELETECancel Order
/accounts/:accountId/orders/:orderId?locale=ar_AECancel an existing order. - POSTPreview Order
/accounts/:accountId/previewOrder?locale=ar_AEGet estimated cost, commission and other information for an order without the order actually being placed or modified. This information is displayed in the… - POSTPreview Close Position
/accounts/:accountId/previewClosePosition?locale=ar_AEGet closing cost, estimations and other information for an attempt to close a position without the position actually being closed. This information is… - POSTOrder Info
/accounts/:accountId/orderInfo?locale=ar_AERetrieves order data displayed in the Order Ticket. This information is displayed in the Order Info section. This endpoint is used if supportCustomOrderInfo… - PUTModify Position
/accounts/:accountId/positions/:positionId?locale=ar_AEModify an existing position stop loss or take profit or both. - DELETEClose Position
/accounts/:accountId/positions/:positionId?locale=ar_AEClose an existing position. - DELETEClose Net Position
/accounts/:accountId/netPositions/:netPositionId?locale=ar_AEClose an existing net position and all of the individual positions on the symbol. - PUTModify Individual Position
/accounts/:accountId/individualPositions/:individualPositionId?locale=ar_AEModify an existing individual position stop loss or take profit or both. - DELETEClose Individual Position
/accounts/:accountId/individualPositions/:individualPositionId?locale=ar_AEClose an individual position. - POSTLatency Tracking
/accounts/:accountId/trackLatencyEndpoint is used to collect performance and statistical data for a particular request. Applies to the following endpoints: Place order: /placeOrder Modify…
Market Data
- GETQuotes
/quotes?locale=ar_AE&accountId=string&symbols=stringGet current prices of the instrument. The bid and ask fields are required, and the buyPipValue and sellPipValue fields are desirable if the account currency… - GETStream Quotes
/stream/quotes?locale=ar_AE&accountId=string&symbols=stringStream current prices of the instrument. The bid and ask fields are required, and the buyPipValue and sellPipValue fields are desirable if the account… - GETDepth
/depth?locale=ar_AE&accountId=string&symbol=stringGet current depth of market for the instrument. Optional. - GETStream Depth
/stream/depth?locale=ar_AE&accountId=string&symbol=stringStream current depth of market for the instrument. Optional.
Data Permissions
- GETGroups
/groupsGet a list of possible groups of symbols. A group is a set of symbols that share a common access level. Any user can have access to any number of such groups.… - GETPermissions
/permissionsGet a list of symbol groups allowed for the user. It is only required if you use groups of symbols to restrict access to instrument's data.
Data Integration
- GETSymbol Info
/symbol_infoGet a list of all instruments. - GETHistory
/history?symbol=string&resolution=string&from=0.0&to=0.0Request for history bars. Each property of the response object is treated as a table column. Data should meet the following requirements: real-time data… - GETStream of prices
/streamingStream of prices. Server constantly keeps the connection alive. If the connection is broken - the server constantly tries to restore it. TradingView…
API details
- Base URL
https://your-rest-implementation.com/api- Authentication
- A bearer token in the Authorization header
OAuth 2.0 (authorization code flow) with 1 scope
OAuth 2.0 (client credentials flow) with 1 scope
OAuth 2.0 (client credentials flow) with 1 scope - Operations
- 47 operations on 43 pathsGET 28POST 12DELETE 4PUT 3
- Main resources
- Account 21Trading 13Data Integration 4Market Data 4Authorization 2Broker Configuration 2Data Permissions 2
- Response formats
application/json- Description format
- OpenAPI 3.0.0, API version
1.22.0 - Links
- OpenAPI document
How to test the TradingView Broker Integration API in Swastik Codes
- Open the APISelect “Fork & run in Swastik Codes” on this page. Sign in or create a free account if asked.
- Fork it into your workspaceChoose a workspace. You get your own copy of the TradingView Broker Integration API collection, without the publisher's secrets.
- Add your credentialsThis API uses A bearer token in the Authorization header. Add yours in the collection's variables or an environment; the requests already reference it.
- Send a requestPick an endpoint, for example “Authorize” (POST /authorize), and press Send. Check the response, add tests and run the whole collection with the runner.
Frequently asked questions
What is the TradingView Broker Integration API?
TradingView's REST spec for brokers (v1.22.0, 47 endpoints): authorization, accounts, orders, positions, quotes, depth and data integration. It is listed under Finance & banking and has 47 endpoints.
Who publishes the TradingView Broker Integration API?
It is listed from TradingView's public API description (an OpenAPI document), not published by TradingView on Swastik Codes. Anyone who controls tradingview.com can claim the profile by adding a DNS TXT record.
What is the base URL of the TradingView Broker Integration API?
Requests go to https://your-rest-implementation.com/api. Endpoint paths are added to this base URL.
How do I authenticate with the TradingView Broker Integration API?
It accepts 4 methods: A bearer token in the Authorization header; OAuth 2.0 (authorization code flow) with 1 scope; OAuth 2.0 (client credentials flow) with 1 scope; OAuth 2.0 (client credentials flow) with 1 scope.
How many endpoints does the TradingView Broker Integration API have?
47 operations on 43 paths (28 GET, 12 POST, 4 DELETE, 3 PUT). The largest groups are Account, Trading, Data Integration, Market Data.
Is forking the TradingView Broker Integration API free?
Yes. Forking copies the collection into your workspace for free. It has been starred 0 times and forked 0 times.