Skip to main content

Data receiption

ALOR Broker trading system gives the possibility to get exchange data via API. You can use HTTP API, WebSocket API and GraphQL API for this task.

Variety of options

There is no universal way of interaction. Each of the available options has its own advantages, disadvantages and peculiarities that should be taken into account. When selecting an interaction option, focus on your tasks and keep fair-use principles in mind so that your actions do not harm the system. Also, using one option of interacting for one task does not affect your ability to use another option for another task.

Data types

The following exchange data can be obtained from the trading system via API:

  • List of created orders and detailed information about them
  • List of concluded transactions and detailed information about them
  • List of available financial instruments and information about them: quotes, order books, historical data, etc.
  • Information about the user and portfolio: general information, positions, risks, etc.
Need a hand?

If you can't get the data you're looking for (can't find a relevant query or the result looks uninformative), contact us at Telegram.


Data categories

All data provided by the trading system via API can be classified into two categories:

  • Public data — information that can be freely obtained from any third-party sources, and access to them by a wide range of persons will not affect the market behavior or the state of the system. Such information includes, for example, lists of available instruments and currency pairs.
  • Protected data - information, the free publication of which for an unlimited range of persons can provoke both changes in market behavior and disclosure of personal data of portfolio holders. Access to data in this category requires authorization to confirm access rights to the requested resources. Such information includes, for example, data on all trades for today and list of open positions in the portfolio.

Access to data

Although public data is not secret and can be freely obtained through other sources, access to it via ALOR Broker API may be partially restricted. This is done to reduce the load on the system and to give priority to requests made by Broker's clients.

Restrictions may be different depending on the chosen method of interaction:

  • HTTP API and GraphQL API public resources do not require mandatory authorization of requests, but the response will contain data that was up to date 15 minutes ago. For example, a request sent at 15:00 to get current UTC time in Unix format will return data corresponding to 14:45.
  • WebSocket API has no public resources. All requests to any of the resources provided must be authorized. This applies even to those requests, information in response to which can be obtained in other ways without authorization.

To avoid these restrictions, log in as a trader or use test access.


Request examples

Common requirements

To ensure that the system returns up-to-date data in response, the queries sent must meet certain requirements. Depending on the selected communication interface, requests must be:

  • authorized (HTTP API, WebSocket API, GraphQL API)
  • identifiable (WebSocket API)
  • sent to united interface URL (WebSocket API, GraphQL API).

To fulfill these requirements, use additional header and/or request body parameters described below.

Authorization

Authorization is necessary to confirm that the sender has the rights to use the requested resource. Request authorization uses a JWT token, which acts as an Access token. A full description of available authorization methods is available in the Authorization section.

HTTP API uses the Authorization header parameter to pass the token. The header must be passed with each executed request.

This token should be passed as a Bearer token, so the header must contain the Bearer prefix before the passed value. A correctly filled Authorization header looks as follows:

Authorization: Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6IkpXVCJ9.eyJzdWIiOiJMb2dpblNhbXBsZSIsImVudCI6ImNsaWVudCIsImVpbiI6IjAxMjM0IiwiY2xpZW50aWQiOiIwMTIzNDU2IiwiYXpwIjoiMDEyMzQ1Njc4OWFiY2RlZjAxMjMiLCJhZ3JlZW1lbnRzIjoiQWdyZWVtZW50U2FtcGxlMSBBZ3JlZW1lbnRTYW1wbGUyIEFncmVlbWVudFNhbXBsZTMiLCJwb3J0Zm9saW9zIjoiUG9ydGZvbGlvU2FtcGxlMSBQb3J0Zm9saW9TYW1wbGUyIFBvcnRmb2xpb1NhbXBsZTMiLCJzY29wZSI6Ik9yZGVyc1JlYWQgT3JkZXJzQ3JlYXRlIFRyYWRlcyBQZXJzb25hbCBTdGF0cyIsImV4cCI6Mjg3MTc2MzE5OSwiaWF0IjowLCJpc3MiOiJBbG9yLklkZW50aXR5IiwiYXVkIjoiQ2xpZW50IFdBUlAgV2FycEFUQ29ubmVjdG9yIHN1YnNjcmlwdGlvbnNBcGkgQ29tbWFuZEFwaSBJbnN0cnVtZW50QXBpIFRyYWRpbmdWaWV3UGxhdGZvcm0ifQ.QOQVMIAoZ6SnF5urnIzJ0EvtQd9P5Sx355069kXoID207wHOTW0wkKNMcrIKXmENEQQ_0yDjqH_kjeqWLBJuqA


Sending requests

To demonstrate the syntax of the data retrieval request, we will use the order book request available in both the HTTP API and WebSocket API.

GraphQL

GraphQL API scheme is under development and some data may be unavailable. This includes order book data, so to demonstrate this method we use an example of obtaining basic instrument information.

Interactive description

Interactive description of the request is available on the Order Book page

Private resource

Request execution requires authorization.

To get the instrument order book via HTTP API, use the GET request to the endpoint /md/v2/orderbooks/{exchange}/{symbol}, where:

Path parameters

    exchange stringrequired

    Possible values: [MOEX, SPBX]

    Exchange

    symbol stringrequired

    Security code (Ticker)

    Example: SBER

Optional Query parameters can be added to fine-tune the query:

Query parameters

    depth int32

    Possible values: >= 1 and <= 50

    Order Book depth. The standard value is 20 (20x20) and maximum value is 50 (50x50).

    Default value: 20
    Example: 5
    format string

    Possible values: [Simple, Slim, Heavy]

    Representation format of returned data: Simple, Slim, Heavy

    Example: Simple

Filled with the required parameter values, the request looks like the following:

https://api.alor.ru/md/v2/orderbooks/MOEX/SBER?depth=5&format=Simple

https://apidev.alor.ru/md/v2/orderbooks/MOEX/SBER?depth=5&format=Simple

If the request is successful, the API will return a response with code 200 and a message containing the requested information:

Response example
{
"snapshot": true,
"bids": [
{
"price": 281.98,
"volume": 36
}
],
"asks": [
{
"price": 281.99,
"volume": 11
}
],
"timestamp": 1713387004,
"ms_timestamp": 1713387004878,
"depth": 20,
"existing": true
}

If the request processing ended with an error, the API will return information about the cause.

Details

Complete list of all parameters and possible responses is available on the request description page.


What's next?

Additionally, we recommend reading the following related articles: