### HTTP GET Request Example (C#) Source: https://alor.dev/docs/api/http/md-v-2-history-get This C# code snippet demonstrates how to make an HTTP GET request to the Alor Dev API's history endpoint using HttpClient. It includes setting the request method, URL, and necessary headers like 'Accept' and 'Authorization'. ```csharp var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, "https://apidev.alor.ru/md/v2/history"); request.Headers.Add("Accept", "application/json"); request.Headers.Add("Authorization", "Bearer "); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); ``` -------------------------------- ### C# Example for Placing a Limit Order Source: https://alor.dev/docs/api/http/commandapi-warptrans-trade-v-2-client-orders-actions-limit-post Demonstrates how to place a limit order using C# and HttpClient. It includes setting headers, constructing the request body, and handling the response. ```csharp var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, "https://apidev.alor.ru/commandapi/warptrans/TRADE/v2/client/orders/actions/limit"); request.Headers.Add("Accept", "application/json"); request.Headers.Add("Authorization", "Bearer "); var content = new StringContent("{\n \"side\": \"buy\",\n \"quantity\": 1,\n \"price\": 142.52,\n \"instrument\": {\n \"symbol\": \"SBER\",\n \"exchange\": \"MOEX\",\n \"instrumentGroup\": \"TQBR\"\n },\n \"comment\": \"Первая заявка\",\n \"user\": {\n \"portfolio\": \"D00013\"\n },\n \"timeInForce\": \"oneday\",\n \"allowMargin\": false,\n \"icebergFixed\": 100,\n \"icebergVariance\": 2\n}", null, "application/json"); request.Content = content; var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); ``` -------------------------------- ### Request Identifier (GUID) Source: https://alor.dev/docs/api/usage/orders/market-orders This section details the usage of the 'guid' parameter, which serves as a unique identifier for API requests. It explains the constraints and provides examples of valid identifiers and their JSON representation. ```APIDOC ## Request Identifier (GUID) ### Description Any string combination, including special characters, can be used as a request identifier. The identifier must be unique within the trading system. If a previously used identifier is submitted, the system will return a cached response from the first request with that identifier. Special characters that could break JSON integrity must be escaped. ### Method N/A (This describes a parameter, not a specific endpoint) ### Endpoint N/A ### Parameters #### Query Parameters - **guid** (string) - Required - A unique identifier for the request. Can include alphanumeric characters and special symbols (`!@№;%:?*()-_=+/|"'`). Must be unique per trading system. ### Request Example ```json { "guid": "d3c886f1-ea1e-4634-aff4-119c902ad926" } ``` ### Response #### Success Response (200) - **guid** (string) - The identifier used for the request. - **response_data** (object) - The actual response payload from the executed request. #### Response Example ```json { "guid": "d3c886f1-ea1e-4634-aff4-119c902ad926", "response_data": { "order_id": "12345", "status": "filled" } } ``` ``` -------------------------------- ### Place Market Order using C# HttpClient Source: https://alor.dev/docs/api/http/commandapi-warptrans-trade-v-2-client-orders-actions-market-post Demonstrates how to place a market order using C# with the HttpClient class. This snippet shows setting up the request, headers, and content for a buy order. ```csharp var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, "https://apidev.alor.ru/commandapi/warptrans/TRADE/v2/client/orders/actions/market"); request.Headers.Add("Accept", "application/json"); request.Headers.Add("Authorization", "Bearer "); var content = new StringContent("{\n \"side\": \"buy\",\n \"quantity\": 1,\n \"instrument\": {\n \"symbol\": \"SBER\",\n \"exchange\": \"MOEX\",\n \"instrumentGroup\": \"TQBR\"\n },\n \"comment\": \"Первая заявка\",\n \"user\": {\n \"portfolio\": \"D00013\"\n },\n \"timeInForce\": \"oneday\",\n \"allowMargin\": false\n}", null, "application/json"); request.Content = content; var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); ``` -------------------------------- ### API Interaction Basics Source: https://alor.dev/docs/tags/%D0%BF%D0%BE%D0%BB%D1%83%D1%87%D0%B5%D0%BD%D0%B8%D0%B5-%D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D1%85 General information on interacting with the API for data retrieval and getting started. ```APIDOC ## API Interaction Basics General information on interacting with the API for data retrieval and getting started. ### Получение данных **Description**: Fundamentals of interacting with the API to retrieve exchange data. ### Старт в Боевом контуре **Description**: Quick start guide for working with the production environment API. ### Старт в Тестовом контуре **Description**: Quick start guide for working with the test environment API. ``` -------------------------------- ### Financial Data Structure (Simple Format Example) Source: https://alor.dev/docs/api/http/md-v-2-clients-exchange-portfolio-positions-get An alternative example of the financial data structure in the 'Simple' format, showcasing different values for a financial instrument like 'APTK'. This demonstrates the typical data points for a stock position. ```json [ { "volume": 549.198, "currentVolume": 555.24, "symbol": "APTK", "brokerSymbol": "MOEX:APTK", "portfolio": "D00013", "exchange": "MOEX", "avgPrice": 9.1533, "qtyUnits": 60, "openUnits": 60, "lotSize": 10, "shortName": "Аптеки36и6", "qtyT0": 60, "qtyT1": 60, "qtyT2": 60, "qtyTFuture": 60, "qtyT0Batch": 6, "qtyT1Batch": 6, "qtyT2Batch": 6, "qtyTFutureBatch": 6, "qtyBatch": 6, "openQtyBatch": 6, "qty": 6, "open": 6, "dailyUnrealisedPl": 1.92, "unrealisedPl": 7.962, "isCurrency": false, "existing": true } ] ``` -------------------------------- ### Get Trading Status (JavaScript) Source: https://alor.dev/docs/api/http/dev-trading-session-status JavaScript example using the fetch API to get trading status. This code demonstrates making a GET request, setting headers for JSON acceptance and Bearer token authentication, and processing the response. ```javascript fetch('https://apidev.alor.ru/md/status/:exchange/:market', { method: 'GET', headers: { 'Accept': 'application/json', 'Authorization': 'Bearer ' } }) .then(response => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); }) .then(data => console.log(data)) .catch(error => console.error('Error fetching trading status:', error)); ``` -------------------------------- ### Order Book Slim General Example (JSON) Source: https://alor.dev/docs/api/http/md-v-2-orderbooks-exchange-symbol-get A 'Slim' format example for general order book data. This format uses shorter key names for bids ('b'), asks ('a'), and timestamps ('t'). ```json { "b": [ { "p": 281.98, "v": 36 } ], "a": [ { "p": 281.99, "v": 11 } ], "t": 1701105939395, "h": true } ``` -------------------------------- ### Get Trade History (C#) Source: https://alor.dev/docs/api/http/trade-stats-by-symbol Retrieves historical trade data for a given symbol and exchange using C#. This example uses HttpClient to make a GET request and includes necessary headers for authentication and content type. ```csharp var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, "https://apidev.alor.ru/md/stats/:exchange/:portfolio/history/trades/:symbol"); request.Headers.Add("Accept", "application/json"); request.Headers.Add("Authorization", "Bearer "); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); ``` -------------------------------- ### Get Order Groups - C# HttpClient Source: https://alor.dev/docs/api/http/commandapi-api-order-groups-get Example of fetching order groups using C#'s HttpClient. This code sends a GET request with an authorization header and processes the response. ```csharp var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, "https://apidev.alor.ru/commandapi/api/orderGroups"); request.Headers.Add("Accept", "application/json"); request.Headers.Add("Authorization", "Bearer "); var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); ``` -------------------------------- ### C# HttpClient Example for Placing an Order Source: https://alor.dev/docs/api/http/v-2-client-orders-actions-take-profit-limit This C# code snippet demonstrates how to use HttpClient to send a POST request to the Alor Dev API to place an order. It includes setting headers, constructing the JSON request body, and handling the response. Ensure you replace '' with your actual Bearer token. ```csharp var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, "https://apidev.alor.ru/warptrans/:tradeServerCode/v2/client/orders/actions/takeProfitLimit"); request.Headers.Add("Accept", "application/json"); request.Headers.Add("Authorization", "Bearer "); var content = new StringContent("{\n \"Quantity\": 1,\n \"Side\": \"buy\",\n \"TriggerPrice\": 191.33,\n \"Price\": 142.52,\n \"Instrument\": {\n \"symbol\": \"SBER\",\n \"exchange\": \"MOEX\"\n },\n \"comment\": \"Первая заявка\",\n \"User\": {\n \"account\": \"L01-00000F00\",\n \"portfolio\": \"D00013\"\n },\n \"OrderEndUnixTime\": 1590094740,\n \"timeInForce\": \"oneday\",\n \"icebergFixed\": 100,\n \"icebergVariance\": 2\n}", null, "application/json"); request.Content = content; var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); ``` -------------------------------- ### Order Data Example (Full Format) Source: https://alor.dev/docs/api/http/md-v-2-clients-exchange-portfolio-stop-orders-get An example of a complete order object in JSON format, including all fields like ID, symbol, status, prices, and iceberg details. ```json [ { "id": 347498, "exchangeOrderId": 425242362, "symbol": "SBER", "brokerSymbol": "MOEX:SBER", "portfolio": "D00013", "exchange": "MOEX", "comment": "Первая заявка", "board": "TQBR", "type": "stop", "side": "buy", "condition": "more", "status": "filled", "transTime": "2020-06-16T23:59:59.9990000Z", "updateTime": "2020-06-16T23:59:59.9990000Z", "endTime": "2020-06-16T23:59:59.9990000Z", "error": "Цена не кратна минимальному шагу цены.", "qtyUnits": 20, "qtyBatch": 1, "qty": 1, "filledQtyUnits": 10, "filledQtyBatch": 1, "price": 208.6, "avg_price": 16.6, "stopPrice": 191.33, "existing": false, "timeInForce": "oneday", "iceberg": { "creationFixedQuantity": 100, "creationVarianceQuantity": 2, "visibleQuantity": 0, "visibleQuantityBatch": 0, "visibleFilledQuantity": 0, "visibleFilledQuantityBatch": 0 }, "volume": 2086.3, "protectingSeconds": 15 } ] ``` -------------------------------- ### Security Data Retrieval (Ruby) Source: https://alor.dev/docs/api/http/md-v-2-securities-exchange-get A Ruby example using the `net/http` library to perform an HTTP GET request for security data. It demonstrates setting up the request, headers, and processing the response. ```ruby require 'net/http' require 'uri' uri = URI.parse("https://apidev.alor.ru/md/v2/Securities/:exchange") token = "" http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) request['Accept'] = 'application/json' request['Authorization'] = "Bearer #{token}" response = http.request(request) puts response.body ``` -------------------------------- ### Security Data Retrieval (Shell) Source: https://alor.dev/docs/api/http/md-v-2-securities-exchange-get This shell script example uses `curl` to make an HTTP GET request for security data. It shows how to set the necessary headers, including the Authorization token. ```shell curl -X GET "https://apidev.alor.ru/md/v2/Securities/:exchange" \ -H "Accept: application/json" \ -H "Authorization: Bearer " ``` -------------------------------- ### Order Data Example (Simple Format) Source: https://alor.dev/docs/api/http/md-v-2-clients-exchange-portfolio-stop-orders-get An example of an order object in a simplified JSON format, showing common fields for order representation. ```json [ { "id": 347499, "exchangeOrderId": 425242362, "symbol": "SBER", "brokerSymbol": "MOEX:LKOH", "portfolio": "D00013", "exchange": "MOEX", "board": "TQBR", "type": "stop", "side": "buy", "condition": "LessOrEqual", "status": "working", "transTime": "2020-05-16T23:59:59.9990000Z", "updateTime": null, "endTime": "2020-06-16T23:59:59.9990000Z", "error": null, "qtyUnits": 10, "qtyBatch": 1, "qty": 1, "filled": 0, "filledQtyUnits": 0, "filledQtyBatch": 0, "price": 0, "avg_price": 0, "stopPrice": 208.6, "existing": true, "timeInForce": "oneday", "iceberg": null, "volume": 2086.1, "protectingSeconds": 15 } ] ``` -------------------------------- ### Trade Data Example Source: https://alor.dev/docs/api/http/md-v-2-clients-exchange-portfolio-symbol-trades-get This JSON snippet demonstrates a sample trade object, including identifiers, instrument details, trade parameters like quantity and price, and commission information. It also includes nested REPO-specific fields. ```json [ { "id": 159, "orderno": "18995978560", "comment": "Первая заявка", "symbol": "SBER", "brokerSymbol": "MOEX:SBER", "exchange": "MOEX", "date": "2020-06-16T23:59:59.9990000Z", "board": "TQBR", "qtyUnits": 1, "qtyBatch": 1, "qty": 1, "price": 142.52, "accruedInt": 0, "side": "buy", "existing": false, "commission": 24.21, "repoSpecificFields": { } } ] ``` -------------------------------- ### Get Trading Status (HTTP) Source: https://alor.dev/docs/api/http/dev-trading-session-status Basic HTTP request example for fetching trading status. It outlines the GET method, the target URL, and the necessary headers for accepting JSON and providing authentication via a Bearer token. ```http GET /md/status/:exchange/:market HTTP/1.1 Host: apidev.alor.ru Accept: application/json Authorization: Bearer ``` -------------------------------- ### REST API Order Book Request Example Source: https://alor.dev/docs/api/usage/data Example of a REST API request to get order book data. It includes query parameters such as instrumentGroup, depth, and format. The API returns a JSON object with bid and ask information upon successful execution. ```http https://api.alor.ru/md/v2/orderbooks/MOEX/SBER?instrumentGroup=TQBR&depth=5&format=Simple https://apidev.alor.ru/md/v2/orderbooks/MOEX/SBER?instrumentGroup=TQBR&depth=5&format=Simple ``` -------------------------------- ### Order Book Simple Example (JSON) Source: https://alor.dev/docs/api/http/md-v-2-orderbooks-exchange-symbol-get An example of order book data in the 'Simple' format. This format includes snapshot flags and both standard and millisecond timestamps. ```json { "snapshot": true, "bids": [ { "price": 281.98, "volume": 36 } ], "asks": [ { "price": 281.99, "volume": 11 } ], "timestamp": 1701105939, "ms_timestamp": 1701105939395, "existing": true } ``` -------------------------------- ### Get Order Groups - JSON Response Example Source: https://alor.dev/docs/api/http/commandapi-api-order-groups-get An example of a successful JSON response when retrieving order groups. It includes details like order group ID, login, associated orders, execution policy, status, and timestamps. ```json [ { "id": "eafb19d6-c578-4afe-aa95-d528c4531031", "login": "P039004", "orders": [ { "orderId": "18995978560" } ], "executionPolicy": "OnExecuteOrCancel", "status": "Active", "createdAt": "2024-07-29T15:51:28.071Z", "closedAt": "2024-07-29T15:51:28.071Z" } ] ``` -------------------------------- ### Trade Data in Slim Format Source: https://alor.dev/docs/api/http/md-v-2-securities-exchange-symbol-alltrades-get This example illustrates the trade data in a 'Slim' format, which is the most concise representation. It uses shorter field names for efficiency. ```json [ { "id": 159, "sym": "SBER", "bd": "TQBR", "q": 1, "px": 142.52, "t": 1611158710768, "s": "buy", "oi": 523920, "h": false } ] ```