How to use the bfx-api-node-models.Order function in bfx-api-node-models

To help you get started, we’ve selected a few bfx-api-node-models examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitfinexcom / bitfinex-api-node / examples / rest2 / submit_order.js View on Github external
'use strict'

process.env.DEBUG = 'bfx:examples:*'

const debug = require('debug')('bfx:examples:submit_order')
const bfx = require('../bfx')
const { Order } = require('bfx-api-node-models')
const rest = bfx.rest(2)

debug('Submitting new order...')

// Build new order
const o = new Order({
  cid: Date.now(),
  symbol: 'tBTCUSD',
  price: 18000,
  amount: -0.02,
  type: Order.type.LIMIT,
  lev: 10
}, rest)

o.submit().then(() => {
  debug(
    'got submit confirmation for order %d [%d] [tif: %d]',
    o.cid, o.id, o.mtsTIF
  )
})
  .catch((err) => console.log(err))
github bitfinexcom / bitfinex-api-node / examples / ws2 / atomic_order_update.js View on Github external
ws.onOrderBook({ symbol: SYMBOL }, (ob) => {
  const topBidL = ob.topBidLevel()

  if (topBidL === null || orderSent) {
    return
  }

  debug('taking out price level: %j', topBidL)

  const o = new Order({
    symbol: SYMBOL,
    type: Order.type.EXCHANGE_LIMIT,
    price: topBidL[0],
    amount: topBidL[2] * -1.1 // sell through top bid
  }, ws)

  o.registerListeners()
  o.submit().then(() => debug('order submitted'))
  o.once('update', (o) => {
    debug('got order update: %s', o.status)

    if (o.isPartiallyFilled()) {
      debug('order is partially filled, amount %f', o.amount)
      debug('increasing amount w/ delta %f', o.amount * 2)

      o.update({ delta: `${o.amount * 2}` }).then(() => {
github bitfinexcom / bitfinex-api-node / lib / transports / ws2.js View on Github external
submitOrder (order) {
    if (!this._isAuthenticated) {
      return Promise.reject(new Error('not authenticated'))
    }

    const packet = Array.isArray(order)
      ? order
      : order instanceof Order
        ? order.toNewOrderPacket()
        : new Order(order).toNewOrderPacket()

    if (this._affCode) {
      if (!packet.meta) {
        packet.meta = {}
      }

      packet.meta.aff_code = packet.meta.aff_code || this._affCode // eslint-disable-line
    }

    this._sendOrderPacket([0, 'on', null, packet])

    return this._getEventPromise(`order-new-${packet.cid}`)
  }
github bitfinexcom / bitfinex-api-node / test / lib / transports / ws2-integration.js View on Github external
wsSingle.once('auth', () => {
      const o = new Order({
        id: Date.now(),
        type: 'EXCHANGE LIMIT',
        price: 100,
        amount: 1,
        symbol: 'tBTCUSD'
      }, wsSingle)

      wsSingle._ws.send = (msgJSON) => {
        const msg = JSON.parse(msgJSON)

        assert.strictEqual(msg[0], 0)
        assert.strictEqual(msg[1], 'ou')
        assert(msg[3])
        assert.strictEqual(msg[3].id, o.id)
        assert.strictEqual(+msg[3].delta, 1)
        assert.strictEqual(+msg[3].price, 200)
github bitfinexcom / bitfinex-api-node / test / lib / transports / ws2-integration.js View on Github external
wsMulti.once('auth', () => {
      const oA = new Order({
        gid: null,
        cid: Date.now(),
        type: 'EXCHANGE LIMIT',
        price: 100,
        amount: 1,
        symbol: 'tBTCUSD'
      })

      const oB = new Order({
        gid: null,
        cid: Date.now(),
        type: 'EXCHANGE LIMIT',
        price: 10,
        amount: 1,
        symbol: 'tETHUSD'
      })
github bitfinexcom / bitfinex-api-node / examples / ws2 / oc_multi.js View on Github external
ws.once('auth', () => {
  debug('authenticated')

  const oA = new Order({
    symbol: 'tBTCUSD',
    price: 200,
    amount: 1,
    type: 'EXCHANGE LIMIT'
  }, ws)

  const oB = new Order({
    symbol: 'tETHUSD',
    price: 50,
    amount: 1,
    type: 'EXCHANGE LIMIT'
  }, ws)

  oA.submit().then(() => {
    debug('created order A')
    return oB.submit()
github bitfinexcom / bitfinex-api-node / examples / ws2 / ox_multi.js View on Github external
const oA = new Order({
    symbol: 'tBTCUSD',
    price: 200,
    amount: 1,
    type: 'EXCHANGE LIMIT'
  }, ws)

  const oB = new Order({
    symbol: 'tETHUSD',
    price: 50,
    amount: 1,
    type: 'EXCHANGE LIMIT'
  }, ws)

  const oC = new Order({
    symbol: 'tETHBTC',
    price: 1,
    amount: 1,
    type: 'EXCHANGE LIMIT'
  }, ws)

  oA.submit().then(() => {
    debug('created order A')
    return oB.submit()
  }).then(() => {
    debug('created order B')
    return oC.submit()
  }).then(() => {
    debug('created order C')

    ws.submitOrderMultiOp([
github bitfinexcom / bitfinex-api-node / examples / ws2 / ox_multi.js View on Github external
ws.once('auth', () => {
  debug('authenticated')

  const oA = new Order({
    symbol: 'tBTCUSD',
    price: 200,
    amount: 1,
    type: 'EXCHANGE LIMIT'
  }, ws)

  const oB = new Order({
    symbol: 'tETHUSD',
    price: 50,
    amount: 1,
    type: 'EXCHANGE LIMIT'
  }, ws)

  const oC = new Order({
    symbol: 'tETHBTC',
    price: 1,
    amount: 1,
    type: 'EXCHANGE LIMIT'
  }, ws)

  oA.submit().then(() => {
    debug('created order A')
    return oB.submit()