Silas-Yang / OKEx-Future-Trader

WebSocket Client For OKEx Contract (Future)
1 stars 2 forks source link

ok_sub_futureusd - example #2

Open oranmis opened 6 years ago

oranmis commented 6 years ago

Hi :) Can you please add an example how to execute one of the ok_sub_futureusd channels?

Also, do you have an english version maybe?

Thanks!

Silas-Yang commented 6 years ago

Sorry for this late response. You can subscribe market data like this:

let okex = new OK.OKEx()

okex.sub({
    subType: OK.SubscriptionType.ticker,
    option: {
        coin: OK.CoinType.btc,
        contype: OK.ContractType.this_week, // this_week | next_week | quarter
    },
    id: 'test',
    handler: data => {
        console.log(data)
    }
})

Response:

{ binary: 0,
  channel: 'ok_sub_futureusd_btc_ticker_this_week',
  data:
   { high: '6587.65',
     limitLow: '6304.21',
     vol: '1570276',
     last: '6500.57',
     low: '6435',
     buy: '6500',
     hold_amount: '1167175',
     sell: '6500.68',
     contractId: 201806220000013,
     unitAmount: '100',
     limitHigh: '6694.26' } }

SubscriptionType can be one of them: { ticker, kline, depth, depth_z, trade, index, trades, // user's trade info userinfo, positions }

I will write a documentation for the details.

Thanks.