Deribit.com WebSocket NodeJS generic library
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()
ws.action('positions').then(console.log)
ws.action('buy', {
instrument: 'BTC-28DEC18-15000-C',
quantity: 1,
type: 'market',
label: '1123123',
}).then(console.log)
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)