Members
(static) generateOrder
- Source:
Generates the next slice order for the provided instance, taking into account the remaining amount that needs to be filled.
(static) getOBPrice
- Source:
Extracts the target price from the last known order book. Null if unavailable
(static) getTradePrice
- Source:
Extracts the target price from the last known trade. Null if unavailable
(static) hasOBTarget
- Source:
Reports of the provided execution parameters have an order book price target.
(static) hasTradeTarget
- Source:
Reports of the provided execution parameters have a trade price target.
(static) isTargetMet
- Source:
Reports if the price target for the provided execution parameters is met for the specified price.
Methods
(async, static) declareChannels(instance, host)
- Source:
Declares necessary data channels for price matching. The instance may
require a book
or trades
channel depending on the execution parameters.
Part of the meta
handler section.
Parameters:
Name | Type | Description |
---|---|---|
instance |
object | AO instance state |
host |
object | algo host instance for declaring channel requirements |
(static) declareEvents(instance, host)
- Source:
Declares internal self:interval_tick
event handler to the host for event
routing.
Part of the meta
handler section.
Parameters:
Name | Type | Description |
---|---|---|
instance |
object | AO instance state |
host |
object | algo host instance for event mapping |
(static) genOrderLabel(state) → {string}
- Source:
Generates a label for a TWAP instance for rendering in an UI.
Part of the meta
handler section.
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
state |
object | source instance state Properties
|
Returns:
label
- Type
- string
(static) genPreview(args) → {Array.<object>}
- Source:
Generates an array of preview orders which show what could be expected if an instance of TWAP 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:
Returns the UI layout definition for TWAP, with a field for each parameter.
Part of the meta
handler section.
Returns:
uiDef
- Type
- AOUIDefinition
(static) initState(args) → {object}
- Source:
Creates an initial state object for a TWAP 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) onDataManagedBook(instance, book, meta)
- Source:
- See:
Saves the book on the instance state if it is needed for price target matching, and it is for the configured symbol.
Mapped to the data:managedBook
event.
Parameters:
Name | Type | Description |
---|---|---|
instance |
AOInstance | AO instance state |
book |
object | order book model |
meta |
EventMetaInformation | source channel information |
Listens to Events:
(async, static) onDataTrades(instance, trades, meta) → {Promise}
- Source:
Saves the last trade on the instance state to be used in price matching.
Mapped to the data:trades
event.
Parameters:
Name | Type | Description |
---|---|---|
instance |
AOInstance | AO instance |
trades |
Array.<object> | array of incoming trades |
meta |
EventMetaInformation | source channel information |
Listens to Events:
Returns:
p - resolves on completion
- Type
- Promise
(async, static) onLifeStart(instance) → {Promise}
- Source:
Sets up the self:interval_tick
interval and saves it on the state.
Parameters:
Name | Type | Description |
---|---|---|
instance |
AOInstance | AO instance |
Listens to Events:
Returns:
p - resolves on completion
- Type
- Promise
(async, static) onLifeStop(instance) → {Promise}
- Source:
Clears the tick interval prior to teardown
Parameters:
Name | Type | Description |
---|---|---|
instance |
object | AO instance |
Listens to Events:
Returns:
p - resolves on completion
- Type
- Promise
(async, static) onOrdersOrderCancel(instance, order) → {Promise}
Triggered when an atomic order cancellation is detected; cancels any open
orders and emits the exec:stop
event to trigger teardown.
Mapped to the orders:order_cancel
event.
Parameters:
Name | Type | Description |
---|---|---|
instance |
object | AO instance |
order |
object | the order that was cancelled |
Listens to Events:
Returns:
p - resolves on completion
- Type
- Promise
(async, static) onOrdersOrderFill(instance, order) → {Promise}
- Source:
Triggered when an atomic order fills. Updates the remaining amount on the
instance state, and emits the exec:stop
if the instance is now fully
filled.
Parameters:
Name | Type | Description |
---|---|---|
instance |
AOInstance | AO instance |
order |
object | the order that filled |
Listens to Events:
Returns:
p - resolves on completion
- Type
- Promise
(async, static) onSelfIntervalTick(instance) → {Promise}
- Source:
Submits the next slice order if the price condition/target is met.
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 TWAP 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:TWAP.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 TWAP order.
Part of the meta
handler section.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
object | incoming parameters Properties
|
Returns:
error - null if parameters are valid, otherwise a description of which parameter is invalid.
- Type
- string
Events
selfIntervalTick
- Source:
Triggers price target comparison and a potential atomic order submit