OCOCO

Order Creates OCO (or OCOCO) triggers an OCO order after an initial MARKET or LIMIT order fills.

Source:
Example
await host.startAO('bfx-ma_crossover', {
  symbol: 'tLEOUSD',
  orderType: 'LIMIT',
  orderPrice: 2,
  amount: 30,
  action: 'Sell',
  limitPrice: 1.7,
  stopPrice: 2.1,
  ocoAmount: 30,
  ocoAction: 'Buy',
  submitDelaySec: 0,
  cancelDelaySec: 0,
  margin: true
})
Parameters:
Name Type Description
symbol string

symbol to trade on

orderType string

initial order type, LIMIT or MARKET

orderPrice number

price for initial order if orderType is LIMIT

amount number

initial order amount

_margin boolean

if false, order type is prefixed with EXCHANGE

_futures boolean

if false, order type is prefixed with EXCHANGE

action string

initial order direction, Buy or Sell

limitPrice number

oco order limit price

stopPrice number

oco order stop price

ocoAmount number

oco order amount

ocoAction string

oco order direction, Buy or Sell

submitDelaySec number

submit delay in seconds

cancelDelaySec number

cancel delay in seconds

lev number

leverage for relevant markets

Members

(static) generateInitialOrder

Source:

Generates the initial atomic order as configured within the execution parameters.

(static) generateOCOOrder

Source:

Generates the OCO atomic order as configured within the execution parameters.

Methods

(static) genOrderLabel(state) → {string}

Source:

Generates a label for an OCOCO instance for rendering in an UI.

Part of the meta handler section.

Parameters:
Name Type Description
state object

source instance state

Properties
Name Type Description
args object

source instance execution parameters

Returns:

label

Type
string

(static) genPreview(args) → {Array.<object>}

Source:

Stub to conform to the algo order schema.

Part of the meta handler section.

Parameters:
Name Type Description
args object

instance arguments

Returns:

preview

Type
Array.<object>

(static) getUIDef() → {object}

Source:

Returns the UI layout definition for OCOCO, with a field for each parameter.

Part of the meta handler section.

Returns:

uiDef

Type
object

(static) initState(args) → {object}

Source:

Creates an initial state object for an OCOCO instance to begin executing with.

Part of the meta handler section.

Parameters:
Name Type Description
args object

instance execution parameters

Returns:

initialState

Type
object

(static) module.exports(instance, host)

Source:

Declares internal self:submit_initial_order and self:self_submit_oco_order event handlers to the host for event routing.

Part of the meta handler section.

Parameters:
Name Type Description
instance AOInstance

AO instance state

host object

algo host instance for event mapping

(async, static) onLifeStart(instance) → {Promise}

Source:
See:

Submits the initial order as configured within the execution parameters

Parameters:
Name Type Description
instance AOInstance

AO instance

Listens to Events:
Returns:

p - resolves on completion

Type
Promise

(async, static) onLifeStop(instance) → {Promise}

Source:

Stub to conform to the algo order schema.

Parameters:
Name Type Description
instance AOInstance

AO instance

Listens to Events:
Returns:

p - resolves on completion

Type
Promise

(async, static) onOrdersOrderCancel(instance, order)

Source:

Triggered on atomic order cancellation; cancels any open orders and triggers the 'exec:stop' event & teardown.

Parameters:
Name Type Description
instance AOInstance

AO instance state

order object

the order that was cancelled externally

Listens to Events:

(async, static) onOrdersOrderFill(instance, order) → {Promise}

Source:

Called on atomic order fill. If it was the initial order, the OCO order is submitted, otherwise the 'exec:stop' event is emitted to trigger teardown.

Parameters:
Name Type Description
instance AOInstance

AO instance

order object

the order that was filled

Listens to Events:
Returns:

p - resolves on completion

Type
Promise

(async, static) onSelfSubmitInitialOrder(instance) → {Promise}

Source:
See:

Generates and submits the initial atomic order as configured within the execution parameters.

Mapped to the 'self:submit_initial_order' event.

Parameters:
Name Type Description
instance AOInstance

AO instance

Listens to Events:
Returns:

p - resolves on completion

Type
Promise

(async, static) onSelfSubmitOCOOrder(instance) → {Promise}

Source:
See:

Generates and submits the OCO order as configured within the execution parameters.

Mapped to the 'self:submit_oco_order' event.

Parameters:
Name Type Description
instance AOInstance

AO instance

Listens to Events:
Returns:

p - resolves on completion

Type
Promise

(static) processParams(data) → {object}

Source:

Converts a raw parameters Object received from an UI into a parameters Object which can be used by an OCOCO instance for execution.

Part of the meta handler section.

Parameters:
Name Type Description
data object

raw parameters from an UI

Returns:

parameters - ready to be passed to a fresh instance

Type
object

(static) serialize(state) → {object}

Source:

Creates a POJO from an instance's state which can be stored as JSON in a database, and later loaded with the corresponding module:OCOCO~unserialize method.

Part of the meta handler section.

Parameters:
Name Type Description
state object

instance state to be serialized

Returns:

pojo - DB-ready plain JS object

Type
object

(static) unserialize(loadedState) → {object}

Source:

Converts a loaded POJO into a state object ready for live execution.

Part of the meta handler section.

Parameters:
Name Type Description
loadedState object

data from a DB

Returns:

instanceState - ready for execution

Type
object

(static) validateParams(args) → {string}

Source:

Verifies that a parameters Object is valid, and all parameters are within the configured boundaries for a valid OCOCO order.

Part of the meta handler section.

Parameters:
Name Type Description
args object

incoming parameters

Properties
Name Type Description
symbol string

symbol to trade on

orderType string

initial order type, LIMIT or MARKET

orderPrice number

price for initial order if orderType is LIMIT

amount number

initial order amount

action string

initial order direction, Buy or Sell

limitPrice number

oco order limit price

stopPrice number

oco order stop price

ocoAmount number

oco order amount

ocoAction string

oco order direction, Buy or Sell

submitDelaySec number

submit delay in seconds

cancelDelaySec number

cancel delay in seconds

Returns:

error - null if parameters are valid, otherwise a description of which parameter is invalid.

Type
string

Events

selfSubmitInitialOrder

Source:

Triggers the creation of the initial atomic order, as configured

Listeners of This Event:

selfSubmitOCOOrder

Source:

Triggers the creation of the OCO atomic order, as configured

Listeners of This Event: