deribit-ws-nodejs
v1.0.3
Published
Deribit.com WebSocket NodeJS generic library
Downloads
11
Readme
deribit-ws-nodejs
Deribit.com WebSocket NodeJS generic library
Install
yarn add deribit-ws-nodejs
Constructor
import Deribit from 'deribit-ws-nodejs'
const ws = new Deribit({
key: 'deribit_key',
secret: 'secret',
testnet: false,
message: msg => console.log(msg),
error: err => console.error(err),
// see documentation for possible events
trade: trade => console.log(msg),
})
Wait for connection
await ws.connected
// or ws.connected.then(() => console.log('Ready') )
Disconnect when done
ws.disconnect()
Actions
ws.action('positions').then(console.log)
ws.action('buy', {
instrument: 'BTC-28DEC18-15000-C',
quantity: 1,
type: 'market',
label: '1123123',
}).then(console.log)
Event hooks
Filters and events (see https://www.deribit.com/main#/pages/docs/api -> WebSocket API -> Subscribe)
let filters = ['all', 'futures', 'options', 'index', 'any_instrument_name']
let events = ['order_book', 'trade', 'user_order', 'my_trade']
Hooks
ws.hook('my_trade', trade => console.log(trade))
With filter
ws.hook('order_book', 'BTC-28SEP18', cb)
Array as filter
ws.hook('trade', ['BTC-28SEP18','BTC-28DEC18'], cb)