行情 API

获取OKCoin最新市场行情数据
接口 描述
ok_sub_spotcny_X_ticker 订阅行情数据

websocket.send("{'event':'addChannel','channel':'ok_sub_spotcny_X_ticker'}");

示例

# Request
{'event':'addChannel','channel':'ok_sub_spotcny_btc_ticker'}
# Response
[{
    "channel":"ok_sub_spotcny_btc_ticker",
    "data":{
        "buy":2478.3,
        "high":2555,
        "last":2478.51,
        "low":2466,
        "sell":2478.5,
        "timestamp":1411718074965,
        "vol":49020.30
    }
}]

返回值说明

buy(double): 买一价
high(double): 最高价
last(double): 最新成交价
low(double): 最低价
sell(double): 卖一价
timestamp(long):时间戳
vol(double): 成交量(最近的24小时)
ok_sub_spot_X_depth  New 订阅现货市场深度(200增量数据返回)

websocket.send("{'event':'addChannel','channel':'ok_sub_spot_X_depth'}");

示例

# Request
{'event':'addChannel','channel':'ok_sub_spot_btc_depth'}
# Response
[{
    "channel":"ok_sub_spot_btc_depth",
    "data":{
        "bids":[
            ["2473.88","2.025"],
            ["2473.5","2.4"],
            ["2470","12.203"]
        ],
        "asks":[
            ["2484","17.234"],
            ["2483.01","6"],
            ["2482.88","3"]
        ],
        "timestamp":1411718972024
    }
}]

返回值说明

使用描述:
	1,第一次返回全量数据
	2,根据接下来数据对第一次返回数据进行,如下操作
	删除(量为0时)
	修改(价格相同量不同)
	增加(价格不存在)
bids([string, string]):买方深度
asks([string, string]):卖方深度
timestamp(string):服务器时间戳
ok_sub_spotcny_X_depth_Y  New 订阅市场深度

websocket.send("{'event':'addChannel','channel':'ok_sub_spotcny_X_depth_Y'}");

示例

# Request
{'event':'addChannel','channel':'ok_sub_spotcny_btc_depth_20'}
# Response
[{
    "channel":"ok_sub_spotcny_btc_depth_20",
    "data":{
        "bids":[
            ["2473.88","2.025"],
            ["2473.5","2.4"],
            ["2470","12.203"]
        ],
        "asks":[
            ["2484","17.234"],
            ["2483.01","6"],
            ["2482.88","3"]
        ],
        "timestamp":1411718972024
    }
}]

返回值说明

bids([string, string]):买方深度
asks([string, string]):卖方深度
timestamp(long):服务器时间戳
ok_sub_spotcny_X_trades  New 订阅成交记录

websocket.send("{'event':'addChannel','channel':'ok_sub_spotcny_X_trades'}");

示例

# Request
{'event':'addChannel','channel':'ok_sub_spotcny_btc_trades'}
# Response
[{
    "channel":"ok_sub_spotcny_btc_trades",
    "data":[["1001","2463.86","0.052","16:34:07","ask"]]
}]

返回值说明

增量数据返回
[交易序号, 价格, 成交量, 时间, 买卖类型]
[string, string, string, string, string]
ok_sub_spotcny_X_kline_Y 订阅K线数据

websocket.send("{'event':'addChannel','channel':'ok_sub_spotcny_X_kline_Y'}");

示例

# Request
{'event':'addChannel','channel':'ok_sub_spotcny_btc_kline_1min'}
# Response
[{
    "channel":"ok_sub_spotcny_btc_kline_1min",
    "data":[
        ["1490337840000","995.37","996.75","995.36","996.75","9.112"],
        ["1490337840000","995.37","996.75","995.36","996.75","9.112"]
    ]
}]

返回值说明

[时间,开盘价,最高价,最低价,收盘价,成交量]
[string, string, string, string, string, string]

交易 API

快速进行交易
接口 描述
login  New 登录事件(个人信息推送)

示例

# Request
{"event":"login","parameters":{"api_key":"xxx","sign":"xxx"}}
# Response
[{"data":{"result":"true"},"channel":"login"}]

请求参数

参数名 描述

api_key

用户申请的apiKey

sign

请求参数的签名

说明

个人信息推送,个人数据有变化时会自动推送,其它旧的个人数据订阅类型可不订阅,
如:
ok_sub_spotcny_trades,ok_sub_spotcny_userinfo

				
ok_spotcny_trade 下单交易

websocket.send("{'event':'addChannel','channel':'ok_spotcny_trade','parameters': {'api_key':'XXXX','sign':'XXXX','symbol':'btc_cny','type':'buy','price':'50','amount':'0.02'}}");

示例

# Request
{
    'event':'addChannel',
    'channel':'ok_spotcny_trade',
    'parameters':{
        'api_key':'XXXX',
        'sign':'XXXX',
        'symbol':'btc_cny',
        'type':'buy',
        'price':'50',
        'amount':'0.02'
    }
}
# Response
[{
    "channel":"ok_spotcny_trade",
    "data":{
        "order_id":125433029,
        "result":true
    }
}]

返回值说明

order_id(long):订单号
result(boolean):执行结果

请求参数

参数名 描述

api_key

用户申请的apiKey

sign

请求参数的签名

symbol

btc_cny: 比特币 ltc_cny: 莱特币 eth_cny: 以太坊

type

买卖类型: 限价单(buy/sell) 市价单(buy_market/sell_market)

price

下单价格 [限价买单(必填): 大于等于0,小于等于1000000 | 市价买单(必填): BTC :最少买入0.01个BTC 的金额(金额>0.01*卖一价) / LTC :最少买入0.1个LTC 的金额(金额>0.1*卖一价) / ETH :最少买入0.01个ETH 的金额(金额>0.01*卖一价)](市价卖单不传price)

amount

交易数量 [限价卖单(必填):BTC 数量大于等于0.01 / LTC 数量大于等于0.1 / ETH 数量大于等于0.01 | 市价卖单(必填): BTC :最少卖出数量大于等于0.01 / LTC :最少卖出数量大于等于0.1 / ETH :最少卖出数量大于等于0.01](市价买单不传amount)

ok_spotcny_cancel_order 取消订单

websocket.send("{'event':'addChannel','channel':'ok_spotcny_cancel_order', 'parameters': {'api_key':'XXXX','sign':'XXXX','symbol':'btc_cny','order_id':'125433027'}}");

示例

# Request 
{
    'event':'addChannel',
    'channel':'ok_spotcny_cancel_order',
    'parameters':{
        'api_key':'XXXX',
        'sign':'XXXX',
        'symbol':'btc_cny',
        'order_id':'125433027'
    }
}
# Response
[{
    "channel":"ok_spotcny_cancel_order",
    "data":{
        "order_id":125433027,
        "result":true
    }
}]

返回值说明

order_id(long):订单号
result(boolean):执行结果

请求参数

参数名 描述

api_key

用户申请的apiKey

sign

请求参数的签名

symbol

btc_cny: 比特币 ltc_cny: 莱特币 eth_cny: 以太坊

order_id

订单Id

ok_spotcny_userinfo 查询账户信息

websocket.send("{'event':'addChannel','channel':'ok_spotcny_userinfo','parameters': {'api_key':'XXXX','sign':'XXXX'}}");

示例

# Request 
{
    'event':'addChannel',
    'channel':'ok_spotcny_userinfo',
    'parameters':{
        'api_key':'XXXX',
        'sign':'XXXX'
    }
}
# Response
[{
    "channel": "ok_spotcny_userinfo",
    "data": {
        "info": {
            "funds": {
                "asset": {
                    "net": "0",
                    "total": "0"
                },
                "borrow": {
                    "btc": "0",
                    "cny": "0",
                    "ltc": "0",
                    "eth": "0"
                },
                "free": {
                    "btc": "0",
                    "cny": "0",
                    "ltc": "0",
                    "eth": "0"
                },
                "freezed": {
                    "btc": "0",
                    "cny": "0",
                    "ltc": "0",
                    "eth": "0"
                },
                "union_fund": {
                    "btc": "0",
                    "ltc": "0",
                    "eth": "0"
                }
            }
        },
        "result": true
    }
}]

返回值说明

asset:账户资产,包含净资产及总资产
borrow:账户借款信息(只有在账户有借款信息时才会返回)
free:账户余额
freezed:账户冻结余额
union_fund:账户理财信息(只有在账户有理财信息时才返回)

请求参数

参数名 描述

api_key

用户申请的apiKey

sign

请求参数的签名

ok_spotcny_orderinfo 查询订单信息

