Skip to content

WebSocket Account Info

WebSocket account information push

  • The base URL for the API endpoints listed in this document is: https://sapi.asterdex.com
  • The listenKey used to subscribe to account data is valid for 60 minutes from the time of creation
  • You can extend the 60-minute validity of a listenKey by sending a PUT request
  • You can immediately close the current data stream and invalidate the listenKey by sending a DELETE for a listenKey
  • Sending a POST on an account with a valid listenKey will return the currently valid listenKey and extend its validity by 60 minutes
  • The WebSocket interface baseurl: wss://sstream.asterdex.com
  • The stream name for subscribing to the user account data stream is **/ws/**
  • Each connection is valid for no more than 24 hours; please handle disconnections and reconnections appropriately

Listen Key (spot account)

Generate Listen Key (USER_STREAM)

Response

{
  "listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1"
}

POST /api/v3/listenKey

Start a new data stream. The data stream will be closed after 60 minutes unless a keepalive is sent. If the account already has a valid listenKey, that listenKey will be returned and its validity extended by 60 minutes.

Weight: 1

Parameters: NONE

Extend Listen Key validity period (USER_STREAM)

Response

{}

PUT /api/v3/listenKey

Validity extended to 60 minutes after this call. It is recommended to send a ping every 30 minutes.

Weight: 1

Parameters:

Name Type Is it required? Description
listenKey STRING YES

Close Listen Key (USER_STREAM)

Response

{}

DELETE /api/v3/listenKey

Close user data stream

Weight: 1

Parameters:

Name Type Is it required? Description
listenKey STRING YES

Payload: ACCOUNT_UPDATE

An outboundAccountPosition event is sent whenever an account balance changes; it contains the assets that may have changed due to the event that generated the balance update.

Payload

{
  "B":[  //Balance
    {
      "a":"SLP25",   //Asset
      "f":"10282.42029415",   //Free
      "l":"653.00000001"   //Locked
    },
    {
      "a":"ADA25",
      "f":"9916.96229880",
      "l":"34.00510000"
    }
  ],
  "e":"outboundAccountPosition",   //Event type
  "T":1649926447190,   //Time of last account update
  "E":1649926447205   //Event Time
  "m":"WITHDRAW" // Event reason type
}

Payload: Order Update

Orders are updated via the executionReport event

Payload

{
 "s":"ADA25SLP25",   // symbol
  "c":"Xzh0gnxT41PStbwqOtXnjD",  // client order id
  "S":"SELL",   // order direction
  "o":"LIMIT",   // order type
  "f":"GTC",   // Time in force
  "q":"10.001000",   // Order quantity
  "p":"19.1000000000",   // Order price
  "ap":"19.0999999955550656",  //average price
  "P":"0",  //stop price
  "x":"TRADE",   // Current execution type
  "X":"PARTIALLY_FILLED",   // Current order status
  "i":27,   // Order ID
  "l":"1",    // Last executed quantity   
  "z":"8.999000",   // Cumulative filled quantity
  "L":"19.1000000000",   // Last executed price
  "n":"0.00382000",   // Commission amount
  "N":"SLP25",   // Commission asset
  "T":1649926447190,   //Trasanction Time
  "t":18,   // transaction id
  "m":true,   // is this trade the maker side?
  "ot":"LIMIT", //original order type
  "O":0,   // Order creation time
  "Z":"171.88089996",   // Cumulative quote asset transacted quantity
  "Y":"19.1000000000000000",   // Last quote asset transacted quantity (i.e. lastPrice * lastQty)
  "Q":"0",   // Quote Order Qty
  "e":"executionReport",   // event
  "E":1649926447209  // event time
}  

Execution type:

  • NEW - New Order
  • CANCELED - Order canceled
  • REJECTED - New order was rejected
  • TRADE - Order had a new fill
  • EXPIRED - Order expired (based on the order's Time In Force parameter)

Event: TradePro

Topic Subscribe:

{
  "method": "SUBSCRIBE",
  "params": [
    "btcusdt@tradepro"
  ],
  "id": 3
}

Payload:

{
    "stream": "btcusdt@tradepro",
    "data": {
        "e": "tradepro",
        "E": 1773751963081,
        "T": 1773751963079,
        "s": "BTCUSDT",
        "t": 128884613,
        "p": "73685.5",
        "q": "0.297",
        "h": "0X0000000000000000000000000000000000000000000000000000000000000000",
        "m": [
            "hidden",
            "hidden"
        ]
    }
}
  • h: Transaction hash of the trade.

  • m: Array containing the participant addresses:

    • m[0]: Taker address

    • m[1]: Maker address

#错误代码

error JSON payload:

{
  "code":-1121,
  "msg":"Invalid symbol."
}

Errors consist of two parts: an error code and a message. The code is standardized, but the message may vary.

10xx - General server or network issues

-1000 UNKNOWN

  • An unknown error occurred while processing the request.

-1001 DISCONNECTED

  • Internal error; unable to process your request. Please try again.

-1002 UNAUTHORIZED

  • You are not authorized to execute this request.

-1003 TOO_MANY_REQUESTS

  • Too many requests queued.
  • Too many requests; please use the WebSocket for live updates.
  • Too many requests; current limit is %s requests per minute. Please use the WebSocket for live updates to avoid polling the API.
  • Too many request weights; IP banned until %s. Please use the WebSocket for live updates to avoid bans.

-1004 DUPLICATE_IP

  • This IP is already on the white list.

-1005 NO_SUCH_IP

  • No such IP has been whitelisted.

-1006 UNEXPECTED_RESP

  • An unexpected response was received from the message bus. Execution status unknown.

-1007 TIMEOUT

  • Timeout waiting for response from backend server. Send status unknown; execution status unknown.

-1014 UNKNOWN_ORDER_COMPOSITION

  • The current order parameter combination is not supported.

-1015 TOO_MANY_ORDERS

  • Too many new orders.
  • Too many new orders; the current limit is %s orders per %s.

-1016 SERVICE_SHUTTING_DOWN

  • This service is no longer available.

-1020 UNSUPPORTED_OPERATION

  • This operation is not supported.

-1022 INVALID_SIGNATURE

  • The signature for this request is invalid.

-1023 START_TIME_GREATER_THAN_END_TIME

  • The start time in the parameters is after the end time.

11xx - Request issues

-1100 ILLEGAL_CHARS

  • Illegal characters found in a parameter.
  • Illegal characters found in parameter %s; legal range is %s.

-1101 TOO_MANY_PARAMETERS

  • Too many parameters sent for this endpoint.
  • Too many parameters; expected %s and received %s.
  • Duplicate values for a parameter detected.

-1102 MANDATORY_PARAM_EMPTY_OR_MALFORMED

  • A mandatory parameter was not sent, was empty/null, or malformed.
  • Mandatory parameter %s was not sent, was empty/null, or malformed.
  • Param %s or %s must be sent, but both were empty/null.

-1103 UNKNOWN_PARAM

  • An unknown parameter was sent.

-1104 UNREAD_PARAMETERS

  • Not all sent parameters were read.
  • Not all sent parameters were read; read %s parameter(s) but %s parameter(s) were sent.

-1105 PARAM_EMPTY

  • A parameter was empty.
  • Parameter %s was empty.

-1106 PARAM_NOT_REQUIRED

  • A parameter was sent when not required. 

-1111 BAD_PRECISION

  • The precision exceeds the maximum defined for this asset.

-1112 NO_DEPTH

  • No open orders for the trading pair.

-1114 TIF_NOT_REQUIRED

  • TimeInForce parameter sent when not required.

-1115 INVALID_TIF

  • Invalid timeInForce.

-1116 INVALID_ORDER_TYPE

  • Invalid orderType.

-1117 INVALID_SIDE

  • Invalid order side.

-1118 EMPTY_NEW_CL_ORD_ID

  • New client order ID was empty.

-1119 EMPTY_ORG_CL_ORD_ID

  • The client’s custom order ID is empty.

-1120 BAD_INTERVAL

  • Invalid time interval.

-1121 BAD_SYMBOL

  • Invalid trading pair.

-1125 INVALID_LISTEN_KEY

  • This listenKey does not exist.

-1127 MORE_THAN_XX_HOURS

  • The query interval is too large.
  • More than %s hours between startTime and endTime.

-1128 OPTIONAL_PARAMS_BAD_COMBO

  • Combination of optional parameters invalid. 

-1130 INVALID_PARAMETER

  • The parameter sent contains invalid data.
  • Data sent for parameter %s is not valid. 

-1136 INVALID_NEW_ORDER_RESP_TYPE

  • Invalid newOrderRespType. 

20xx - Processing Issues

-2010 NEW_ORDER_REJECTED

  • New order rejected.

-2011 CANCEL_REJECTED

  • Order cancellation rejected.

-2013 NO_SUCH_ORDER

  • Order does not exist.

-2014 BAD_API_KEY_FMT

  • API-key format invalid.

-2015 REJECTED_MBX_KEY

  • Invalid API key, IP, or permissions for action.

-2016 NO_TRADING_WINDOW

  • No trading window could be found for the symbol. Try ticker/24hrs instead.

-2018 BALANCE_NOT_SUFFICIENT

  • Balance is insufficient.

-2020 UNABLE_TO_FILL

  • Unable to fill.

-2021 ORDER_WOULD_IMMEDIATELY_TRIGGER

  • Order would immediately trigger.

-2022 REDUCE_ONLY_REJECT

  • ReduceOnly Order is rejected.

-2024 POSITION_NOT_SUFFICIENT

  • Position is not sufficient.

-2025 MAX_OPEN_ORDER_EXCEEDED

  • Reached max open order limit.

-2026 REDUCE_ONLY_ORDER_TYPE_NOT_SUPPORTED

  • This OrderType is not supported when reduceOnly.

40xx - Filters and other Issues

-4000 INVALID_ORDER_STATUS

  • Invalid order status.

-4001 PRICE_LESS_THAN_ZERO

  • Price less than 0.

-4002 PRICE_GREATER_THAN_MAX_PRICE

  • Price greater than max price.

-4003 QTY_LESS_THAN_ZERO

  • Quantity less than zero.

-4004 QTY_LESS_THAN_MIN_QTY

  • Quantity less than minimum quantity.

-4005 QTY_GREATER_THAN_MAX_QTY

  • Quantity greater than maximum quantity.

-4006 STOP_PRICE_LESS_THAN_ZERO

  • Stop price less than zero.

-4007 STOP_PRICE_GREATER_THAN_MAX_PRICE

  • Stop price greater than max price.

-4008 TICK_SIZE_LESS_THAN_ZERO

  • Tick size less than zero.

-4009 MAX_PRICE_LESS_THAN_MIN_PRICE

  • Max price less than min price.

-4010 MAX_QTY_LESS_THAN_MIN_QTY

  • Maximum quantity less than minimum quantity.

-4011 STEP_SIZE_LESS_THAN_ZERO

  • Step size less than zero.

-4012 MAX_NUM_ORDERS_LESS_THAN_ZERO

  • Maximum order quantity less than 0.

-4013 PRICE_LESS_THAN_MIN_PRICE

  • Price less than minimum price.

-4014 PRICE_NOT_INCREASED_BY_TICK_SIZE

  • Price not increased by tick size.

-4015 INVALID_CL_ORD_ID_LEN

  • Client order ID is not valid.
  • Client order ID length should not be more than 36 characters.

-4016 PRICE_HIGHTER_THAN_MULTIPLIER_UP

  • Price is higher than mark price multiplier cap.

-4017 MULTIPLIER_UP_LESS_THAN_ZERO

  • Multiplier up less than zero.

-4018 MULTIPLIER_DOWN_LESS_THAN_ZERO

  • Multiplier down less than zero.

-4019 COMPOSITE_SCALE_OVERFLOW

  • Composite scale too large.

-4020 TARGET_STRATEGY_INVALID

  • Target strategy invalid for orderType %s, reduceOnly %b'

-4021 INVALID_DEPTH_LIMIT

  • Invalid depth limit.
  • %s is not a valid depth limit.

-4022 WRONG_MARKET_STATUS

  • Market status sent is not valid.

-4023 QTY_NOT_INCREASED_BY_STEP_SIZE

  • The increment of the quantity is not a multiple of the step size.

-4024 PRICE_LOWER_THAN_MULTIPLIER_DOWN

  • Price is lower than mark price multiplier floor.

-4025 MULTIPLIER_DECIMAL_LESS_THAN_ZERO

  • Multiplier decimal less than zero.

-4026 COMMISSION_INVALID

  • Commission invalid.
  • Incorrect profit value.
  • %s less than zero.
  • %s absolute value greater than %s.

-4027 INVALID_ACCOUNT_TYPE

  • Invalid account type.

-4029 INVALID_TICK_SIZE_PRECISION

  • Tick size precision is invalid.
  • Price decimal precision is incorrect.

-4030 INVALID_STEP_SIZE_PRECISION

  • The number of decimal places for the step size is incorrect.

-4031 INVALID_WORKING_TYPE

  • Invalid parameter working type: %s

-4032 EXCEED_MAX_CANCEL_ORDER_SIZE

  • Exceeds the maximum order quantity that can be canceled.
  • Invalid parameter working type: %s

-4044 INVALID_BALANCE_TYPE

  • The balance type is incorrect.

-4045 MAX_STOP_ORDER_EXCEEDED

  • Reached the stop-loss order limit.

-4055 AMOUNT_MUST_BE_POSITIVE

  • The quantity must be a positive integer.

-4056 INVALID_API_KEY_TYPE

  • The API key type is invalid.

-4057 INVALID_RSA_PUBLIC_KEY

  • The API key is invalid.

-4058 MAX_PRICE_TOO_LARGE

  • maxPrice and priceDecimal too large, please check.

-4060 INVALID_POSITION_SIDE

  • Invalid position side.

-4061 POSITION_SIDE_NOT_MATCH

  • The order's position direction does not match the user’s settings.

-4062 REDUCE_ONLY_CONFLICT

  • Invalid or improper reduceOnly value.

-4084 UPCOMING_METHOD

  • Method is not allowed currently. Coming soon.

-4086 INVALID_PRICE_SPREAD_THRESHOLD

  • Invalid price spread threshold.

-4087 REDUCE_ONLY_ORDER_PERMISSION

  • Users can only place reduce-only orders.

-4088 NO_PLACE_ORDER_PERMISSION

  • User cannot place orders currently.

-4114 INVALID_CLIENT_TRAN_ID_LEN

  • clientTranId is not valid.
  • The customer's tranId length should be less than 64 characters.

-4115 DUPLICATED_CLIENT_TRAN_ID

  • clientTranId is duplicated.
  • The client's tranId should be unique within 7 days.

-4118 REDUCE_ONLY_MARGIN_CHECK_FAILED

  • ReduceOnly Order failed. Please check your existing position and open orders

-4131 MARKET_ORDER_REJECT

  • The counterparty's best price does not meet the PERCENT_PRICE filter limit.

-4135 INVALID_ACTIVATION_PRICE

  • Invalid activation price.

-4137 QUANTITY_EXISTS_WITH_CLOSE_POSITION

  • Quantity must be zero when closePosition is true.

-4138 REDUCE_ONLY_MUST_BE_TRUE

  • Reduce only must be true when closePosition is true.

-4139 ORDER_TYPE_CANNOT_BE_MKT

  • Order type cannot be a market order if it cannot be canceled.

-4140 INVALID_OPENING_POSITION_STATUS

  • Invalid symbol status for opening position.

-4141 SYMBOL_ALREADY_CLOSED

  • Trading pair has been delisted.

-4142 STRATEGY_INVALID_TRIGGER_PRICE

  • Rejected: Take Profit or Stop order would be triggered immediately.

-4164 MIN_NOTIONAL

  • Order notional must be at least 5.0 (unless you select Reduce Only)
  • Order notional must be no smaller than %s (unless you choose Reduce Only)

-4165 INVALID_TIME_INTERVAL

  • Invalid time interval
  • Maximum time interval is %s days

-4183 PRICE_HIGHTER_THAN_STOP_MULTIPLIER_UP

  • Limit price cannot be higher than the cap of %s.
  • Take-Profit/Stop-Loss price cannot be higher than the cap of %s.

-4184 PRICE_LOWER_THAN_STOP_MULTIPLIER_DOWN

  • Price is below the stop price limit.
  • Take-Profit/Stop-Loss price must be above the trigger price × multiplier floor.
  • Order price (limit or TP/SL) can’t be below %s.