forked from viabtc/viabtc_exchange_server
-
Notifications
You must be signed in to change notification settings - Fork 6
HTTP Protocol
Daniel Newton edited this page Oct 13, 2017
·
42 revisions
192.168.1.1:8080
The API is based on HTTP protocol using JSON RPC,HTTP request methods must be POST, URL is: / , Content-Type is: application/json
Request
- method: Method, String
- params: Parameters, Array
- id: Request id, Integer
Response
- result: Json object, null failed
- error: Json object, null success,not null failed
- code: error code
- message: error message
- id: Request id, Integer
common error codes:
- 1: invalid argument
- 2: internal error
- 3: service unavailable
- 4: method not found
- 5: service timeout
Balance query
- method:
balance.query
- params: No fixed parameters, first param is user ID, followed by a list of asset names, if the list is empty, return all the assets of the user
- user_id: ID, Integer
- result: {"asset": {"available": "amount", "freeze": "amount"}}
- example:
"params": [1, "BTC"]
"result": {"BTC": {"available": "1.10000000","freeze": "9.90000000"}}
Balance update
- method:
balance.update
- params:
- user_id: ID, Integer
- asset: Asset, String
- business: Type of action, String
- business_id: Business ID, Integer (the same user_id, asset, business and business_id can only be executed once)
- change: Change amount, String, (negative number means deduct from the balance)
- detail: Json object with any extra information
- result: "success"
- error code:
- repeat update
- balance not enough
- example:
"params": [1, "BTC", "deposit", 100, "1.2345", {"metadata": 123}]
"result": "success"
Balance history
- method:
balance.history
- params:
- user_id: User ID, Integer
- asset: Asset name, can be empty
- business: Type of action, can be empty or mutiple entries split by ','
- start_time: Start time, 0 means no limit, Integer
- end_time: End time,0 means no limit, Integer
- offset: Offset position, Integer
- limit: Record limit, Integer
- result:
{
"offset":
"limit":
"records": [
{
"time": timestamp,
"asset": asset,
"business": business,
"change": change,
"balance":balance,
"detail": detail
}
...
]
Limit order
- method:
order.put_limit
- params:
- user_id: User ID, Integer
- market: Market, String
- side: 1: list ask, 2: list bid,Integer
- amount: Amount, String
- price: Price, String
- taker_fee_rate: String, taker rate
- maker_fee_rate: String, maker reate
- source: String, source, max 30 bytes long
- result: order details
- error:
- balance not enough
- example:
params: [1, "BTCCNY", 1, "10", "8000", "0.002", "0.001"]
Market order
- method:
order.put_market
- params:
- user_id: User ID, Integer
- market: Market, String
- side: 1: list ask, 2: list bid,Integer
- amount: Amount, String
- taker_fee_rate: taker rate
- source: String, source, max 30 bytes long
- result: order details
- error:
- balance not enough
- example:
params: '[1, "BTCCNY", 1, "10","0.002"]'
Cancel order
- method:
order.cancel
- params:
- user_id: User ID
- market: Market
- order_id: Order ID
- result: order details
- error:
- order not found
- user not match
Order Transations
- method:
order.deals
- params:
- order_id: Order ID, Integer
- offset
- limit
- result:
- example:
"result": {
"offset":
"limit":
"records": [
{
"id": transaction ID
"time": timestamp
"user": user ID
"role": actor 1: Maker, 2: Taker
"amount": amount
"price": price
"deal": transaction amount
"fee": fee
"deal_order_id": counterparty transaction ID
}
...
]
Order book
- method:
order.book
- params:
- market:
- side: direction,1: ask,2: bid
- offset:
- limit:
- result:
Order depth
- method:
order.depth
- params:
- market: Market name
- limit: Limit, Integer
- interval: Interval,String, eg: "1" means intervals of 1 unit, "0" mean no interval
- result:
"result": {
"asks": [
[
"8000.00",
"9.6250"
]
],
"bids": [
[
"7000.00",
"0.1000"
]
]
}
Orders pending
- method:
order.pending
- params:
- user_id: User ID, Integer
- market: Market, String
- offset: Offet, Integer
- limit: Limit, Integer
- result:
- example:
"params": [1, "BTCCNY", 0, 100]"
"result": {
"offset": 0,
"limit": 100,
"total": 1,
"records": [
{
"id": 2,
"ctime": 1492616173.355293,
"mtime": 1492697636.238869,
"market": "BTCCNY",
"user": 2,
"type": 1, // 1: limit order,2: market order
"side": 2, // 1: ask,2: bid
"amount": "1.0000".
"price": "7000.00",
"taker_fee": "0.0020",
"maker_fee": "0.0010",
"source": "web",
"deal_money": "6300.0000000000",
"deal_stock": "0.9000000000",
"deal_fee": "0.0009000000"
}
]
}
Pending order details
- method:
order.pending_detail
- params:
- market:
- order_id: Order ID, Interger
- result:
Orders completed
- method:
order.finished
- params:
- user_id: User ID, Integer
- market: Market, String
- start_time: Start time, 0 means no limit, Integer
- end_time: End time, 0 means no limit, Integer
- offset: Offset, Integer
- limit: Limit, Integer
- side: direction,0 open/not-limited??, 1 ask, 2 bid
- result:
Order completed details
- method:
order.finished_detail
- params:
- order_id: Order ID, Interger
- result:
Market price
- method:
market.last
- params:
- market
- result: "price"
Market history
- method:
market.deals
- params:
- market:
- limit: Integer,not over 10000
- last_id: Last id
- result:
"result": [
{
"id": 5,
"time": 1492697636.238869,
"type": "sell",
"amount": "0.1000",
"price": "7000.00"
},
{
"id": 4,
"time": 1492697467.1411841,
"type": "sell",
"amount": "0.1000"
"price": "7000.00",
}
}
User transaction history
- method:
market.user_deals
- params:
- user_id: User ID, Integer
- market: Market name, String
- offset: Offset, Integer
- limit: Limit, Integer
- result:
"result": [
"offset":
"limit":
"records": [
{
"id": transaction ID
"time": timestamp
"user": user ID
"side": direction, 1: ask, 2: bid
"role": actor, 1: maker, 2: taker
"amount": amount
"price": price
"deal": transaction amount
"fee": fee
"deal_order_id": counterparty transaction ID
}
...
]
}
KLine
- method:
market.kline
- params:
- market: Market
- start: Start time, Integer
- end: End time, Integer
- interval: Number of seconds, Integer
- result:
"result": [
[
1492358400, time
"7000.00", open
"8000.0", close
"8100.00", high
"6800.00", low
"1000.00" volume
"123456.78" turnover
"BTCCNY" market name
]
]
Market status
- method:
market.status
- params:
- market: Market name
- period: Number of seconds, Integer, such as 86400 for the past 24 hours
- result:
"result": {
"period": 86400,
"last": "7000.00",
"open": "0",
"close": "0",
"high": "0",
"low": "0",
"volume": "0"
}
Todays market status
- method:
market.status_today
- params:
- market: Market name
- result:
{
"open": todays open
"last": latest price
"high": high price
"low": lowest price
"deal": 24 hour turnover
"volume": 24 hour volume
}