AOHost

AOHost

The AOHost class provides a wrapper around the algo order system, and manages lifetime events/order execution. Internally it hosts a Manager instance from bfx-api-node-core for communication with the Bitfinex API, and listens for websocket stream events in order to update order state/trigger algo order events.

Execution is handled by an event system, with events being triggered by Bitfinex API websocket stream payloads, and the algo orders themselves.

To start/stop algo orders, gid = startAO(id, args) and stopAO(gid) methods are provided, with the generated group ID (gid) being the same as that used for all atomic orders created by the individual algo orders.

Constructor

new AOHost(argsopt)

Source:
Parameters:
Name Type Attributes Description
args object <optional>

arguments

Properties
Name Type Attributes Description
db object <optional>

optional

wsURL string <optional>

wss://api.bitfinex.com/ws/2

restURL string <optional>

https://api.bitfinex.com

agent object <optional>

optional proxy agent

aos Array.<object> <optional>

algo orders to manage

dms number <optional>

dead man switch, active 4 (default)

Members

(static) TEARDOWN_GRACE_PERIOD_MS :number

Source:
Default Value:
  • 10000

How long orders are allowed to settle for before teardown in ms.

Type:
  • number

Methods

aosRunning() → {boolean}

Source:
Returns:

aosRunning - true if any algo order is currently running

Type
boolean

close() → {Promise}

Source:

Close the exchange adapter connection.

Returns:

p - resolves on connection close

Type
Promise

connect()

Source:

Opens a new socket connection on the internal adapter

getAdapter() → {object}

Source:

Get configured exchange adapter

Returns:

adapter

Type
object

getAO(id) → {object}

Source:

Returns the algo order definition identified by the provided ID

Parameters:
Name Type Description
id string

i.e. bfx-iceberg

Returns:

aoDef

Type
object

getAOInstance(gid) → {object}

Source:

Returns the active AO instance state identified by the provided GID

Parameters:
Name Type Description
gid string

algo order group ID

Returns:

state - algo order state

Type
object

getAOInstances() → {Array.<object>}

Source:

Returns an array of all running algo order instances

Returns:

aoInstances

Type
Array.<object>

getAOs() → {Array}

Source:

Fetch configured algorithmic orders

Returns:

aos

Type
Array

(async) loadAllAOs()

Source:

Loads and starts all saved previously active algo orders

reconnect()

Source:

Disconnect & reconnect the exchange adapter

(async) reloadAllAOs()

Source:

Implodes all current AO instances, but does NOT stop them. Afterwards, all known AOs are loaded and started again.

(async) startAO(id, args, gidCBopt) → {string}

Source:

Creates and starts a new algo order instance, based on the AO def identified by the supplied ID

Parameters:
Name Type Attributes Description
id string

algo order definition ID, i.e. bfx-iceberg

args object

algo order arguments/parameters

gidCB function <optional>

callback to acquire GID prior to ao:start

Returns:

gid - instance GID

Type
string

(async) stopAO(gid)

Source:

Stops an algo order instance by GID

Parameters:
Name Type Description
gid string

algo order instance GID

Events

dataBook

Source:

Triggered when an order book update is received.

Parameters:
Name Type Description
update Array.<Array>

incoming snapshot or price level

meta EventMetaInformation

source channel information

dataCandles

Source:

Triggered when a candle snapshot or individual candle is received.

Parameters:
Name Type Description
update Array.<Array>

incoming snapshot or single candle

meta EventMetaInformation

source channel information

dataManagedBook

Source:

Triggered when an order book update is received, and an internally managed order book instance is updated. The entire order book is passed to the event listeners.

Parameters:
Name Type Description
book object

full order boook

meta EventMetaInformation

source channel information

Listeners of This Event:

dataManagedCandles

Source:

Triggered when a candle update is received, and an internally managed candle dataset is updated. The entire dataset is passed to the event listeners.

Parameters:
Name Type Description
candles Array.<object>

full dataset

meta EventMetaInformation

source channel information

Listeners of This Event:

dataNotification

Source:

Triggered when a notification is received.

Parameters:
Name Type Description
notification Array.<Array>

incoming notification data

meta EventMetaInformation

source channel information

dataTicker

Source:

Triggered when a ticker is received.

Parameters:
Name Type Description
ticker Array.<Array>

incoming ticker data

meta EventMetaInformation

source channel information

dataTrades

Source:

Triggered when a trade snapshot or single trade is received

Parameters:
Name Type Description
update Array.<Array>

incoming snapshot or single trade

meta EventMetaInformation

source channel information

Listeners of This Event:

errorsInsufficientBalance

Source:

Triggered when an order fails due to have insufficient balance

Parameters:
Name Type Description
order object

the order that failed

notification object

the incoming notification

Listeners of This Event:

errorsMinimumSize

Source:

Triggered when an order fails due to being below the minimum size for that market.

Parameters:
Name Type Description
order object

the order that failed

notification object

the incoming notification

Listeners of This Event:

lifeStart

Source:

Triggered when an algorithmic order begins execution.

Listeners of This Event:

lifeStop

Source:

Triggered when an algorithmic order ends execution.

Listeners of This Event:

ordersOrderCancel

Source:

Triggered on atomic order cancellation

Parameters:
Name Type Description
order object

the order that was cancelled

Listeners of This Event:

ordersOrderError

Source:

Triggered on a generic order error

Parameters:
Name Type Description
order object

the order that caused the error

Listeners of This Event:

ordersOrderFill

Source:

Triggered on atomic order fill

Parameters:
Name Type Description
order object

the order that was filled

Listeners of This Event: