API文档
一、API使用说明
1、请求过程说明
1.1 构造请求数据,用户数据按照COOLCOIN提供的接口规则,通过程序生成签名和要传输给COOLCOIN的数据集合;
1.2 发送请求数据,把构造完成的数据集合通过POST/GET提交的方式传递给COOLCOIN;
1.3 COOLCOIN对请求数据进行处理,服务器在接收到请求后,会首先进行安全校验,验证通过后便会处理该次发送过来的请求;
1.4 返回响应结果数据,COOLCOIN把响应结果以JSON的格式反馈给用户,具体的响应格式,错误代码参见接口部分;
1.5 对获取的返回结果数据进行处理;
2、安全认证
所有的private API都需要经过认证
Api的申请可以到财务中心 -> API,申请得到私钥和公钥,私钥COOLCOIN将不做储存,一旦丢失将无法找回
注意:请勿向任何人泄露这两个参数,这像您的密码一样重要
2.签名机制
每次请求private api 都需要验证签名,发送的参数示例:
$param = array(
amount => 1,
price => 10000,
type => 'buy',
nonce => 141377098123
key => 5zi7w-4mnes-swmc4-egg9b-f2iqw-396z4-g541b
signature => 459c69d25c496765191582d9611028b9974830e9dfafd762854669809290ed82
);
nonce 可以理解为一个递增的整数:http://zh.wikipedia.org/wiki/Nonce
key 是申请到的公钥
signature是签名,是将amount price type nonce key等参数通过'&'字符连接起来通过md5(私钥)为key进行sha256算法加密得到的值.
3、接口
Ticker(牌价)
Path:/api/v1/ticker/
Request类型:GET
参数
coin - eth
region - btc|usc
返回JSON dictionary
high - 最高价
low - 最低价
buy - 买一价
sell - 卖一价
last - 最近一次成交价
vol - 成交量
返回结果示例:
{"high":22,"low":20,"buy":1.879,"sell":0,"last":38800,"vol":283.954}
Depth(市场深度)
描述:返回所有的市场深度,此回应的数据量会较大,所以请勿频繁调用。
Path:/api/v1/depth/
Request类型:GET
参数
coin - eth
region - btc|usc
返回JSON dictionary
asks - 委卖单[价格, 委单量],价格从低到高排序
bids - 委买单[价格, 委单量],价格从高到低排序
返回结果示例:
{"asks":[[70000,5],[69000,0.48],[67000,0.9999],[64498,0.02],[61160,0.017],[60980,0.03],[60000,0.1924],[55900,1.4],[55100,2],[55044,0.019],[54500,0.7836],[54190,1],[52500,5.8645],[51500,5.6594],[51490,0.02],[47500,7],[45999,0.0244],[44585,0.024],[43000,10],[41700,10],[41300,6],[40900,10],[40500,6],[40125,10.0277],[40100,5],[40089,0.509],[39800,14.7132],[39799,0.0695],[39798,5],[39700,2.89],[39000,0.209]],"bids":[[38300,1.879],[38100,1.0078],[38000,1.24],[37700,4.706],[37600,3.8313],[37001,0.146],[36999,5.8],[36400,5],[36200,1.3314],[36002,2],[36000,1.568],[35501,0.282],[35500,9.9],[35200,5.6],[35010,10],[35001,0.03],[34600,7.6],[34500,5.505],[34200,9.3],[34000,6.4],[33800,4.434],[33333,3],[32830,0.0305],[31800,2],[31500,3.018],[30001,0.03],[30000,11.48],[28000,10],[25001,0.04],[22000,5.863],[20001,0.05],[460,10]]}
Orders(市场交易)
描述:返回100个最近的市场交易,按时间倒序排列,此回应的数据量会较大,所以请勿频繁调用。
Path:/api/v1/orders/
Request类型:GET
参数
coin - eth
region - btc|usc
返回JSON dictionary
date - 时间戳
price - 交易价格
amount - 交易数量
tid - 交易ID
type - 交易类型
返回结果示例:
[{"date":"0","price":3,"amount":0.1,"tid":"1","type":"buy"},{"date":"0","price":32323,"amount":2,"tid":"2","type":"sell"},{"date":"0","price":32,"amount":432,"tid":"3","type":"sell"},{"date":"0","price":323,"amount":2,"tid":"4","type":"sell"},{"date":"0","price":2100,"amount":0.3,"tid":"5","type":"buy"}]
只读权限方法列表
Account Balance(账户信息)
列举您的帐户信息
Path:/api/v1/balance/
Request类型:POST
参数
key - API key
signature - signature
nonce - nonce
返回JSON dictionary
eth_balance - ETH总余额
btc_balance - 比特币总余额
eth_lock - ETH冻结余额
btc_lock - 比特币冻结余额
返回结果示例:
{"result":true,"data":{"uid":"1","xas_balance":1,"xas_lock":0,"eth_balance":1,"eth_lock":0,"btc_balance":1,"btc_lock":0,"usc_balance":1,"usc_lock":0}}
Trade_list(挂单查询)
您指定时间后的挂单,可以根据类型查询,比如查看正在挂单和全部挂单
Path:/api/v1/trade_list/
Request类型:POST
参数
key - API key
signature - signature
nonce - nonce
since - unix timestamp(utc timezone) default == 0, i.e. 返回所有
coin - eth
region - btc|usc
type - 挂单类型[open:正在挂单, all:所有挂单]
返回JSON dictionary
id - 挂单ID
coin - eth
datetime - date and time
type - "buy" or "sell"
price - price
amount_original - 下单时数量
amount_outstanding - 当前剩余数量
返回结果示例:
{"result":true,"data":[{"id":"28","datetime":"2016-10-26 14:47:54","type":"sell","price":0.000123,"amount_original":1213,"amount_outstanding":1213}]}
Trade_view(查询订单信息)
Path:/api/v1/trade_view/
Request类型:POST
参数
key - API key
signature - signature
nonce - nonce
id - 挂单ID
coin - eth
region - btc|usc
返回JSON dictionary
id - 挂单ID
datetime - 挂单时间(格式:YYYY-mm-dd HH:ii:ss)
type - "buy" or "sell"
price - 挂单价
amount_original - 下单时数量
amount_outstanding - 当前剩余数量
status - 状态:new(新挂单), open(开放交易), cancelled(撤消), closed(完全成交)
返回结果示例:
{"result":true,"data":{"id":28,"datetime":"2016-10-26 14:47:54","type":"sell","price":0.000123,"amount_original":1213,"amount_outstanding":1213,"status":"open"}}
完整权限方法列表
Trade_cancel(取消订单)
Path:/api/v1/trade_cancel/
Request类型:POST
参数
key - API key
signature - signature
nonce - nonce
id - 挂单ID
coin - eth
region - btc|usc
返回JSON dictionary
result - true(成功), false(失败)
id - 订单ID
返回结果示例:
{"result":true, "id":"11"}
Trade_add(下单)
Path:/api/v1/trade_add/
Request类型:POST
参数
key - API key
signature - signature
nonce - nonce
amount - 购买数量
price - 购买价格
type - 买单或者卖单
coin - eth
region - btc|usc
返回JSON dictionary
id - 挂单ID
result - true(成功), false(失败)
返回结果示例:
{"result":true, "id":"11"}
数据类型
*_balance - float
id - int
datetime - datetime
since - int
type - string
price - float
amount* - float
status - string
trade_id - int
fee - float
result - bool
message - string
address - string
DEMO
错误代码对照表
错误代码 | 详细描述 |
---|---|
100 | 必选参数不能为空 |
101 | 非法参数 |
102 | 请求的虚拟币不存在 |
103 | 密钥不存在 |
104 | 签名不匹配 |
105 | 权限不足 |
106 | 请求过期(nonce错误) |
200 | 余额不足 |
201 | 买卖的数量小于最小买卖额度 |
202 | 下单价格必须在 0 - 1000000 之间 |
203 | 订单不存在 |
204 | 挂单金额必须在 0.001 BTC以上 |
205 | 限制挂单价格 |
206 | 小数位错误 |
401 | 系统错误 |
402 | 请求过于频繁 |
403 | 非开放API |
404 | IP限制不能请求该资源 |
405 | 币种交易暂时关闭 |