NAV Navbar
json

Change Log

2021-04-14

1st release of API document.

General Info

General API Information

HTTP Return Codes

General Information on Endpoints

Authentication

Overview

The API request may be tampered during internet, therefore all private API must be signed by your API Key (Secrete Key).

Each API Key has permission property, please check the API permission, and make sure your API key has proper permission.

A valid request consists of below parts:

Signature Method

The signature may be different if the request text is different, therefore the request should be normalized before signing. Below signing steps take the order query as an example:

This is a full URL to query one order:

https://api.moonxbt.com/v1/orders/history/get

AccessKeyId=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx

&SignatureMethod=HmacSHA256

&SignatureVersion=2

&Timestamp=2020-05-11T15:19:30

&code=1234567890

  1. The request Method (GET or POST, WebSocket use GET), append line break “\n”

GET\n

  1. The host with lower case, append line break “\n”

Example: api.moonxbt.com\n

  1. The path, append line break “\n”

For example, query orders:

/v1/order/orders/history/get\n

For example, WebSocket v1

/ws/v1

  1. The parameters are URL encoded, and ordered based on ASCII

For example below is the original parameters:

AccessKeyId=ylxxxxxx-t9xxxxxx-uixxxxxx-9xxxxxx

code=1234567890

SignatureMethod=HmacSHA256

SignatureVersion=1

Timestamp=2017-05-11T15%3A19%3A30

Use UTF-8 encoding and URL encoded, the hex must be upper case. For example, The semicolon ':' should be encoded as '%3A', The space should be encoded as '%20'. The 'timestamp' should be formated as 'YYYY-MM-DDThh:mm:ss' and URL encoded. Then above parameter should be ordered like below:

AccessKeyId=ylxxxxxx-t9xxxxxx-uixxxxxx-9xxxxxx

SignatureMethod=HmacSHA256

SignatureVersion=1

Timestamp=2020-05-11T15%3A19%3A30

code=1234567890

  1. Use char “&” to concatenate all parameters

AccessKeyId=ylxxxxxx-t9xxxxxx-uixxxxxx-9xxxxxx&SignatureMethod=HmacSHA256&SignatureVersion=1&Timestamp=2020-05-11T15%3A19%3A30&code=1234567890

  1. Assemble the pre-signed text

GET\n

api.moonxbt.com\n

/v1/order/orders/history/get\n

AccessKeyId=ylxxxxxx-t9xxxxxx-uixxxxxx-9xxxxxx&SignatureMethod=HmacSHA256&SignatureVersion=1&Timestamp=2020-05-11T15%3A19%3A30&code=1234567890

  1. Use the pre-signed text and your Secret Key to generate a signature

Use the pre-signed text in above step and your API Secret Key to generate hash code by HmacSHA256 hash function. Encode the hash code with base-64 to generate the signature. Ef65x8IDLyMWVQj3Aqp+B4w+ivaA8d9Oi2SuYtCJ9o=

  1. Put the signature into request URL

For Rest interface:

Put all the parameters in the URL Append the signature in the URL, with parameter name “Signature”. Finally, the request sent to API should be:

https://api.moonxbt.com/v1/orders/history/get?AccessKeyId=ylxxxxxx-t9xxxxxx-uixxxxxx-9xxxxxx&code=1234567890&SignatureMethod=HmacSHA256&SignatureVersion=1&Timestamp=2017-05-11T15%3A19%3A30&Signature=4F65x5A2bLyMWVQj3Aqp%2BB4w%2BivaA7n5Oi2SuYtCJ9o%3D

For WebSocket interface:

Fill the value according to required JSON schema The value in JSON doesn't require URL encode For example:


{
  "AccessKey":"ylxxxxxx-t9xxxxxx-uixxxxxx-9xxxxxx",
  "SignatureMethod":"HmacSHA256",
  "SignatureVersion":"1",
  "Timestamp":"2020-09-01T18:16:16",
  "Signature":"Ef65x8IDLyMWVQj3Aqp+B4w+ivaA8d9Oi2SuYtCJ9o="
}

K-Line Endpoints

API Key Permission:Read.

This endpoint returns a list of K-lines history data for all public users.

HTTP Request: GET /v1/kline/{symbol}/{kType}/{size}

Reqeust Parameters

