### Get Operations Request (Java) Source: https://developer.tbank.ru/invest/api/sandbox-service-get-sandbox-operations-by-cursor This Java code example demonstrates how to make a request to the Invest API to retrieve operations using the Apache HttpClient library. It shows how to set up the request with headers and a JSON payload. ```java import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import java.io.IOException; import java.util.HashMap; import java.util.Map; public class InvestApiRequest { public static void main(String[] args) { String url = "YOUR_API_ENDPOINT"; String token = "YOUR_TOKEN"; try (CloseableHttpClient client = HttpClients.createDefault()) { HttpPost request = new HttpPost(url); Map requestBodyMap = new HashMap<>(); requestBodyMap.put("accountId", "string"); requestBodyMap.put("instrumentId", "string"); requestBodyMap.put("from", "2025-08-29T14:11:00.713Z"); requestBodyMap.put("to", "2025-08-29T14:11:00.713Z"); requestBodyMap.put("cursor", "string"); requestBodyMap.put("limit", 0); requestBodyMap.put("operationTypes", new String[]{"OPERATION_TYPE_UNSPECIFIED"}); requestBodyMap.put("state", "OPERATION_STATE_UNSPECIFIED"); requestBodyMap.put("withoutCommissions", true); requestBodyMap.put("withoutTrades", true); requestBodyMap.put("withoutOvernights", true); // Convert map to JSON string (using a library like Jackson or Gson is recommended for production) String jsonRequestBody = "{\"accountId\":\"string\", \"instrumentId\":\"string\", \"from\":\"2025-08-29T14:11:00.713Z\", \"to\":\"2025-08-29T14:11:00.713Z\", \"cursor\":\"string\", \"limit\":0, \"operationTypes\":[\"OPERATION_TYPE_UNSPECIFIED\"], \"state\":\"OPERATION_STATE_UNSPECIFIED\", \"withoutCommissions\":true, \"withoutTrades\":true, \"withoutOvernights\":true}"; request.setEntity(new StringEntity(jsonRequestBody)); request.setHeader("Authorization", "Bearer " + token); request.setHeader("Content-Type", "application/json"); // Execute the request and process the response // CloseableHttpResponse response = client.execute(request); // System.out.println("Status Code: " + response.getStatusLine().getStatusCode()); // String responseBody = EntityUtils.toString(response.getEntity()); // System.out.println("Response Body: " + responseBody); // EntityUtils.consume(response.getEntity()); // Ensure the response entity is fully consumed } catch (IOException e) { e.printStackTrace(); } } } ``` -------------------------------- ### GetPortfolio Request Example (Go) Source: https://developer.tbank.ru/invest/api/operations-service-get-portfolio Example of how to make a GetPortfolio request using Go to the T-Invest API. ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.OperationsService/GetPortfolio" requestBody := map[string]string{ "accountId": "string", "currency": "RUB", } requestBodyBytes, err := json.Marshal(requestBody) if err != nil { fmt.Println("Error marshalling request body:", err) return } req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBodyBytes)) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "Bearer YOUR_TOKEN") client := &http.Client{} res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() fmt.Println("Status Code:", res.StatusCode) // Process response body here } ``` -------------------------------- ### GetSandboxOperations Request Examples Source: https://developer.tbank.ru/invest/api/sandbox-service-get-sandbox-operations Examples of how to call the GetSandboxOperations API method using different programming languages and cURL. These examples demonstrate how to structure the request body with parameters like accountId, from, to, state, and figi. ```cURL curl -X POST \ https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxOperations \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": "string", \ "from": "2025-08-29T14:11:00.713Z", \ "to": "2025-08-29T14:11:00.713Z", \ "state": "OPERATION_STATE_UNSPECIFIED", \ "figi": "string" \ }' ``` ```Go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxOperations" requestBody := map[string]interface{}{ "accountId": "string", "from": "2025-08-29T14:11:00.713Z", "to": "2025-08-29T14:11:00.713Z", "state": "OPERATION_STATE_UNSPECIFIED", "figi": "string" } jsonBody, err := json.Marshal(requestBody) if err != nil { fmt.Printf("Error marshaling JSON: %s\n", err) return } resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonBody)) if err != nil { fmt.Printf("Error making request: %s\n", err) return } defer resp.Body.Close() fmt.Printf("Status Code: %d\n", resp.StatusCode) // Process response body here } ``` ```Node.js const fetch = require('node-fetch'); async function getSandboxOperations() { const url = 'https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxOperations'; const requestBody = { "accountId": "string", "from": "2025-08-29T14:11:00.713Z", "to": "2025-08-29T14:11:00.713Z", "state": "OPERATION_STATE_UNSPECIFIED", "figi": "string" }; try { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(requestBody) }); console.log(`Status Code: ${response.status}`); const data = await response.json(); console.log(data); } catch (error) { console.error('Error:', error); } } getSandboxOperations(); ``` ```Python import requests import json url = "https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxOperations" request_body = { "accountId": "string", "from": "2025-08-29T14:11:00.713Z", "to": "2025-08-29T14:11:00.713Z", "state": "OPERATION_STATE_UNSPECIFIED", "figi": "string" } headers = { "Content-Type": "application/json" } try: response = requests.post(url, data=json.dumps(request_body), headers=headers) print(f"Status Code: {response.status_code}") print(response.json()) except requests.exceptions.RequestException as e: print(f"Error: {e}") ``` -------------------------------- ### GetSandboxAccounts Request Examples Source: https://developer.tbank.ru/invest/api/sandbox-service-get-sandbox-accounts Provides examples of how to call the GetSandboxAccounts API endpoint using different programming languages. This endpoint retrieves user accounts from the sandbox environment. ```cURL curl -X POST \ https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxAccounts \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer YOUR_TOKEN' \ -d '{ "status": "ACCOUNT_STATUS_UNSPECIFIED" }' ``` ```Go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxAccounts" payload := map[string]string{"status": "ACCOUNT_STATUS_UNSPECIFIED"} jsonPayload, _ := json.Marshal(payload) req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonPayload)) req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "Bearer YOUR_TOKEN") client := &http.Client{} res, err := client.Do(req) if err != nil { fmt.Println("Error making request: ", err) return } defer res.Body.Close() // Process response here fmt.Println("Status Code:", res.StatusCode) } ``` ```Java import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; public class GetSandboxAccounts { public static void main(String[] args) { try { URL url = new URL("https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxAccounts"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Authorization", "Bearer YOUR_TOKEN"); connection.setDoOutput(true); String jsonInputString = "{\"status\": \"ACCOUNT_STATUS_UNSPECIFIED\"}"; try (OutputStream os = connection.getOutputStream()) { byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } int responseCode = connection.getResponseCode(); System.out.println("Status Code: " + responseCode); // Process response here } catch (Exception e) { e.printStackTrace(); } } } ``` ```NodeJs const https = require('https'); const options = { hostname: 'invest-public-api.tbank.ru', port: 443, path: '/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxAccounts', method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer YOUR_TOKEN' } }; const postData = JSON.stringify({ status: 'ACCOUNT_STATUS_UNSPECIFIED' }); const req = https.request(options, (res) => { console.log(`Status Code: ${res.statusCode}`); // Process response here res.on('data', (d) => { process.stdout.write(d); }); }); req.on('error', (error) => { console.error(error); }); req.write(postData); req.end(); ``` ```PHP 'ACCOUNT_STATUS_UNSPECIFIED']); $options = stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => "Content-type: application/json\r\nAuthorization: Bearer YOUR_TOKEN\r\n", 'content' => $data ] ]); $result = file_get_contents($url, false, $options); // Process result here var_dump($result); ?> ``` ```Python import requests import json url = "https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxAccounts" headers = { "Content-Type": "application/json", "Authorization": "Bearer YOUR_TOKEN" } payload = { "status": "ACCOUNT_STATUS_UNSPECIFIED" } response = requests.post(url, headers=headers, data=json.dumps(payload)) print(f"Status Code: {response.status_code}") # Process response here print(response.json()) ``` -------------------------------- ### GetSandboxWithdrawLimits Java Request Source: https://developer.tbank.ru/invest/api/sandbox-service-get-sandbox-withdraw-limits Example of how to send a GetSandboxWithdrawLimits request using Java, showing the HTTP POST request setup and JSON payload. ```Java import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; public class GetSandboxWithdrawLimits { public static void main(String[] args) { try { URL url = new URL("https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxWithdrawLimits"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoOutput(true); String requestBody = "{\"accountId\": \"string\"}"; try (OutputStream os = connection.getOutputStream()) { byte[] input = requestBody.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } int responseCode = connection.getResponseCode(); System.out.println("Status Code: " + responseCode); // Process response here } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### GetSandboxOrderState Request Example (Go) Source: https://developer.tbank.ru/invest/api/sandbox-service-get-sandbox-order-state This snippet provides an example of how to call the GetSandboxOrderState method using the Go programming language. It demonstrates constructing the request body with account and order details. ```Go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxOrderState" payload := map[string]string{ "accountId": "string", "orderId": "string", "priceType": "PRICE_TYPE_UNSPECIFIED", "orderIdType": "ORDER_ID_TYPE_UNSPECIFIED" } jsonPayload, err := json.Marshal(payload) if err != nil { fmt.Println("Error marshaling JSON:", err) return } req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonPayload)) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Set("Content-Type", "application/json") client := &http.Client{} res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() fmt.Println("Status Code:", res.StatusCode) // Process response body here } ``` -------------------------------- ### GetSandboxPortfolio Request Examples (T-Invest API) Source: https://developer.tbank.ru/invest/api/sandbox-service-get-sandbox-portfolio Provides example requests for the GetSandboxPortfolio method in various programming languages. This method is used to retrieve a user's account portfolio within the T-Invest sandbox environment. ```cURL curl -X POST \ https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxPortfolio \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer YOUR_TOKEN' \ -d '{ "accountId": "string", "currency": "RUB" }' ``` ```Go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxPortfolio" payload := map[string]string{ "accountId": "string", "currency": "RUB", } jsonPayload, _ := json.Marshal(payload) req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonPayload)) req.Header.Set("Content-Type", "application/json") req.Header.Set("Authorization", "Bearer YOUR_TOKEN") client := &http.Client{} res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() fmt.Println("Status Code:", res.StatusCode) } ``` ```Java import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; public class GetSandboxPortfolio { public static void main(String[] args) throws Exception { URL url = new URL("https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxPortfolio"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Authorization", "Bearer YOUR_TOKEN"); connection.setDoOutput(true); String jsonInputString = "{ \"accountId\": \"string\", \"currency\": \"RUB\" }"; try (OutputStream os = connection.getOutputStream()) { byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } int responseCode = connection.getResponseCode(); System.out.println("Status Code: " + responseCode); } } ``` ```NodeJs const fetch = require('node-fetch'); const url = 'https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxPortfolio'; const payload = { accountId: 'string', currency: 'RUB' }; fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer YOUR_TOKEN' }, body: JSON.stringify(payload) }) .then(response => { console.log('Status Code:', response.status); return response.json(); }) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` ```PHP 'string', 'currency' => 'RUB']); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Authorization: Bearer YOUR_TOKEN' ]); $response = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } else { echo 'Status Code: ' . $httpcode . "\n"; echo $response; } curl_close($ch); ?> ``` ```Python import requests import json url = "https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxPortfolio" payload = { "accountId": "string", "currency": "RUB" } headers = { "Content-Type": "application/json", "Authorization": "Bearer YOUR_TOKEN" } response = requests.post(url, headers=headers, data=json.dumps(payload)) print(f"Status Code: {response.status_code}") print(response.json()) ``` -------------------------------- ### GetPortfolio Request Example (Python) Source: https://developer.tbank.ru/invest/api/operations-service-get-portfolio Example of how to make a GetPortfolio request using Python to the T-Invest API. ```python import requests import json url = "https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.OperationsService/GetPortfolio" headers = { "Content-Type": "application/json", "Authorization": "Bearer YOUR_TOKEN" } payload = { "accountId": "string", "currency": "RUB" } response = requests.post(url, headers=headers, data=json.dumps(payload)) print(f"Status Code: {response.status_code}") print(f"Response Data: {response.json()}") ``` -------------------------------- ### GetMarketValues Request Examples (T-Invest API) Source: https://developer.tbank.ru/invest/api/market-data-service-get-market-values This snippet provides examples of how to call the GetMarketValues method of the MarketDataService in the T-Invest API. It includes examples for various programming languages and cURL, demonstrating how to request market data for instruments. ```cURL curl -X POST \ https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.MarketDataService/GetMarketValues \ -H 'Content-Type: application/json' \ -d '{ "instrumentId": [ "string" ], "values": [ "INSTRUMENT_VALUE_UNSPECIFIED" ] }' ``` ```Go package main import ( "fmt" "log" "google.golang.org/protobuf/proto" "tinkoff/public/invest/api/contract/v1" ) func main() { data := &investapi.GetMarketValuesRequest{ InstrumentId: []string{"string"}, Values: []investapi.QuotationUnit{investapi.QuotationUnit_INSTRUMENT_VALUE_UNSPECIFIED}, } // Marshal the request to bytes requestBytes, err := proto.Marshal(data) if err != nil { log.Fatalf("Failed to marshal request: %v", err) } // In a real application, you would send requestBytes to the API endpoint fmt.Printf("Go Request Payload: %s\n", requestBytes) } ``` ```Java import com.google.protobuf.InvalidProtocolBufferException; import tinkoff.public.invest.api.contract.v1.InvestApiProto; import tinkoff.public.invest.api.contract.v1.GetMarketValuesRequest; import tinkoff.public.invest.api.contract.v1.QuotationUnit; public class MarketDataClient { public static void main(String[] args) { GetMarketValuesRequest request = GetMarketValuesRequest.newBuilder() .addInstrumentId("string") .addValues(QuotationUnit.INSTRUMENT_VALUE_UNSPECIFIED) .build(); // In a real application, you would send the serialized request to the API byte[] requestBytes = request.toByteArray(); System.out.println("Java Request Payload: " + bytesToHex(requestBytes)); } // Helper to convert bytes to hex string for display public static String bytesToHex(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (byte b : bytes) { sb.append(String.format("%02x", b)); } return sb.toString(); } } ``` ```NodeJs const investapi = require('tinkoff-invest-api'); async function getMarketValues() { const client = new investapi.InvestApiClient({ // Add your API token here token: 'YOUR_API_TOKEN', // Use the sandbox environment if needed // sandbox: true }); const request = { instrumentId: ['string'], values: [investapi.QuotationUnit.INSTRUMENT_VALUE_UNSPECIFIED], }; try { const response = await client.marketData.getMarketValues(request); console.log('Node.js Response:', response); } catch (error) { console.error('Error calling GetMarketValues:', error); } } getMarketValues(); ``` ```PHP addInstrumentId('string'); $request->addValues(QuotationUnit::INSTRUMENT_VALUE_UNSPECIFIED); try { // The SDK might have a direct method, or you might need to use gRPC or REST calls // This is a conceptual example, actual implementation depends on the SDK's capabilities // For REST, you'd typically serialize the request and send it via HTTP POST $serializedRequest = $request->serializeToString(); echo 'PHP Request Payload (serialized): ' . base64_encode($serializedRequest) . "\n"; // Example of making a REST call (if the SDK supports it directly or you implement it) // $response = $marketDataClient->GetMarketValues($request); // print_r($response); } catch (Exception $e) { echo 'Error: ' . $e->getMessage() . "\n"; } ?> ``` ```Python import grpc from tinkoff.invest import MarketDataServiceStub, GetMarketValuesRequest, QuotationUnit def get_market_values(): # Replace with your actual token and endpoint token = 'YOUR_API_TOKEN' channel_options = ( ('grpc.max_send_message_length', -1), ('grpc.max_receive_message_length', -1), ) channel = grpc.secure_channel('invest-public-api.tbank.ru:443', grpc.ssl_channel_credentials(), options=channel_options) stub = MarketDataServiceStub(channel) request = GetMarketValuesRequest( instrument_id=['string'], values=[QuotationUnit.INSTRUMENT_VALUE_UNSPECIFIED] ) try: response = stub.GetMarketValues(request, metadata={'Authorization': f'Bearer {token}'}) print('Python Response:', response) except grpc.RpcError as e: print(f'Error calling GetMarketValues: {e.code()} - {e.details()}') get_market_values() ``` -------------------------------- ### GetSandboxMaxLots Request Example (cURL) Source: https://developer.tbank.ru/invest/api/sandbox-service-get-sandbox-max-lots An example of how to call the GetSandboxMaxLots endpoint using cURL, demonstrating the necessary headers and the JSON payload. ```bash curl -X POST \ https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxMaxLots \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer YOUR_TOKEN' \ -d '{ "accountId": "string", "instrumentId": "string", "price": { "nano": 6, "units": "units" } }' ``` -------------------------------- ### GetPortfolio Request Example (cURL) Source: https://developer.tbank.ru/invest/api/operations-service-get-portfolio Example of how to make a GetPortfolio request using cURL to the T-Invest API. ```shell curl -X POST \ https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.OperationsService/GetPortfolio \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer YOUR_TOKEN' \ -d '{ "accountId": "string", "currency": "RUB" }' ``` -------------------------------- ### GetPortfolio Request Example (Node.js) Source: https://developer.tbank.ru/invest/api/operations-service-get-portfolio Example of how to make a GetPortfolio request using Node.js to the T-Invest API. ```javascript const fetch = require('node-fetch'); async function getPortfolio() { const url = 'https://invest-public-api.tbank.ru/rest/tinkoff.public.invest.api.contract.v1.OperationsService/GetPortfolio'; const requestBody = { accountId: 'string', currency: 'RUB' }; try { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer YOUR_TOKEN' }, body: JSON.stringify(requestBody) }); const data = await response.json(); console.log('Status Code:', response.status); console.log('Response Data:', data); } catch (error) { console.error('Error making request:', error); } } getPortfolio(); ``` -------------------------------- ### T-API Stop Order Request Examples Source: https://developer.tbank.ru/invest/api/stop-orders-service-post-stop-order This snippet provides examples of how to structure a stop order request using various programming languages. It includes common parameters like quantity, price, direction, and account information. The examples are designed to be used with the T-API for placing stop orders. ```cURL curl -X POST \ http://example.com/api/v1/stoporders \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer YOUR_TOKEN' \ -d '{ "quantity": "string", "price": { "nano": 6, "units": "units" }, "stopPrice": { "nano": 6, "units": "units" }, "direction": "STOP_ORDER_DIRECTION_UNSPECIFIED", "accountId": "string", "expirationType": "STOP_ORDER_EXPIRATION_TYPE_UNSPECIFIED", "stopOrderType": "STOP_ORDER_TYPE_UNSPECIFIED", "expireDate": "2025-08-29T14:11:00.714Z", "instrumentId": "string", "exchangeOrderType": "EXCHANGE_ORDER_TYPE_UNSPECIFIED", "takeProfitType": "TAKE_PROFIT_TYPE_UNSPECIFIED", "trailingData": { "indent": { "nano": 6, "units": "units" }, "indentType": "TRAILING_VALUE_UNSPECIFIED", "spread": { "nano": 6, "units": "units" }, "spreadType": "TRAILING_VALUE_UNSPECIFIED" }, "priceType": "PRICE_TYPE_UNSPECIFIED", "orderId": "string", "confirmMarginTrade": true }' ``` ```Go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { requestBody := map[string]interface{}{ "quantity": "string", "price": map[string]interface{}{"nano": 6, "units": "units"}, "stopPrice": map[string]interface{}{"nano": 6, "units": "units"}, "direction": "STOP_ORDER_DIRECTION_UNSPECIFIED", "accountId": "string", "expirationType": "STOP_ORDER_EXPIRATION_TYPE_UNSPECIFIED", "stopOrderType": "STOP_ORDER_TYPE_UNSPECIFIED", "expireDate": "2025-08-29T14:11:00.714Z", "instrumentId": "string", "exchangeOrderType": "EXCHANGE_ORDER_TYPE_UNSPECIFIED", "takeProfitType": "TAKE_PROFIT_TYPE_UNSPECIFIED", "trailingData": map[string]interface{}{ "indent": map[string]interface{}{"nano": 6, "units": "units"}, "indentType": "TRAILING_VALUE_UNSPECIFIED", "spread": map[string]interface{}{"nano": 6, "units": "units"}, "spreadType": "TRAILING_VALUE_UNSPECIFIED" }, "priceType": "PRICE_TYPE_UNSPECIFIED", "orderId": "string", "confirmMarginTrade": true } requestBodyBytes, err := json.Marshal(requestBody) if err != nil { fmt.Println("Error marshaling JSON:", err) return } resp, err := http.Post("http://example.com/api/v1/stoporders", "application/json", bytes.NewBuffer(requestBodyBytes)) if err != nil { fmt.Println("Error sending request:", err) return } defer resp.Body.Close() fmt.Println("Status Code:", resp.StatusCode) } ``` ```Java import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; public class StopOrderRequest { public static void main(String[] args) { try { URL url = new URL("http://example.com/api/v1/stoporders"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Authorization", "Bearer YOUR_TOKEN"); connection.setDoOutput(true); String jsonPayload = "{\"quantity\": \"string\", \"price\": { \"nano\": 6, \"units\": \"units\" }, \"stopPrice\": { \"nano\": 6, \"units\": \"units\" }, \"direction\": \"STOP_ORDER_DIRECTION_UNSPECIFIED\", \"accountId\": \"string\", \"expirationType\": \"STOP_ORDER_EXPIRATION_TYPE_UNSPECIFIED\", \"stopOrderType\": \"STOP_ORDER_TYPE_UNSPECIFIED\", \"expireDate\": \"2025-08-29T14:11:00.714Z\", \"instrumentId\": \"string\", \"exchangeOrderType\": \"EXCHANGE_ORDER_TYPE_UNSPECIFIED\", \"takeProfitType\": \"TAKE_PROFIT_TYPE_UNSPECIFIED\", \"trailingData\": { \"indent\": { \"nano\": 6, \"units\": \"units\" }, \"indentType\": \"TRAILING_VALUE_UNSPECIFIED\", \"spread\": { \"nano\": 6, \"units\": \"units\" }, \"spreadType\": \"TRAILING_VALUE_UNSPECIFIED\" }, \"priceType\": \"PRICE_TYPE_UNSPECIFIED\", \"orderId\": \"string\", \"confirmMarginTrade\": true }"; try (OutputStream os = connection.getOutputStream()) { byte[] input = jsonPayload.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } int responseCode = connection.getResponseCode(); System.out.println("Status Code: " + responseCode); } catch (Exception e) { e.printStackTrace(); } } } ``` ```NodeJs const fetch = require('node-fetch'); async function placeStopOrder() { const url = 'http://example.com/api/v1/stoporders'; const token = 'YOUR_TOKEN'; const requestBody = { quantity: "string", price: { nano: 6, units: "units" }, stopPrice: { nano: 6, units: "units" }, direction: "STOP_ORDER_DIRECTION_UNSPECIFIED", accountId: "string", expirationType: "STOP_ORDER_EXPIRATION_TYPE_UNSPECIFIED", stopOrderType: "STOP_ORDER_TYPE_UNSPECIFIED", expireDate: "2025-08-29T14:11:00.714Z", instrumentId: "string", exchangeOrderType: "EXCHANGE_ORDER_TYPE_UNSPECIFIED", takeProfitType: "TAKE_PROFIT_TYPE_UNSPECIFIED", trailingData: { indent: { nano: 6, units: "units" }, indentType: "TRAILING_VALUE_UNSPECIFIED", spread: { nano: 6, units: "units" }, spreadType: "TRAILING_VALUE_UNSPECIFIED" }, priceType: "PRICE_TYPE_UNSPECIFIED", orderId: "string", confirmMarginTrade: true }; try { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }, body: JSON.stringify(requestBody) }); console.log('Status Code:', response.status); const data = await response.json(); console.log('Response Data:', data); } catch (error) { console.error('Error placing stop order:', error); } } placeStopOrder(); ``` ```PHP 'string', 'price' => ['nano' => 6, 'units' => 'units'], 'stopPrice' => ['nano' => 6, 'units' => 'units'], 'direction' => 'STOP_ORDER_DIRECTION_UNSPECIFIED', 'accountId' => 'string', 'expirationType' => 'STOP_ORDER_EXPIRATION_TYPE_UNSPECIFIED', 'stopOrderType' => 'STOP_ORDER_TYPE_UNSPECIFIED', 'expireDate' => '2025-08-29T14:11:00.714Z', 'instrumentId' => 'string', 'exchangeOrderType' => 'EXCHANGE_ORDER_TYPE_UNSPECIFIED', 'takeProfitType' => 'TAKE_PROFIT_TYPE_UNSPECIFIED', 'trailingData' => [ 'indent' => ['nano' => 6, 'units' => 'units'], 'indentType' => 'TRAILING_VALUE_UNSPECIFIED', 'spread' => ['nano' => 6, 'units' => 'units'], 'spreadType' => 'TRAILING_VALUE_UNSPECIFIED' ], 'priceType' => 'PRICE_TYPE_UNSPECIFIED', 'orderId' => 'string', 'confirmMarginTrade' => true ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestBody)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Authorization: Bearer ' . $token ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch); } else { echo 'Status Code: ' . $httpCode . "\n"; echo 'Response: ' . $response; } curl_close($ch); ?> ``` ```Python import requests import json url = 'http://example.com/api/v1/stoporders' token = 'YOUR_TOKEN' request_body = { "quantity": "string", "price": {"nano": 6, "units": "units"}, "stopPrice": {"nano": 6, "units": "units"}, "direction": "STOP_ORDER_DIRECTION_UNSPECIFIED", "accountId": "string", "expirationType": "STOP_ORDER_EXPIRATION_TYPE_UNSPECIFIED", "stopOrderType": "STOP_ORDER_TYPE_UNSPECIFIED", "expireDate": "2025-08-29T14:11:00.714Z", "instrumentId": "string", "exchangeOrderType": "EXCHANGE_ORDER_TYPE_UNSPECIFIED", "takeProfitType": "TAKE_PROFIT_TYPE_UNSPECIFIED", "trailingData": { "indent": {"nano": 6, "units": "units"}, "indentType": "TRAILING_VALUE_UNSPECIFIED", "spread": {"nano": 6, "units": "units"}, "spreadType": "TRAILING_VALUE_UNSPECIFIED" }, "priceType": "PRICE_TYPE_UNSPECIFIED", "orderId": "string", "confirmMarginTrade": True } headers = { 'Content-Type': 'application/json', 'Authorization': f'Bearer {token}' } try: response = requests.post(url, headers=headers, data=json.dumps(request_body)) print(f"Status Code: {response.status_code}") print(f"Response: {response.json()}") except requests.exceptions.RequestException as e: print(f"Error placing stop order: {e}") ```