# Iceberg

### Members

#### (static) generateOrders

Source:
  - iceberg/util/generate_orders.js, line 9
See:
  - module:Iceberg.onSelfSubmitOrders

Returns an order set for the provided Iceberg instance, including a slice order and the remaining amount as a hidden order if configured.

### Methods

#### (static) declareEvents(instance, host)

Source:
  - iceberg/meta/declare_events.js, line 13

Declares internal `self:submit_orders` event handler to the host for event routing.

Part of the `meta` handler section.

##### Parameters:

Name | Type | Description
--- | --- | ---
`instance` | AOInstance | AO instance state
`host` | AOHost | algo host instance for event mapping

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

Source:
  - iceberg/meta/gen_order_label.js, line 15

Generates a label for an Iceberg 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) genOrderLabel(state) → {string}

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

Generates a label for an MACrossver 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:
  - iceberg/meta/gen_preview.js, line 15

Generates an array of preview orders which show what could be expected if an instance of Iceberg was executed with the specified parameters.

Part of the `meta` handler section.

##### Parameters:

Name | Type | Description
--- | --- | ---
`args` | object | instance parameters

##### Returns:

previewOrders

Type
  Array.<object>

#### (static) getUIDef() → {AOUIDefinition}

Source:
  - iceberg/meta/get_ui_def.js, line 9

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

Part of the `meta` handler section.

##### Returns:

uiDef

Type
  AOUIDefinition

#### (static) initState(args) → {object}

Source:
  - iceberg/meta/init_state.js, line 13

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

Part of the `meta` handler section.

##### Parameters:

Name | Type | Description
--- | --- | ---
`args` | object | instance execution parameters

##### Returns:

initialState

Type
  object

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

Source:
  - iceberg/events/life_start.js, line 14
See:
  - module:Iceberg.onSelfSubmitOrders

##### Parameters:

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

##### Fires:

- module:Iceberg~event:selfSubmitOrders

##### Listens to Events:

- AOHost~event:lifeStart

##### Returns:

p - resolves on completion

Type
  Promise

#### (async, static) onLifeStop(instance)

Source:
  - iceberg/events/life_stop.js, line 11

Cancels any pending order submits prior to teardown

##### Parameters:

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

##### Listens to Events:

- AOHost~event:lifeStop

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

Source:
  - iceberg/events/orders_order_cancel.js, line 14

Called when an atomic order cancellation is detected. Cancels any open orders and emits the `'exec:stop'` event.

##### Parameters:

Name | Type | Description
--- | --- | ---
`instance` | AOInstance | AO instance
`order` | object | order that was cancelled

##### Listens to Events:

- AOHost~event:ordersOrderCancel

##### Returns:

p - resolves on completion

Type
  Promise

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

Source:
  - iceberg/events/orders_order_fill.js, line 19

Called when an order is filled. Cancels any remaining open orders (slice or excess), updates the remaining amount on the instance state, and submits the next order set.

##### Parameters:

Name | Type | Description
--- | --- | ---
`instance` | AOInstance | AO instance
`order` | object | order that filled

##### Listens to Events:

- AOHost~event:ordersOrderFill

##### Returns:

p - resolves on completion

Type
  Promise

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

Source:
  - iceberg/events/self_submit_orders.js, line 16
See:
  - module:Iceberg~generateOrders

Submits the next slice order, and remaining amount as a hidden order if configured.

##### Parameters:

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

##### Listens to Events:

- module:Iceberg~event:selfSubmitOrders

##### Returns:

p - resolves on completion

Type
  Promise

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

Source:
  - iceberg/meta/process_params.js, line 13

Converts a raw parameters Object received from an UI into a parameters Object which can be used by an Iceberg 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:
  - iceberg/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:Iceberg~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:
  - iceberg/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:
  - iceberg/meta/validate_params.js, line 25

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

Part of the `meta` handler section.

##### Parameters:

Name | Type | Description
--- | --- | ---
`args` | object | incoming parameters ###### Properties
Name | Type | Attributes | Description
--- | --- | --- | ---
`amount` | number |  | total order amount
`sliceAmount` | number |  | iceberg slice order amount
`sliceAmountPerc` | number | <optional> | optional, slice amount as % of total amount
`excessAsHidden` | boolean |  | whether to submit remainder as a hidden order
`orderType` | string |  | LIMIT or MARKET
`submitDelay` | number | <optional> | in ms, default 1500
`cancelDelay` | number | <optional> | in ms, default 5000

##### Returns:

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

Type
  string

### Events

#### event:selfSubmitOrders

Source:
  - iceberg/meta/declare_events.js, line 17

Triggers order submit for both the slice and remainder if configured.

##### Listeners of This Event:

- module:Iceberg.onSelfSubmitOrders