Spot Price API

Receive the latest OKCoin Spot market data
Resource Description
ok_sub_spot_X_ticker  New Subscribe Price Ticker

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

Example

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

Returned Value Description

buy(double): best bid
high(double): highest price
last(double): latest price
low(double): lowest price
sell(double): best ask
timestamp(long): timestamp
vol(double: volume(the most recent 24 hours)
ok_sub_spot_X_depth  New Subscribe Market Depth(Increment)

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

Example

# Request
{'event':'addChannel','channel':'ok_sub_spot_btc_usd_depth'}
# Response
[{
    "channel":"ok_sub_spot_btc_usd_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
    }
}]

Returned Value Description

Incremental data return (Return full data for the first query)
Delete (BTC/LTC amount is 0)
Edit (Same price, different amount)
Add (Price inexist)
bids([string, string]):bids depth
asks([string, string]):asks depth
timestamp(long): server timestamp
ok_sub_spot_X_depth_Y  New Subscribe Market Depth(Full)

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

Example

# Request
{'event':'addChannel','channel':'ok_sub_spot_btc_usd_depth_20'}
# Response
[{
    "channel":"ok_sub_spot_btc_usd_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
    }
}]

Returned Value Description

bids[string, string]: bids depth
asks[string, string]: asks depth
timestamp(long): server timestamp
ok_sub_spot_X_deals  New Subscribe Trade Records

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

Example

# Response
[{
    "channel":"ok_sub_spot_btc_usd_deals",
    "data":[["1001","2463.86","0.052","16:34:07","ask"]]
}]

Returned Value Description

[tid, price, amount, time, type]
[string, string, string, string, string]
ok_sub_spot_X_kline_Y  New Subscribe Candlestick Chart Data

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

Example

# Request
{'event':'addChannel','channel':'ok_sub_spot_btc_usd_kline_1min'}
# Response
[{
    "channel":"ok_sub_spot_btc_usd_kline_1min",
    "data":[
        [1411720800000,2466.98,2467.98,2466.21,2467.97,101.3],
        [1411720860000,2467.96,2467.98,2467.94,2467.98,5.89]
    ]
}]

Returned Value Description

[time, open price, highest price, lowest price, close price, volume]
[string, string, string, string, string, string]

Spot Trade API

Easily place spot orders on OKCoin
Resource Description
login  New Login(Personal Information)

Example

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

Request Parameters

Parameter Name Description

api_key

apiKey of the user

sign

signature of request parameters

Description

The data will return when it changed. These types need not be subscribed. eg:ok_sub_spot_X_order,ok_sub_spot_X_balance
ok_spot_order  New Place Orders

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

Example

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

Returned Value Description

order_id(long):order id
result(boolean):execute result

Request Parameters

Parameter Name Description

api_key

apiKey of the user

sign

signature of request parameters

symbol

btc_usd, ltc_usd, eth_usd, etc_usd, bcc_usd

type

order Type: limit order (buy/sell) market order (buy_market/sell_market)

price

order price [limit order buy (required): price between 0~1,000,000 | market order buy (required): BTC:price bigger than (0.01 * best ask price) / LTC :price bigger than (0.1 * best ask price) / ETH :price bigger than (0.01 * best ask price)]

amount

order quantity:[limit order sell (required): BTC quantity not less than 0.01 / LTC quantity not less than 0.1 / ETH quantity not less than 0.01| market order sell (required): BTC quantity not less than 0.01 / LTC quantity not less than 0.1 / ETH quantity not less than 0.01]

ok_spot_cancel_order  New Cancel Order

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

Example

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

Returned Value Description

order_id(long):order id
result(boolean):execute result

Request Parameters

Parameter Name Description

api_key

apiKey of the user

sign

signature of request parameters

symbol

btc_usd, ltc_usd, eth_usd, etc_usd, bcc_usd

order_id

order Id

ok_spot_userinfo  New Get User Account Info

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

Example

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

Returned Value Description

asset: account funds, including net fund and total fund
borrow: account borrowing information (only returned when this field is not null)
free: available fund
freezed: frozen fund
union_fund: fund management information (only returned when this field is not null)

Request Parameters

Parameter Name Description

api_key

apiKey of the user

sign

signature of request parameters

ok_spot_orderinfo  New Get Order Info

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

Example

# Request
{
    'event':'addChannel',
    'channel':'ok_spot_orderinfo',
    'parameters':{
        'api_key':'XXXX',
        'sign':'XXXX',
        'symbol':'btc_usd',
        'order_id':'20914907'
    }
}
# Response
[{
    "channel": "ok_spot_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": "btc_usd",
            "type": "sell_market"
        }],
        "result": true
    }
}]

Returned Value Description

amount(double): order quantity
create_date(double): order time
avg_price(double): average transaction price
deal_amount(double): filled quantity
order_id(long): order ID
orders_id(long): order ID (Deprecated)
price(double): order price
status(int): -1 = cancelled, 0 = unfilled, 1 = partially filled, 2 = fully filled, 4 = cancel request in process,5 = cancel request in process
symbol(string): coin type
type(string): buy_market = market buy order, sell_market = market sell order

Request Parameters

Parameter Name Description

api_key

apiKey of the user

sign

signature of request parameters

symbol

btc_usd, ltc_usd, eth_usd, etc_usd, bcc_usd

order_id

order ID

ok_sub_spot_X_order  New Trade Record

Example

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

Returned Value Description

createdDate(string): created date
orderId(long): order ID
tradeType(string): trade type (buy: buy;sell: sell;buy_market: buy at market price;sell_market: sell at market price)
sigTradeAmount(string):quantity in a single transaction
sigTradePrice(string):rate in a single transaction
tradeAmount(string):for market sell orders: total sell quantity, for limit orders: order quantity
tradeUnitPrice(string):for market buy orders: total buy amount, for limit orders: order rate
symbol(string):btc_usd, ltc_usd, eth_usd, etc_usd, bcc_usd
completedTradeAmount(string): filled 'tradeAmount'
tradePrice(string): filled amount
averagePrice(string): average transaction price
unTrade(string): unfilled amount in usd for market order, unfilled coin quantity for limit order
status(int): -1: cancelled, 0: pending, 1: partially filled, 2: fully filled, 4: cancel request in process

Description

There is no need to subscribe to the login, compatible with the old subscription, the old subscription is equivalent to the login operation.
Response:
[
    {
        "binary": 0,
        "channel": "login",
        "data": {
            "result": true
        }
    }
]
ok_sub_spot_X_balance  New User Account Info

Example

# Response
[{
    "channel": "ok_sub_spot_X_balance",
    "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
            }
        }
    }
}]

Returned Value Description

lend: account lending information (only returned when this field is not null)
borrow: account borrowing information (only returned when this field is not null)
free: available fund
freezed: frozen fund

Description

There is no need to subscribe to the login, compatible with the old subscription, the old subscription is equivalent to the login operation.
Response:
[
    {
        "binary": 0,
        "channel": "login",
        "data": {
            "result": true
        }
    }
]
提示

请先登录

客服+852 5808 5768
在线咨询 在线咨询
在线留言 发起提问
聊天室
OKCoin聊天室
请遵守聊天室规则!详情>>
客服+852 5808 5768
聊天室规则 X