### GET /fapi/v3/order Example Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-testnet.md Example of querying an order using the GET /fapi/v3/order endpoint. Requires authentication. ```javascript const axios = require('axios'); async function queryOrder() { const url = 'https://testnet-api.aster.finance/fapi/v3/order'; const apiKey = 'YOUR_API_KEY'; const apiSecret = 'YOUR_API_SECRET'; const timestamp = Date.now(); const params = { symbol: 'BTCUSDT', orderId: 123456789, recvWindow: 5000, timestamp: timestamp }; // Generate signature (implementation depends on your crypto library) const signature = generateSignature(params, apiSecret); params.signature = signature; try { const response = await axios.get(url, { headers: { 'X-MBX-APIKEY': apiKey }, params: params }); console.log('Order details:', response.data); } catch (error) { console.error('Error querying order:', error.response ? error.response.data : error.message); } } // Placeholder for signature generation function function generateSignature(params, apiSecret) { // Implement your HMAC-SHA256 signature generation here return 'SIGNATURE'; } queryOrder(); ``` -------------------------------- ### Get Position Information (Hedge Mode - Short) Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-v3.md Example response for a short position in hedge mode. Details include entry price, isolated margin, and unrealized profit. ```javascript {"entryPrice": "0.00000", "marginType": "isolated", "isAutoAddMargin": "false", "isolatedMargin": "5413.95799991", "leverage": "10", "liquidationPrice": "7189.95", "markPrice": "6679.50671178", "maxNotionalValue": "20000000", "positionAmt": "-10.000", "symbol": "BTCUSDT", "unRealizedProfit": "-1156.46711780", "positionSide": "SHORT", "updateTime": 0} ``` -------------------------------- ### Get All Open Orders Response Example Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-testnet.md This is an example of the JSON response when retrieving all open orders. Note the specific fields for TRAILING_STOP_MARKET orders. ```javascript [ { "avgPrice": "0.00000", "clientOrderId": "abc", "cumQuote": "0", "executedQty": "0", "orderId": 1917641, "origQty": "0.40", "origType": "TRAILING_STOP_MARKET", "price": "0", "reduceOnly": false, "side": "BUY", "positionSide": "SHORT", "status": "NEW", "stopPrice": "9300", // please ignore when order type is TRAILING_STOP_MARKET "closePosition": false, "symbol": "BTCUSDT", "time": 1579276756075, // order time "timeInForce": "GTC", "type": "TRAILING_STOP_MARKET", "activatePrice": "9020", // activation price, only return with TRAILING_STOP_MARKET order "priceRate": "0.3", // callback rate, only return with TRAILING_STOP_MARKET order "updateTime": 1579276756075, // update time "workingType": "CONTRACT_PRICE", "priceProtect": false // if conditional order trigger is protected } ] ``` -------------------------------- ### POST /fapi/v3/order Example Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-testnet.md Example of placing a new order using the POST /fapi/v3/order endpoint. Requires authentication. ```javascript const axios = require('axios'); async function placeOrder() { const url = 'https://testnet-api.aster.finance/fapi/v3/order'; const apiKey = 'YOUR_API_KEY'; const apiSecret = 'YOUR_API_SECRET'; const timestamp = Date.now(); const params = { symbol: 'BTCUSDT', side: 'BUY', type: 'LIMIT', timeInForce: 'GTC', quantity: 0.001, price: 30000, recvWindow: 5000, timestamp: timestamp }; // Generate signature (implementation depends on your crypto library) const signature = generateSignature(params, apiSecret); params.signature = signature; try { const response = await axios.post(url, null, { headers: { 'X-MBX-APIKEY': apiKey }, params: params }); console.log('Order placed successfully:', response.data); } catch (error) { console.error('Error placing order:', error.response ? error.response.data : error.message); } } // Placeholder for signature generation function function generateSignature(params, apiSecret) { // Implement your HMAC-SHA256 signature generation here return 'SIGNATURE'; } placeOrder(); ``` -------------------------------- ### POST /fapi/v3/order example Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-v3.md This section provides an example of how to place a new order using the POST /fapi/v3/order endpoint. It details the request parameters and structure. ```APIDOC ## POST /fapi/v3/order ### Description Places a new order on the futures market. This endpoint supports various order types and parameters for precise trade execution. ### Method POST ### Endpoint /fapi/v3/order ### Parameters #### Request Body - **symbol** (string) - Required - The trading symbol (e.g., "BTCUSDT") - **side** (string) - Required - Order side, either BUY or SELL - **type** (string) - Required - Order type, e.g., "LIMIT", "MARKET", "STOP_MARKET" - **timeInForce** (string) - Optional - How long an order is active, e.g., "GTC", "IOC", "FOK" - **quantity** (decimal) - Required - The number of contracts to trade - **price** (decimal) - Required (for LIMIT orders) - The price at which to place the order - **newClientOrderId** (string) - Optional - An unique id for the order, this can be used by client to generate order id. - **stopPrice** (decimal) - Optional - Used with STOP or STOP_MARKET orders, the price at which to trigger the stop order - **workingType** (string) - Optional - The type of stop order, e.g., "STOP_MARKET" or "MARKET" - **priceProtect** (string) - Optional - Used with STOP_MARKET orders to enable/disable price protection - **newOrderRespType** (string) - Optional - Set the response format for new orders, e.g., "ACK", "FULL" ### Request Example { "symbol": "BTCUSDT", "side": "BUY", "type": "LIMIT", "timeInForce": "GTC", "quantity": "0.001", "price": "60000.00", "newClientOrderId": "my_unique_id_123" } ### Response #### Success Response (200) - **orderId** (long) - The unique identifier for the order - **clientOrderId** (string) - The client-generated order ID - **symbol** (string) - The trading symbol - **side** (string) - The order side (BUY or SELL) - **type** (string) - The order type - **status** (string) - The current status of the order (e.g., "NEW", "PARTIALLY_FILLED", "FILLED") - **cummulativeQuoteQty** (decimal) - The total quantity filled so far - **executedQty** (decimal) - The quantity executed so far - **avgPrice** (decimal) - The average execution price - **origQty** (decimal) - The original order quantity - **price** (decimal) - The order price - **activatePrice** (decimal) - The activation price for stop orders - **stopPrice** (decimal) - The stop price for stop orders - **workingType** (string) - The working type of the stop order - **priceProtect** (string) - Price protection status - **updateTime** (long) - The time when the order was last updated #### Response Example { "orderId": 123456789, "clientOrderId": "my_unique_id_123", "symbol": "BTCUSDT", "side": "BUY", "type": "LIMIT", "status": "NEW", "cummulativeQuoteQty": "0.00000000", "executedQty": "0.00000000", "avgPrice": "0.00000000", "origQty": "0.001", "price": "60000.00", "activatePrice": "0.00000000", "stopPrice": "0.00000000", "workingType": "STOP_MARKET", "priceProtect": "false", "updateTime": 1678886400000 } ``` -------------------------------- ### Get Position Information (Hedge Mode - Long) Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-v3.md Example response for a long position in hedge mode. Includes entry price, leverage, liquidation price, and unrealized profit. ```javascript {"entryPrice": "6563.66500", "marginType": "isolated", "isAutoAddMargin": "false", "isolatedMargin": "15517.54150468", "leverage": "10", "liquidationPrice": "5930.78", "markPrice": "6679.50671178", "maxNotionalValue": "20000000", "positionAmt": "20.000", "symbol": "BTCUSDT", "unRealizedProfit": "2316.83423560", "positionSide": "LONG", "updateTime": 1625474304765} ``` -------------------------------- ### Get User Futures Fills Response Example Source: https://github.com/asterdex/api-docs/blob/master/RPC/aster-chain-rpc.md This snippet demonstrates a typical JSON response when querying user futures fills. It includes the address, account privacy status, start and end times, and a list of individual trade fills with details like symbol, side, price, quantity, and time. ```javascript { "result": { "address": "0x87EC27*********************", "accountPrivacy": "disabled", "startTime": 1773916057398, "endTime": 1774520857398, "fills": [ { "symbol": "BTCUSDT", "side": "BUY", "price": "69999", "qty": "0.001", "time": 1774233564000 }, { "symbol": "BTCUSDT", "side": "SELL", "price": "70658.6", "qty": "0.001", "time": 1774084612000 }, { "symbol": "ETHUSDT", "side": "BUY", "price": "1971", "qty": "0.013", "time": 1774084518000 }, { "symbol": "BTCUSDT", "side": "BUY", "price": "70676.7", "qty": "0.001", "time": 1774084489000 } ] }, "id": {}, "jsonrpc": "2.0" } ``` -------------------------------- ### Place Multiple Orders Request Example Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-v3.md This example demonstrates the structure of a request to place multiple orders. The `batchOrders` parameter accepts a list of order objects, each defining the parameters for an individual order. ```javascript [ { "clientOrderId": "testOrder", "cumQty": "0", "cumQuote": "0", "executedQty": "0", "orderId": 22542179, "avgPrice": "0.00000", "origQty": "10", "price": "0", "reduceOnly": false, "side": "BUY", "positionSide": "SHORT", "status": "NEW", "stopPrice": "9300", // please ignore when order type is TRAILING_STOP_MARKET "symbol": "BTCUSDT", "timeInForce": "GTC", "type": "TRAILING_STOP_MARKET", "origType": "TRAILING_STOP_MARKET", "activatePrice": "9020", // activation price, only return with TRAILING_STOP_MARKET order "priceRate": "0.3", // callback rate, only return with TRAILING_STOP_MARKET order "updateTime": 1566818724722, "workingType": "CONTRACT_PRICE", "priceProtect": false // if conditional order trigger is protected }, { "code": -2022, "msg": "ReduceOnly Order is rejected." } ] ``` -------------------------------- ### Query Open Order Response Example Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-testnet.md This is an example of the JSON response when querying an open order. It includes details like average price, executed quantity, order status, and symbol. ```javascript { "avgPrice": "0.00000", "clientOrderId": "abc", "cumQuote": "0", "executedQty": "0", "orderId": 1917641, "origQty": "0.40", "origType": "TRAILING_STOP_MARKET", "price": "0", "reduceOnly": false, "side": "BUY", "positionSide": "SHORT", "status": "NEW", "stopPrice": "9300", // please ignore when order type is TRAILING_STOP_MARKET "closePosition": false, "symbol": "BTCUSDT", "time": 1579276756075, // order time "timeInForce": "GTC", "type": "TRAILING_STOP_MARKET", "activatePrice": "9020", // activation price, only return with TRAILING_STOP_MARKET order "priceRate": "0.3", // callback rate, only return with TRAILING_STOP_MARKET order "updateTime": 1579276756075, "workingType": "CONTRACT_PRICE", "priceProtect": false } ``` -------------------------------- ### Withdraw by FAPI v3 (EVM) Request Example (Shell) Source: https://github.com/asterdex/api-docs/blob/master/demo/aster-deposit-withdrawal.md Example cURL command for initiating a user withdrawal on an EVM-compatible chain using FAPI v3. Ensure the userSignature is generated according to Pro API-KEY Signature (V3) instructions. ```shell curl --location --request POST 'https://fapi.asterdex.com/fapi/v3/aster/user-withdraw?chainId=56&asset=USDT&amount=31&fee=0.3&receiver=0x000ae314e2a2172a039b26378814c252734f556a&userNonce=1761210000000000&userSignature=0xde4ca529eef20db136eed1daf1d072083431d5279e6d6e219600cf57161c5e6d1232af3c8a8ef37ba8b5963f439ef9cc2b475fe18dcc3732dda9fb93c94a3abd1c' \ --header 'Content-Type: application/json' ``` -------------------------------- ### Position Information Response (Hedge Mode) Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-testnet.md Example response for the GET /fapi/v3/positionRisk endpoint when using the hedge position mode. Shows separate entries for long and short positions. ```javascript [ { "entryPrice": "6563.66500", "marginType": "isolated", "isAutoAddMargin": "false", "isolatedMargin": "15517.54150468", "leverage": "10", "liquidationPrice": "5930.78", "markPrice": "6679.50671178", "maxNotionalValue": "20000000", "positionAmt": "20.000", "symbol": "BTCUSDT", "unRealizedProfit": "2316.83423560" "positionSide": "LONG", "updateTime": 1625474304765 }, { "entryPrice": "0.00000", "marginType": "isolated", "isAutoAddMargin": "false", "isolatedMargin": "5413.95799991", "leverage": "10", "liquidationPrice": "7189.95", "markPrice": "6679.50671178", "maxNotionalValue": "20000000", "positionAmt": "-10.000", "symbol": "BTCUSDT", "unRealizedProfit": "-1156.46711780" "positionSide": "SHORT", "updateTime": 0 } ] ``` -------------------------------- ### Get Position Information (One-way Mode) Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-v3.md Example response for current position information when using the one-way position mode. It shows details like entry price, margin type, and unrealized profit. ```javascript [{"entryPrice": "0.00000", "marginType": "isolated", "isAutoAddMargin": "false", "isolatedMargin": "0.00000000", "leverage": "10", "liquidationPrice": "0", "markPrice": "6679.50671178", "maxNotionalValue": "20000000", "positionAmt": "0.000", "symbol": "BTCUSDT", "unRealizedProfit": "0.00000000", "positionSide": "BOTH", "updateTime": 0}] ``` -------------------------------- ### Start User Data Stream Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-v3.md Starts a new user data stream. If an active listenKey exists, it will be returned and its validity extended. The stream closes after 60 minutes without a keepalive. ```APIDOC ## Start User Data Stream (USER_STREAM) ### Description Starts a new user data stream. The stream will close after 60 minutes unless a keepalive is sent. If the account has an active `listenKey`, that `listenKey` will be returned and its validity will be extended for 60 minutes. ### Method POST ### Endpoint /fapi/v3/listenKey ### Parameters None ### Response #### Success Response (200) - **listenKey** (string) - The unique key for the user data stream. ``` -------------------------------- ### Portfolio Line Chart Request Example Source: https://github.com/asterdex/api-docs/blob/master/bapi/aster-bapi-en.md Example of a request body to fetch portfolio line chart data for a 30-day period. The 'period' field is optional and defaults to '24h' if not provided. ```json { "period": "30d" } ``` -------------------------------- ### Withdraw by FAPI v3 (Solana) Request Example (Shell) Source: https://github.com/asterdex/api-docs/blob/master/demo/aster-deposit-withdrawal.md Example cURL command for initiating a user withdrawal on the Solana chain using FAPI v3. The userSignature must be generated following the Pro API-KEY Signature (V3) guidelines. ```shell curl --location --request POST 'https://fapi.asterdex.com/fapi/v3/aster/user-solana-withdraw?chainId=101&asset=USDT&amount=3&fee=0.6&receiver=4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf&userNonce=1773741793787000&userSignature=51pM5A46n5NzHYTtuzB7gh8FFfbkh4Aij1fceCZV2NtkiVvE7DADMnSvXFiUJvauKawdWaCfPhzCTVfXYcf1iteQ' \ --header 'Content-Type: application/json' ``` -------------------------------- ### Get User Futures Fills Request Example Source: https://github.com/asterdex/api-docs/blob/master/RPC/aster-chain-rpc.md This snippet shows how to make a POST request to the /info endpoint to query user futures fills using the aster_userFills method. It includes parameters for address, symbol, time range, and block tag. ```shell curl -X POST "https://tapi.asterdex.com/info" \ -H "accept: */*" \ -H "Content-Type: application/json" \ -d '{ "id": {}, "jsonrpc": "2.0", "method": "aster_userFills", "params": [ "0x87EC27*********************", null, null, null, "latest" ] }' ``` -------------------------------- ### Get User's Force Orders Response Example Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-v3.md This snippet displays the JSON response structure for retrieving user's force orders. It includes details for filled orders with different types like IOC and GTC, and various order parameters. ```javascript [ { "orderId": 6071832819, "symbol": "BTCUSDT", "status": "FILLED", "clientOrderId": "autoclose-1596107620040000020", "price": "10871.09", "avgPrice": "10913.21000", "origQty": "0.001", "executedQty": "0.001", "cumQuote": "10.91321", "timeInForce": "IOC", "type": "LIMIT", "reduceOnly": false, "closePosition": false, "side": "SELL", "positionSide": "BOTH", "stopPrice": "0", "workingType": "CONTRACT_PRICE", "origType": "LIMIT", "time": 1596107620044, "updateTime": 1596107620087 } { "orderId": 6072734303, "symbol": "BTCUSDT", "status": "FILLED", "clientOrderId": "adl_autoclose", "price": "11023.14", "avgPrice": "10979.82000", "origQty": "0.001", "executedQty": "0.001", "cumQuote": "10.97982", "timeInForce": "GTC", "type": "LIMIT", "reduceOnly": false, "closePosition": false, "side": "BUY", "positionSide": "SHORT", "stopPrice": "0", "workingType": "CONTRACT_PRICE", "origType": "LIMIT", "time": 1596110725059, "updateTime": 1596110725071 } ] ``` -------------------------------- ### Response Example Source: https://github.com/asterdex/api-docs/blob/master/demo/aster-deposit-withdrawal.md Example of a successful response for a transaction or record query. ```APIDOC ### Response Example ```json [ { "id": "1234567", "type": "DEPOSIT", "asset": "USDT", "amount": "100", "state": "SUCCESS", "txHash": "0x9a40f0119b670fb6b155744b51981f91c4c4c8a20c333441a63853fe7d055c90", "time": 1742198400000, "chainId": 56, "accountType": "spot" } ] ``` | field | desc | |-------------|----------------------------------------------------------------------| | id | Record ID | | type | Record type: `DEPOSIT` or `WITHDRAW` | | asset | Asset name, e.g., USDT | | amount | Amount | | state | Status: `PROCESSING`, `SUCCESS`, or `FAILED` | | txHash | On-chain transaction hash | | time | Record time in milliseconds (Unix) | | chainId | Chain ID | | accountType | Account type: `spot` or `perp` | ``` -------------------------------- ### Portfolio Line Calendar Response Example Source: https://github.com/asterdex/api-docs/blob/master/bapi/aster-bapi-en.md This is an example of the response structure for the Portfolio Line Calendar endpoint. It includes daily balance, PnL, and other relevant financial metrics. ```json { "code": "000000", "data": [ { "dt": "2026-05-01", "balance": "9800.00", "pnl": "-20.00", "perpBalance": "6800.00", "perpPnl": "-30.00", "perpTradePnl": "-25.00", "shieldTradePnl": "5.00", "spotBalance": "2000.00", "spotPnl": "10.00", "stakingBalance": "1000.00", "stakingPnl": "0.00", "predictionPnl": "0.00", "allSPnl": "10.00", "period": null, "futureUid": 123456789 } ] } ``` -------------------------------- ### Place Order using Signed API (Python) Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-spot-api-v3.md Demonstrates how to place an order using the Aster Finance Spot API V3 with signed authentication. This example uses EIP712 for signing and shows how to construct the request, sign it, and send it via URL parameters or request body. ```python import time import urllib import threading import requests from eth_account.messages import encode_structured_data from eth_account import Account typed_data = { "types": { "EIP712Domain": [ {"name": "name", "type": "string"}, {"name": "version", "type": "string"}, {"name": "chainId", "type": "uint256"}, {"name": "verifyingContract", "type": "address"} ], "Message": [ { "name": "msg", "type": "string" } ] }, "primaryType": "Message", "domain": { "name": "AsterSignTransaction", "version": "1", "chainId": 1666, "verifyingContract": "0x0000000000000000000000000000000000000000" }, "message": { "msg": "$msg" } } headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'PythonApp/1.0' } host = 'https://sapi.asterdex.com' # config your user and agent info here user = '*' signer = '*' private_key = "*" place_order = {"url":"/api/v3/order","method":"POST","params":{"symbol": "ASTERUSDT", "type": "LIMIT", "side": "BUY", "timeInForce": "GTC", "quantity": "100", "price": "0.4"}} _last_ms = 0 _i = 0 _nonce_lock = threading.Lock() def get_nonce(): global _last_ms, _i with _nonce_lock: now_ms = int(time.time()) if now_ms == _last_ms: _i += 1 else: _last_ms = now_ms _i = 0 return now_ms * 1_000_000 + _i def send_by_url(api) : my_dict = api['params'] url = host + api['url'] my_dict['nonce'] = str(get_nonce()) my_dict['signer'] = signer param = urllib.parse.urlencode(my_dict) print(param) typed_data['message']['msg'] = param message = encode_structured_data(typed_data) signed = Account.sign_message(message, private_key=private_key) url = url + '?' + param + '&signature=' + signed.signature.hex() print(url) res = requests.post(url, headers=headers) print(res.text) def send_by_body(api) : my_dict = api['params'] url = host +api['url'] my_dict['nonce'] = str(get_nonce()) my_dict['signer'] = signer param = urllib.parse.urlencode(my_dict) typed_data['message']['msg'] = param message = encode_structured_data(typed_data) signed = Account.sign_message(message, private_key=private_key) print(signed.signature.hex()) my_dict['signature'] = signed.signature.hex() print(my_dict) res = requests.post(url, data=my_dict, headers=headers) print(res.text) if __name__ == '__main__': send_by_url(place_order) # send_by_body(place_order) ``` -------------------------------- ### Place Order via URL (Python) Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-testnet.md Demonstrates how to place a limit order by constructing the request URL with parameters and signature. Ensure your user, signer, and privateKey are correctly configured. ```python import json import time import urllib import threading import requests from eth_account.messages import encode_structured_data from eth_account import Account typed_data = { "types": { "EIP712Domain": [ {"name": "name", "type": "string"}, {"name": "version", "type": "string"}, {"name": "chainId", "type": "uint256"}, {"name": "verifyingContract", "type": "address"} ], "Message": [ { "name": "msg", "type": "string" } ] }, "primaryType": "Message", "domain": { "name": "AsterSignTransaction", "version": "1", "chainId": 714, "verifyingContract": "0x0000000000000000000000000000000000000000" }, "message": { "msg": "$msg" } } headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'PythonApp/1.0' } host = 'https://fapi.asterdex-testnet.com' # config your user and agent info here user = '*' signer = '*' private_key = '*' place_order = {"url":"/fapi/v3/order","method":"POST","params":{"symbol": "ASTERUSDT", "type": "LIMIT", "side": "BUY", "timeInForce": "GTC", "quantity": "20", "price": "0.5"}} batch_orders = {"url":"/fapi/v3/batchOrders","method":"POST","params":{ "batchOrders":"[{'symbol':'ASTERUSDT','type':'LIMIT','side':'BUY','timeInForce':'GTC','quantity':'20','price':'0.5'},{'symbol':'ASTERUSDT','type':'LIMIT','side':'BUY','timeInForce':'GTC','quantity':'20','price':'0.5'}]" }} listen_key = {"url":"/fapi/v3/listenKey","method":"POST","params":{}} _last_ms = 0 _i = 0 _nonce_lock = threading.Lock() def get_nonce(): global _last_ms, _i with _nonce_lock: now_ms = int(time.time()) if now_ms == _last_ms: _i += 1 else: _last_ms = now_ms _i = 0 return now_ms * 1_000_000 + _i def send_by_url(api) : my_dict = api['params'] url = host + api['url'] my_dict['nonce'] = str(get_nonce()) my_dict['signer'] = signer param = urllib.parse.urlencode(my_dict) print(param) typed_data['message']['msg'] = param message = encode_structured_data(typed_data) signed = Account.sign_message(message, private_key=private_key) url = url + '?' + param + '&signature=' + signed.signature.hex() print(url) res = requests.post(url, headers=headers) print(res.text) def send_by_body(api) : my_dict = api['params'] url = host +api['url'] my_dict['nonce'] = str(get_nonce()) my_dict['signer'] = signer param = urllib.parse.urlencode(my_dict) typed_data['message']['msg'] = param message = encode_structured_data(typed_data) signed = Account.sign_message(message, private_key=private_key) print(signed.signature.hex()) my_dict['signature'] = signed.signature.hex() print(my_dict) res = requests.post(url, data=my_dict, headers=headers) # print(res.headers) print(res.text) if __name__ == '__main__': send_by_url(place_order) # send_by_url(listen_key) # send_by_url(batch_orders) # send_by_body(place_order) # send_by_body(batch_orders) ``` -------------------------------- ### Get Position Margin Change History Response Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-testnet.md Example response structure for the GET /fapi/v3/positionMargin/history endpoint, showing details of margin changes for a position. ```javascript [ { "amount": "23.36332311", "asset": "USDT", "symbol": "BTCUSDT", "time": 1578047897183, "type": 1, "positionSide": "BOTH" }, { "amount": "100", "asset": "USDT", "symbol": "BTCUSDT", "time": 1578047900425, "type": 1, "positionSide": "LONG" } ] ``` -------------------------------- ### Generate Listen Key (Spot Account) Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-spot-api-testnet.md Use this endpoint to start a new user data stream. If a listen key already exists, it will be returned and its validity extended. The stream will close after 60 minutes without a keepalive. ```javascript { "listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1" } ``` -------------------------------- ### Get Direct Announcements Response Example Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-v3.md This JSON object represents a successful response from the GET /fapi/v3/announcement/direct endpoint, showing announcement details including multi-language content, category, and publish time. ```json { "total": 2, "rows": [ { "id": 1001, "contents": [ { "language": "en", "title": "Platform Maintenance Notice", "subtitle": "Scheduled downtime", "content": "The platform will undergo scheduled maintenance on 2026-06-20 from 02:00 to 04:00 UTC." }, { "language": "zh", "title": "平台维护公告", "subtitle": "定期停机", "content": "平台将于2026年6月20日UTC时间02:00至04:00进行定期维护。" } ], "category": "MAINTENANCE", "publishTime": 1750000000000, "jumpLink": "https://www.asterdex.com/en/announcement/1001" } ] } ``` -------------------------------- ### Place Order using Aster Finance API (Python) Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-prediction-api.md Example of how to place an order using the POST /api/v3/order endpoint. It includes generating a nonce, signing the request using EIP712, and sending the request either as URL parameters or in the request body. ```python import time import urllib import threading import requests from eth_account.messages import encode_structured_data from eth_account import Account typed_data = { "types": { "EIP712Domain": [ {"name": "name", "type": "string"}, {"name": "version", "type": "string"}, {"name": "chainId", "type": "uint256"}, {"name": "verifyingContract", "type": "address"} ], "Message": [ { "name": "msg", "type": "string" } ] }, "primaryType": "Message", "domain": { "name": "AsterSignTransaction", "version": "1", "chainId": 1666, "verifyingContract": "0x0000000000000000000000000000000000000000" }, "message": { "msg": "$msg" } } headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'PythonApp/1.0' } host = 'https://papi.asterdex.com' # config your user and agent info here user = '*' signer = '*' private_key = "*" place_order = {"url":"/api/v3/order","method":"POST","params":{"symbol": "ASTERUSDT", "type": "LIMIT", "side": "BUY", "timeInForce": "GTC", "quantity": "100", "price": "0.4"}} _last_ms = 0 _i = 0 _nonce_lock = threading.Lock() def get_nonce(): global _last_ms, _i with _nonce_lock: now_ms = int(time.time()) if now_ms == _last_ms: _i += 1 else: _last_ms = now_ms _i = 0 return now_ms * 1_000_000 + _i def send_by_url(api) : my_dict = api['params'] url = host + api['url'] my_dict['nonce'] = str(get_nonce()) my_dict['signer'] = signer param = urllib.parse.urlencode(my_dict) print(param) typed_data['message']['msg'] = param message = encode_structured_data(typed_data) signed = Account.sign_message(message, private_key=private_key) url = url + '?' + param + '&signature=' + signed.signature.hex() print(url) res = requests.post(url, headers=headers) print(res.text) def send_by_body(api) : my_dict = api['params'] url = host +api['url'] my_dict['nonce'] = str(get_nonce()) my_dict['signer'] = signer param = urllib.parse.urlencode(my_dict) typed_data['message']['msg'] = param message = encode_structured_data(typed_data) signed = Account.sign_message(message, private_key=private_key) print(signed.signature.hex()) my_dict['signature'] = signed.signature.hex() print(my_dict) res = requests.post(url, data=my_dict, headers=headers) print(res.text) if __name__ == '__main__': send_by_url(place_order) # send_by_body(place_order) ``` -------------------------------- ### Get Server Time Request Source: https://github.com/asterdex/api-docs/blob/master/demo/aster-deposit-withdrawal.md Example of a cURL request to fetch the current server time from the Asterdex API. ```shell curl 'https://fapi5.asterdex.com/fapi/v3/time' ``` -------------------------------- ### WebSocket Stream Response - Get Property Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-futures-api-testnet.md Example of a successful response when retrieving a property, indicating the current value of the requested property. ```javascript { "result": true, "id": 2 } ``` -------------------------------- ### GET /api/v3/historicalTrades Source: https://github.com/asterdex/api-docs/blob/master/V3(Recommended)/EN/aster-finance-spot-api-testnet.md Retrieves historical trades for a given symbol. This endpoint allows querying trades starting from a specific trade ID. ```APIDOC ## GET /api/v3/historicalTrades ### Description Retrieves historical trades for a given symbol. This endpoint allows querying trades starting from a specific trade ID. ### Method GET ### Endpoint /api/v3/historicalTrades ### Parameters #### Query Parameters - **symbol** (STRING) - Required - The trading symbol. - **limit** (INT) - Optional - The maximum number of trades to return. Default is 500; maximum is 1000. - **fromId** (LONG) - Optional - Return starting from which trade id. Defaults to returning the most recent trade records. ### Response #### Success Response (200) - **id** (integer) - The trade ID. - **price** (string) - The price of the trade. - **qty** (string) - The quantity of the trade. - **baseQty** (string) - The quantity of the base asset in the trade. - **time** (long) - The timestamp of the trade. - **isBuyerMaker** (boolean) - Whether the buyer was the maker. ### Request Example ```json [ { "id": 1140, "price": "1.10000000", "qty": "7.27200000", "baseQty": "6.61090909", "time": 1756094288700, "isBuyerMaker": false } ] ``` ```