Parameter Description Mandatory Data Type Value Range
kType Data range true integer 1: 1 day, 2: 1 min, 3: 5 mins, 4: 15 mins, 5: 1 hour, 7: 4 hours
size Fetch size true integer 1-200
symbol Trading symbol (wildcard inacceptable) true string btcusd, ltcusd, xrpusd, eosusd, ethusd, adausd, bchusd, etcusd, linkusd, bnbusd, trxusd...

Response Content:

{
    "code": 0,
    "data": [
        {
            "open": 9313.2881,
            "close": 9316.2478,
            "low": 9260.2442,
            "high": 9390.1536,
            "vol": 4190.569625,
            "time": 1589414400
        }
    ],
    "message": "Success",
    "time": "2020-05-14 11:07:46"
}
Field Description Data Type
code Return code integer
data Return data (if avaliable, check below Kline Entity ) array
message Return message string
time Return timestamp string

Kline Entity

Field Description Data Type
close Close price number
high High price number
low Low price number
open Open price number
time Market Timestamp long
vol Volume number

K-Line WebSocket streams

API Key Permission:Read.

This WebSocket returns a list of K-lines history data for owned by this API user.

WebSocket Path: wss://api.moonxbt.com/ws/v1/kline

Reqeust Parameters

{

  "kType": 1,
  "symbol": "btcusd",
  "size": 10
}

Parameter Description Mandatory Data Type Value Range
kType Data range true integer 1: 1 day, 2: 1 min, 3: 5 mins, 4: 15 mins, 5: 1 hour, 7: 4 hours
size Fetch size true integer 1-200
symbol Trading symbol (wildcard inacceptable) true string btcusd, ltcusd, xrpusd, eosusd, ethusd, adausd, bchusd, etcusd

Response Content:

{
    "code": 0,
    "data": "PONG",
    "message": "Success",
    "time": "2020-05-14 11:07:46"
}
{
    "code": 0,
    "data": [
        {
            "open": 9313.2881,
            "close": 9316.2478,
            "low": 9260.2442,
            "high": 9390.1536,
            "vol": 4190.569625,
            "time": 1589414400
        }
    ],
    "message": "Success",
    "time": "2020-05-14 11:07:46"
}
Field Description Data Type
code Return code integer
data Return data (if avaliable, check below Kline Entity ) array
message Return message string
time Return timestamp string

Kline Entity

Field Description Data Type
close Close price number
high High price number
low Low price number
open Open price number
time Market Timestamp long
vol Volume number

Trading Endpoints

Position History

API Key Permission:Read

This endpoint returns a list of historical orders owned by this API user.

HTTP Request: GET /v1/orders/history/get

Reqeust Parameters

Parameter Description Mandatory Data Type Value Range
code Order Code false string -
direction Order Type false integer 1: up, 2: down
deviceType Device Type false string iOS, Android, Web
currencyName Currency Name false string btcusd, eosusd, ltcusd, adausd, xrpusd, ethusd, etcusd, bchusd
begin Filter start time false string Format yyyy-MM-dd HH:mm:ss
end Filter end time false string Format yyyy-MM-dd HH:mm:ss

Response Content:

{
    "message": "Success",
    "time": "2020-05-14 11:58:06",
    "code": 0,
    "data": [
            {
                "id": null,
                "code": "fd14628655274ae98b5e86741e1c1558",
                "cid": 2,
                "cusSuperior": null,
                "direction": 0,
                "amount": 150,
                "orderTime": "2020-02-22 18:50:44",
                "strikePrice": 8662.642,
                "settlement": 8662.642,
                "charge": 2.025,
                "profit": 0,
                "orderStatus": 1,
                "overtime": "2020-02-22 18:50:44",
                "state": 0,
                "balance": null,
                "stopLoss": 8000,
                "simulatedTrading": 0,
                "sign": 0,
                "holdPosition": null,
                "symbol": null,
                "type": 1,
                "targetProfit": 9000,
                "money": 152.025,
                "lever": 10,
                "bamoney": 0.6075,
                "interest": 14.58,
                "currencyName": "btcusd",
                "nightCount": null,
                "cusAccount": "13810000011",
                "countryCode": null,
                "countryName": null,
                "pendingTime": null,
                "deviceType": "iOS",
                "profitRate": null,
                "holdingTime": null,
                "appendCharge": null,
                "positions": 0.173157,
                "currentPrice": null,
                "normal": true,
                "simuOrder": false
            }
        ]
}
Field Description Data Type
code Return code integer
data Return data (if avaliable, check below Order Entity ) array
message Return message string
time Return timestamp string