websocket.send("{'event':'addChannel','channel':'ok_spotcny_orderinfo','parameters': {'api_key':'XXXX','symbol':'ltc_cny','order_id':'20914907','sign':'XXXX'}}");

示例

# Request
{
    'event':'addChannel',
    'channel':'ok_spotcny_orderinfo',
    'parameters':{
        'api_key':'XXXX',
        'sign':'XXXX',
        'symbol':'ltc_cny',
        'order_id':'20914907'
    }
}
# Response
[{
    "channel": "ok_spotcny_orderinfo",
    "data": {
        "orders": [{
            "amount": 0.1,
            "avg_price": 1.961,
            "create_date": 1422502117000,
            "deal_amount": 0.1,
            "order_id": 20914907,
            "orders_id": 20914907,
            "price": 0,
            "status": 2,
            "symbol": "ltc_cny",
            "type": "sell_market"
        }],
        "result": true
    }
}]

返回值说明

amount(double):委托数量
create_date(double): 委托时间
avg_price(long):平均成交价
deal_amount(double):成交数量
order_id(long):订单ID
orders_id(long):订单ID(不建议使用)
price(double):委托价格
status(int):-1:已撤销  0:未成交  1:部分成交  2:完全成交 4:撤单处理中,5:撤单处理中
symbol(string):币种
type(string):buy_market:市价买入 / sell_market:市价卖出

请求参数

参数名 描述

api_key

用户申请的apiKey

sign

请求参数的签名

symbol

btc_cny: 比特币 ltc_cny: 莱特币 eth_cny: 以太坊

order_id

订单ID

ok_sub_spotcny_trades  New 交易数据

示例

# Response
[
    {
        "channel": "ok_sub_spotcny_trades",
        "data": {
            "averagePrice": "0",
            "completedTradeAmount": "0",
            "createdDate": 1422258604000,
            "id": 268013884,
            "orderId": 268013884,
            "sigTradeAmount": "0",
            "sigTradePrice": "0",
            "status": -1,
            "symbol": "btc_cny",
            "tradeAmount": "1.105",
            "tradePrice": "0",
            "tradeType": "buy",
            "tradeUnitPrice": "1853.74",
            "unTrade": "0"
        }
    }
]

返回值说明

createdDate(string):创建日期
orderId(long):订单id
tradeType(string):交易类型(buy:买入;sell:卖出;buy_market:按市价买入;sell_market:按市价卖出)
sigTradeAmount(string):单笔成交数量
sigTradePrice(string):单笔成交价格
tradeAmount(string):委托数量(市价卖代表要卖总数量;限价单代表委托数量)
tradeUnitPrice(string):委托价格(市价买单代表购买总金额; 限价单代表委托价格)
symbol(string):btc_cny:比特币;ltc_cny:莱特币; eth_cny:以太坊
completedTradeAmount(string):已完成成交量
tradePrice(string):成交金额
averagePrice(string):平均成交价
unTrade(string):当按市场价买币时表示剩余金额,其他情况表示此笔交易剩余买/卖币的数量
status(int):-1已撤销,0等待成交,1部分成交,2完全成交,4撤单处理中

说明

登录后无需订阅,兼容旧的订阅方式,旧的订阅方式相当于登录操作。
Response:
[{"data":{"result":"true"},"channel":"login"}]
				
ok_sub_spotcny_userinfo  New 账户信息

示例

# Response
[{
    "channel": "ok_sub_spotcny_userinfo",
    "data": {
        "info": {
            "free": {
                "btc": 0.0001,
                "usd": 2.2687485,
                "ltc": 1.479023,
                "eth": 1.479022
            },
            "freezed": {
                "btc": 0,
                "usd": 0.000045,
                "ltc": 0,
                "eth": 0
            }
        }
    }
}]

返回值说明

lend:账户放款信息(只有在账户有放款信息时才会返回)
borrow:账户借款信息(只有在账户有借款信息时才会返回)
free:账户余额
freezed:账户冻结余额

说明

登录后无需订阅,兼容旧的订阅方式,旧的订阅方式相当于登录操作。
Response:
[{"data":{"result":"true"},"channel":"login"}]
				
提示

请先登录

客服400-888-6636
在线咨询 在线咨询
在线留言 发起提问
聊天室
OKCoin聊天室
请遵守聊天室规则!详情>>
客服400-888-6636
聊天室规则 X