Skip to content

Latest commit

 

History

History
81 lines (59 loc) · 1.21 KB

README.md

File metadata and controls

81 lines (59 loc) · 1.21 KB

deribit-ws-js

Deribit.com WebSocket browser generic library

Install

yarn add deribit-ws-js

Constructor

import Deribit from 'deribit-ws-js'
const ws = new Deribit({
  key: 'deribit_key',
  secret: 'secret',
  testnet: false,
  message: msg => console.log(msg),

  // 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)