Order

Overview

Order is part of the backtest system of Nyxar. Although users do not interact directly with Order, it is worthwhile to clarify some properties of it and the role it plays behind the scene.

User’s trading algorithms place and query orders in the BackExchange through the API therein. BackExchange determines whether orders are filled based on the order type and the ticker price. Transaction are generated by the Slippage Model to determine how (amount and price) orders are filled.

API Reference

class OrderSide(Enum)

Enumeration of order side.

Buy
Sell
class OrderType(Enum)

Enumeration of order type.

Market

Market order. Market order will be filled as soon as it is accepted. Market order is also all-or-none order, meaning either the order is filled in full or an InsufficientFunds exception is raised.

Limit

Limit order. Limit order will only be filled when the ticker price is higher/lower than the limit price for sell/buy orders. Limit order doesn’t necessarily need to be filled in full. The filled amount at each time bar is determined the by Slippage Model.

Asset in the unfilled part of the order is not available for trading unless the order is cancelled. In order balance can be queried as used in :meth::BackExchange.fetch_balance.

StopLimit

Stop limit order. Stop limit order will become a limit order when the ticker price is lower/higher than the stop price for sell/buy orders. Note that whether to open a stop limit order is determined only by the ticker price. Slippage model is only effective in filling the order.

class OrderStatus(Enum)

Enumeration of order status.

Submitted

Orders submitted to the Order Queue of BackExchange.

Accepted

Orders accepted by the exchange but is not yet open. It is only applicable to stop limit orders.

Open

Open orders that are not filled yet. It is applicable to limit and stop limit orders.

Filled

Orders that are fully filled.

Cancelled

Orders that are cancelled before fully filled.

class Order(timestamp, order_type, side, quote_name, base_name, amount, price, stop_price)
timestamp

The timestamp when the order is created.

datetime

A datetime object converted from Order.timestamp.

id

The unique id of the order that is used to query the order in order queue or order books.

status

An OrderStatus object represents the current order status.

type

An OrderType object represents order type.

side

An OrderSide object represents order side.

quote_name

The name of the quote asset.

base_name

The name of the quote asset.

symbol

The name of the trading pair symbol, which is quote asset name/base asset name.

amount

The total amount of the order.

filled

The filled amount of the order.

remaining

The remaining amount of the order. The relation filled + remaining = amount always holds true.

filled_percentage

The filled percentage of the order, computed as 100.0 * filled/amount.

price

The limit price of the order. Applicable for limit order and stop limit order. For market order, it defaults to 0.

stop_price

The stop limit price of the order. Applicable for stop limit order. For other order types, it defaults to 0.

transactions

A list of Transaction that accounts for the filled amount of the order.

fee

A dictionary of fees taken by the exchange.

>>> order.fee
{'FOO': 0.05}
info

A dictionary of order info.

>>> order.info
{'id': 4920631724339456104,
 'datetime': '2018-02-02 14:26:00',
 'timestamp': 1517599560000,
 'status': 'filled',
 'symbol': 'FOO/BAR',
 'type': 'limit',
 'side': 'buy',
 'price': 0.000954,
 'stop_price': 0,
 'amount': 100,
 'filled': 100,
 'remaining': 0,
 'transaction': [{'datetime': '2018-02-02 15:44:00', 'timestamp': 1517604240000, 'price': 0.00095367, 'amount': 100}],
 'fee': {'FOO': 0.05}}
open()
accept()
cancel()
generate_transaction(amount, price, timestamp)
execute_transaction(transaction)
pay_fee(asset, amount)
class Transaction(quote_name, base_name, price, amount, side, timestamp)

Attributes of Transaction are very similar to those in Order. In fact, Order is inherited from Transaction with more attributes and methods.

timestamp
datetime
id
side
quote_name
base_name
symbol
amount
price
info
>>> tx.info
{'datetime': '2018-02-02 15:44:00', 'timestamp': 1517604240000, 'price': 0.00095367, 'amount': 100}