使用基于Rx.js
封装WebSocket的observable-socket连接OKEX,使用Promise封装交易与行情接口。
配置keys.conf.js
中的API Key后,例如:
const OK = require('./dist')
const apikeys = require('./keys.conf')
let okex = new OK.OKEx(apikeys.apiKey, apikeys.secret)
/* 登录 */
okex.login().then(console.log) // 服务器返回结果 [{"binary":0,"channel":"login","data":{"result":true}}]
/* 设置参数 */
okex.setParams({
symbol: 'btc_usd',
lever_rate: '20',
contract_type: 'this_week'
})
/* 开多 */
okex.openBuy({
price: '8570',
amount: '1'
}).then(res => {
console.log('============= openBuy ==============')
console.log(res)
console.log('====================================')
})
/** 收到服务器返回之后输出结果
============= openBuy ==============
[ { binary: 0,
channel: 'ok_futureusd_trade',
data: { result: true, order_id: 458956156910592 } } ]
====================================
*/