# OCOCO

### Members

#### (static) generateInitialOrder

Source:
  - ococo/util/generate_initial_order.js, line 6

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

#### (static) generateOCOOrder

Source:
  - ococo/util/generate_oco_order.js, line 6

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

### Methods

#### (static) genOrderLabel(state) → {string}

Source:
  - ococo/meta/gen_order_label.js, line 13

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:
  - ococo/meta/gen_preview.js, line 12

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:
  - ococo/meta/get_ui_def.js, line 9

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:
  - ococo/meta/init_state.js, line 12

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:
  - ococo/meta/declare_events.js, line 13

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:
  - ococo/events/life_start.js, line 13
See:
  - module:OCOCO.onSelfSubmitInitialOrder

Submits the initial order as configured within the execution parameters

##### Parameters:

Name | Type | Description
--- | --- | ---
`instance` | AOInstance | AO instance

##### Listens to Events:

- AOHost~event:lifeStart

##### Returns:

p - resolves on completion

Type
  Promise

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

Source:
  - ococo/events/life_stop.js, line 12

Stub to conform to the algo order schema.

##### Parameters:

Name | Type | Description
--- | --- | ---
`instance` | AOInstance | AO instance

##### Listens to Events:

- AOHost~event:lifeStop

##### Returns:

p - resolves on completion

Type
  Promise

#### (async, static) onOrdersOrderCancel(instance, order)

Source:
  - ococo/events/orders_order_cancel.js, line 13

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:

- AOHost~event:ordersOrderCancel

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

Source:
  - ococo/events/orders_order_fill.js, line 18

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:

- AOHost~event:ordersOrderCancel

##### Returns:

p - resolves on completion

Type
  Promise

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

Source:
  - ococo/events/self_submit_initial_order.js, line 18
See:
  - module:OCOCO.generateInitialOrder

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:

- module:OCOCO~event:selfSubmitInitialOrder

##### Returns:

p - resolves on completion

Type
  Promise

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

Source:
  - ococo/events/self_submit_oco_order.js, line 18
See:
  - module:OCOCO.generateOCOOrder

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:

- module:OCOCO~event:selfSubmitOCOOrder

##### Returns:

p - resolves on completion

Type
  Promise

#### (static) processParams(data) → {object}

Source:
  - ococo/meta/process_params.js, line 15

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:
  - ococo/meta/serialize.js, line 14

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:
  - ococo/meta/unserialize.js, line 12

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:
  - ococo/meta/validate_params.js, line 30

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:
  - ococo/meta/declare_events.js, line 17

Triggers the creation of the initial atomic order, as configured

##### Listeners of This Event:

- module:OCOCO.onSelfSubmitInitialOrder

#### selfSubmitOCOOrder

Source:
  - ococo/meta/declare_events.js, line 24

Triggers the creation of the OCO atomic order, as configured

##### Listeners of This Event:

- module:OCOCO.onSelfSubmitOCOOrder