Position Holdings

API Key Permission:Read

This endpoint returns a list of holding orders owned by this API user.

HTTP Request: GET /v1/orders/holding/get

Reqeust Parameters

Parameter Description Mandatory Data Type Value Range
code Order Code false string -
direction Order Type false integer 1: up, 2: down
deviceType Device Type false string iOS, Android, Web
currencyName Currency Name false string btcusd, eosusd, ltcusd, adausd, xrpusd, ethusd, etcusd, bchusd
begin Filter start time false string Format yyyy-MM-dd HH:mm:ss
end Filter end time false string Format yyyy-MM-dd HH:mm:ss

Response Content:

{
    "message": "Success",
    "time": "2020-05-14 11:58:06",
    "code": 0,
    "data": [
            {
                "id": null,
                "code": "fd14628655274ae98b5e86741e1c1558",
                "cid": 2,
                "cusSuperior": null,
                "direction": 0,
                "amount": 150,
                "orderTime": "2020-02-22 18:50:44",
                "strikePrice": 8662.642,
                "settlement": 8662.642,
                "charge": 2.025,
                "profit": 0,
                "orderStatus": 0,
                "overtime": "2020-02-22 18:50:44",
                "state": 0,
                "balance": null,
                "stopLoss": 8000,
                "simulatedTrading": 0,
                "sign": 0,
                "holdPosition": null,
                "symbol": null,
                "type": 1,
                "targetProfit": 9000,
                "money": 152.025,
                "lever": 10,
                "bamoney": 0.6075,
                "interest": 14.58,
                "currencyName": "btcusd",
                "nightCount": null,
                "cusAccount": "13810000011",
                "countryCode": null,
                "countryName": null,
                "pendingTime": null,
                "deviceType": "iOS",
                "profitRate": null,
                "holdingTime": "13810000011",
                "appendCharge": null,
                "positions": 0.173157,
                "currentPrice": null,
                "normal": true,
                "simuOrder": false
            }
        ]
}
Field Description Data Type
code Return code integer
data Return data (if avaliable, check below Order Entity ) array
message Return message string
time Return timestamp string

Positon Pendings

API Key Permission:Read

This endpoint returns a list of pending orders owned by this API user.

HTTP Request: GET /v1/orders/pending/get

Reqeust Parameters

Parameter Description Mandatory Data Type Value Range
code Order Code false string -
direction Order Type false integer 1: up, 2: down
deviceType Device Type false string iOS, Android, Web
currencyName Currency Name false string btcusd, eosusd, ltcusd, adausd, xrpusd, ethusd, etcusd, bchusd
begin Filter start time false string Format yyyy-MM-dd HH:mm:ss
end Filter end time false string Format yyyy-MM-dd HH:mm:ss

Response Content:

{
    "message": "Success",
    "time": "2020-05-14 11:58:06",
    "code": 0,
    "data": [
            {
                "id": null,
                "code": "fd14628655274ae98b5e86741e1c1558",
                "cid": 2,
                "cusSuperior": null,
                "direction": 0,
                "amount": 150,
                "orderTime": "2020-02-22 18:50:44",
                "strikePrice": 8662.642,
                "settlement": 8662.642,
                "charge": 2.025,
                "profit": 0,
                "orderStatus": 0,
                "overtime": "2020-02-22 18:50:44",
                "state": 0,
                "balance": null,
                "stopLoss": 8000,
                "simulatedTrading": 0,
                "sign": 0,
                "holdPosition": null,
                "symbol": null,
                "type": 1,
                "targetProfit": 9000,
                "money": 152.025,
                "lever": 10,
                "bamoney": 0.6075,
                "interest": 14.58,
                "currencyName": "btcusd",
                "nightCount": null,
                "cusAccount": "13810000011",
                "countryCode": null,
                "countryName": null,
                "pendingTime": "2020-02-22 18:50:44",
                "deviceType": "iOS",
                "profitRate": null,
                "holdingTime": "13810000011",
                "appendCharge": null,
                "positions": 0.173157,
                "currentPrice": null,
                "normal": true,
                "simuOrder": false
            }
        ]
}
Field Description Data Type
code Return code integer
data Return data (if avaliable, check below Order Entity ) array
message Return message string
time Return timestamp string

Create Order

API Key Permission:Trade

This endpoint is create order or pending order and returns ordercode and points awarded.

HTTP Request: GET /v1/orders/createOrder

Reqeust Parameters

Parameter Description Mandatory Data Type Value Range
leverage leverage true string -
startBond principal true number -
targetProfit take profit price,after reaching the price,system will try close the order true number -
stopLoss stop loss,after reaching the price,system will try close the order true number -
openPrice pending price false number -
direction order direction true integer 1: up, 2: down
currencyName Currency Name false string btcusd, eosusd...
type overnight type true integer 0: no, 1: overnight

Response Content:

{
    "message": "Success",
    "time": "2020-12-09 13:55:23",
    "code": 0,
    "data": {
        "feeBackIntegral": 0.15,
        "ordercode": "31e5e78921264f5094c9d74632847e8a"
    }
}
Field Description Data Type
code Return code integer
data Return data with ordercode and points awarded object
message Return message string
time Return timestamp string

Variation Margin

API Key Permission:Trade

This endpoint is variation order margin.

HTTP Request: GET /v1/orders/appendMargin

Reqeust Parameters

Parameter Description Mandatory Data Type Value Range
code order code true string -
appendAmount margin amount true number -

Response Content:

{
    "message": "Success",
    "time": "2020-05-14 11:58:06",
    "code": 0
}
Field Description Data Type
code Return code integer
message Return message string
time Return timestamp string

Update TP/SL Price

API Key Permission:Trade

This endpoint is update take profit price and stop loss price.

HTTP Request: GET /v1/orders/updateStandard

Reqeust Parameters

Parameter Description Mandatory Data Type Value Range
code order code true string -
targetProfit take profit price true number -
stopLoss stop loss price true number -

Response Content:

{
    "message": "Success",
    "time": "2020-05-14 11:58:06",
    "code": 0
}
Field Description Data Type
code Return code integer
message Return message string
time Return timestamp string

Change Overnight Type

API Key Permission:Trade

This endpoint is change order overnight type.

HTTP Request: GET /v1/orders/changeOverNightType

Reqeust Parameters

Parameter Description Mandatory Data Type Value Range
code order code true string -
type overnight type true number 0: no, 2: overnight

Response Content:

{
    "message": "Success",
    "time": "2020-05-14 11:58:06",
    "code": 0
}
Field Description Data Type
code Return code integer
message Return message string
time Return timestamp string

Close Pending Position

API Key Permission:Trade

This endpoint is to close the pending order.

HTTP Request: GET /v1/orders/closePendingOrder

Reqeust Parameters

Parameter Description Mandatory Data Type Value Range
code order code true string -

Response Content:

{
    "message": "Success",
    "time": "2020-05-14 11:58:06",
    "code": 0
}
Field Description Data Type
code Return code integer
message Return message string
time Return timestamp string

Close Holding Position

API Key Permission:Trade

This endpoint is close the holding order.

HTTP Request: GET /v1/orders/closeHoldingOrder

Reqeust Parameters

Parameter Description Mandatory Data Type Value Range
code order code true string -

Response Content:

{
    "message": "Success",
    "time": "2020-05-14 11:58:06",
    "code": 0
}
Field Description Data Type
code Return code integer
message Return message string
time Return timestamp string

Order Entity

Field Description Data Type
id Order Id integer
code Order Code string
cid Customer Id integer
cusSuperior Customer Supervisor integer
direction Order Type integer
amount Trading Amount number
orderTime Order Time - Format yyyy-MM-dd HH:mm:ss datetime
strikePrice Strike Price number
settlement Settle Price number
charge Service Charge number
profit Profit number
orderStatus Order Status - 0: pending, 1: finished integer
overtime Order Finish Time - Format yyyy-MM-dd HH:mm:ss datetime
state Account Status - 0: pending, 1: forced liquidation, 2: non-overnight charge, 3: manual liquidation, 4: overnight charge due integer
stopLoss Stop-loss number
simulatedTrading Flag of Simulated Trading - 0: no, 1: yes integer
sign Flag of Overnight Charge - 0: no, 1: yes integer
holdPosition Hold Position string
symbol Symbol string
type Flag of Overnight - 0: no, 1: yes integer
targetProfit Target Profit number
money Purchase Money number
lever Lever number
bamoney Overnight Charge(per day) number
interest Overnight Charge(total) number
currencyName Currency Name string
nightCount Days of Overnight number
cusAccount Customer Account number
countryCode Country Code string
countryName Country Name string
pendingTime Pending Time - Format yyyy-MM-dd HH:mm:ss datetime
deviceType Device Type - Range: iOS, Android, Web string
profitRate Profit Rate number
holdingTime Holding Time long
appendCharge Append Charge number
positions Positions number
currentPrice Current Price number
normal Order Category - true: normal, false: pending boolean
simuOrder Simulated Order - true: yes, false: no boolean

