Order Executors
Order Executors are participants that earn a fee by executing executable orders. OrderExecutorTool is the relevant SDK component.
OrderExecutorTool ⇐ WriteAccessHandler
WriteAccessHandler
Functions to execute existing conditional orders from the limit order book. This class requires a private key and executes smart-contract interactions that require gas-payments.
Kind: global class
Extends: WriteAccessHandler
OrderExecutorTool ⇐
WriteAccessHandler
new OrderExecutorTool(config, signer)
.executeOrder(symbol, orderId, executorAddr, nonce, [submission]) ⇒
.executeOrders(symbol, orderIds, executorAddr, nonce, [submission]) ⇒
.getAllOpenOrders(symbol) ⇒
.numberOfOpenOrders(symbol) ⇒
number
.getOrderById(symbol, digest) ⇒
.pollLimitOrders(symbol, numElements, [startAfter]) ⇒
.isTradeable(order, indexPrices) ⇒
.isTradeableBatch(orders, indexPrice) ⇒
.smartContractOrderToOrder(scOrder) ⇒
.getTransactionCount(blockTag) ⇒
new OrderExecutorTool(config, signer)
Constructor.
Param | Type | Description |
---|---|---|
config |
| Configuration object, see PerpetualDataHandler.readSDKConfig. |
signer |
| Private key or ethers Signer of the account |
Example
orderExecutorTool.executeOrder(symbol, orderId, executorAddr, nonce, [submission]) ⇒
Executes an order by symbol and ID. This action interacts with the blockchain and incurs gas costs.
Kind: instance method of OrderExecutorTool
Returns:
Transaction object.
Param | Type | Description |
---|---|---|
symbol |
| Symbol of the form ETH-USD-MATIC. |
orderId |
| ID of the order to be executed. |
executorAddr |
| optional address of the wallet to be credited for executing the order, if different from the one submitting this transaction. |
nonce |
| optional nonce |
[submission] |
| optional signed prices obtained via PriceFeeds::fetchLatestFeedPriceInfoForPerpetual |
Example
orderExecutorTool.executeOrders(symbol, orderIds, executorAddr, nonce, [submission]) ⇒
Executes a list of orders of the symbol. This action interacts with the blockchain and incurs gas costs.
Kind: instance method of OrderExecutorTool
Returns:
Transaction object.
Param | Type | Description |
---|---|---|
symbol |
| Symbol of the form ETH-USD-MATIC. |
orderIds |
| IDs of the orders to be executed. |
executorAddr |
| optional address of the wallet to be credited for executing the order, if different from the one submitting this transaction. |
nonce |
| optional nonce |
[submission] |
| optional signed prices obtained via PriceFeeds::fetchLatestFeedPriceInfoForPerpetual |
Example
orderExecutorTool.getAllOpenOrders(symbol) ⇒
All the orders in the order book for a given symbol that are currently open.
Kind: instance method of OrderExecutorTool
Returns:
Array with all open orders and their IDs.
Param | Type | Description |
---|---|---|
symbol |
| Symbol of the form ETH-USD-MATIC. |
Example
orderExecutorTool.numberOfOpenOrders(symbol) ⇒ number
number
Total number of limit orders for this symbol, excluding those that have been cancelled/removed.
Kind: instance method of OrderExecutorTool
Returns: number
-
Number of open orders.
Param | Type | Description |
---|---|---|
symbol |
| Symbol of the form ETH-USD-MATIC. |
Example
orderExecutorTool.getOrderById(symbol, digest) ⇒
Get order from the digest (=id)
Kind: instance method of OrderExecutorTool
Returns:
order or undefined
Param | Description |
---|---|
symbol | symbol of order book, e.g. ETH-USD-MATIC |
digest | digest of the order (=order ID) |
Example
orderExecutorTool.pollLimitOrders(symbol, numElements, [startAfter]) ⇒
Get a list of active conditional orders in the order book. This a read-only action and does not incur in gas costs.
Kind: instance method of OrderExecutorTool
Returns:
Array of orders and corresponding order IDs
Param | Type | Description |
---|---|---|
symbol |
| Symbol of the form ETH-USD-MATIC. |
numElements |
| Maximum number of orders to poll. |
[startAfter] |
| Optional order ID from where to start polling. Defaults to the first order. |
Example
orderExecutorTool.isTradeable(order, indexPrices) ⇒
Check if a conditional order can be executed
Kind: instance method of OrderExecutorTool
Returns:
true if order can be executed for the current state of the perpetuals
Param | Description |
---|---|
order | order structure |
indexPrices | pair of index prices S2 and S3. S3 set to zero if not required. If undefined the function will fetch the latest prices from the REST API |
Example
orderExecutorTool.isTradeableBatch(orders, indexPrice) ⇒
Check for a batch of orders on the same perpetual whether they can be traded
Kind: instance method of OrderExecutorTool
Returns:
array of tradeable boolean
Param | Description |
---|---|
orders | orders belonging to 1 perpetual |
indexPrice | S2,S3-index prices for the given perpetual. Will fetch prices from REST API if not defined. |
Example
orderExecutorTool.smartContractOrderToOrder(scOrder) ⇒
Wrapper of static method to use after mappings have been loaded into memory.
Kind: instance method of OrderExecutorTool
Returns:
A user-friendly order struct.
Param | Description |
---|---|
scOrder | Perpetual order as received in the proxy events. |
orderExecutorTool.getTransactionCount(blockTag) ⇒
Gets the current transaction count for the connected signer
Kind: instance method of OrderExecutorTool
Returns:
The nonce for the next transaction
Param |
---|
blockTag |