Errors

HTTP error codes

Error Code Meaning
400 Bad Request -- Your request is invalid.
401 Unauthorized -- Your API key is wrong.
403 Forbidden -- The kitten requested is hidden for administrators only.
404 Not Found -- The specified kitten could not be found.
405 Method Not Allowed -- You tried to access a kitten with an invalid method.
406 Not Acceptable -- You requested a format that isn't json.
410 Gone -- The request has been removed from our servers.
500 Internal Server Error -- We had a problem with our server. Try again later.
503 Service Unavailable -- We're temporarily offline for maintenance. Please try again later.

100xxx - Access Key & Signature Error

Error Code Meaning
100001 Access Key Not Exist -- Your should checkout your access key from website.
100002 Parameter Validation Error: %s -- You can check the detailed message to fix it.
100003 Signature Validation Failed: %s -- You can check the detailed message to fix it.
100004 AccessKey Expired -- You can bind your IP to make it permanently.
100005 Wrong IP Address for the Binding -- Your current IP Address does not match the bindings.

Public

trading-pairs

API Key Permission:Read.

Provide summary information of all trading pairs.

HTTP Request: https://api.moonxbt.com/api/v1/futures

Response Content:

{
"code": 0,
"result": [
{
    "ticker_id": SXP-PERPUSDT,
    "base_currency": SXP,
    "quote_currency": USDT,
    "last_price": 2.35500000,
    "base_volume": 8656873.8200000,
    "quote_volume": 20784373.4065800000,
    "bid": 59551.00000000,
    "ask": 7.00000000,
    "high": 2.46600000,
    "low": 2.33600000,
    "product_type": Perpetual,
    "open_interest": 0,
    "index_price": 130.60000000,
    "funding_rate": 0.0005,
    "next_funding_rate": 0.0005,
    "next_funding_rate_timestamp": 1636761600866,
    "maker_fee": 0,
    "taker_fee": 0.0005
}],
"success": true
}
Field Description Data Type
code Return code integer
result Return data array
success Return result boolean

depth

API Key Permission:Read.

Provide order book information with at least depth = 100 (50 each side) returned for a given market pair/ticker.

HTTP Request: https://api.moonxbt.com/api/v1/markets/BTC-PERPUSDT/orderbook

Reqeust Parameters

{
"depth": 100
}

Parameter Description Mandatory Data Type Value Range
depth trade depth true integer at least 100

Response Content:

{
"code": 0,
"result":
{
    "asks": [[63777.94,0.004522]],
    "bids": [[63777.93,1.078256]]
},
"ticker_id": "BTC-PERPUSDT",
"timestamp": 1637551589045,
"success": true
}
Field Description Data Type
code Return code integer
result Return data object
ticker_id Return Currency string
timestamp Return timestamp long
success Return result boolean

tickers

API Key Permission:Read.

Provide the specifications of all trading pairs, including the price and type of the contract.

HTTP Request: https://api.moonxbt.com/api/v1/tickers

Response Content:

{
"code": 0,
"result": [
{
    "ticker_id": SXP-PERPUSDT,
    "base_currency": SXP,
    "quote_currency": USDT,
    "last_price": 2.35500000,
    "base_volume": 8656873.8200000,
    "quote_volume": 20784373.4065800000,
    "bid": 59551.00000000,
    "ask": 7.00000000,
    "high": 2.46600000,
    "low": 2.33600000,
    "product_type": Perpetual,
    "open_interest": 0,
    "index_price": 130.60000000,
    "funding_rate": 0.0005,
    "next_funding_rate": 0.0005,
    "next_funding_rate_timestamp": 1636761600866,
    "maker_fee": 0,
    "taker_fee": 0.0005,
    "contract_type": linear,
    "contract_price": 2.51100000,
    "contract_price_currency": USDT
}
],
"success": true
}
Field Description Data Type
code Return code integer
result Return data array
success Return result boolean