Module areix_io.strategy
Classes
class Strategy
-
Strategy Base
Ancestors
- Base
- abc.ABC
Methods
def after_bar(self, tick)
-
The function will be invoked after the bar
Args
tick
:[datetime]
- datetime of current bar
def before_bar(self, tick)
-
The function will be invoked before enter the bar
Args
tick
:[datetime]
- datetime of current bar
def before_trade(self, order)
-
The function will be invoked before trading (Can conduct money management and risk management here)
Args
order
:[dict]
- order you have placed
Returns
[bool]
- True, if trade is executable
def buy(self, code, quantity, price=None, stop_price=None, msg='', ioc=False, asset_type='Crypto', currency='USD', ttl='gtc', **kwargs)
-
Create a buy (long) order and send it to the broker
Args
code
:[str]
-
- The instrument code that you would like to trade.
- The
code
must exists inself.ctx.feed
quantity
:[int]
-
- The quantity of the order.
- The quanity must be positive.
price
:[float]
, optional-
- The price of the order.
- The price must be positive.
- If price is
None
, the order would be aMarket
order - If price is specified, the order would be a
Limit
order. (also can be regarded asTakeProfit
order) - Defaults to None.
stop_price
:[float]
, optional-
- If
stop_price
is specified, the order would be aStop
order. - If both
stop_price
andprice
are specified, the order would be aStopLimit
order, when the price is matched, theStopLimit
order will become aLimit
order. (also can be regarded asStopLoss
order) - Defaults to None.
- If
msg
:[str]
, optional-
- The msg/notes that you would like to display in the final trade record.
- Defaults to ''.
ioc
:[bool]
, optional-
- IOC(Immediate or Cancel Order)
- If
ioc
is True, the order would only require a partial fill. - If
ioc
is False, the order is AON(all-or-none), it will fill the order completely or cancel it, partial fills are not allowed. - Defaults to False.
asset_type
:[str]
, optional-
- The order asset type.
- If
asset_type
is 'Crypto', the order will automatically check quantity to be greater than the minimum lot size. - If
asset_type
is 'Stock', the order will automatically check quantity to be the multiples of the lot size. - Defaults to 'Crypto'.
currency
:[str]
, optional-
- The order currency.
- Defaults to 'USD'.
ttl
:[int]
, optional-
- TTL(Time To Live), the time validity of an order, the order will be in the pending list untill ttl became 0.
- If
ttl
is 'gtc'(Good 'Til Canceled), the order wont be expired. - Defaults to 'gtc'.
Returns
[dict]
- order you have placed
def cancel(self, order)
-
Cancels the order in the broker
Args
order
:[dict]
- order you have placed
def on_bar(self, tick)
-
This method must be implemented, and write your own trading strategy here
Call the strategies’ on_bar method to let the strategy evaluate the new data
Args
tick
:[datetime]
- datetime of current bar
def on_order_ok(self, order)
-
The function will be invoked after an order is executed or filled, it results in a trade
Args
order
:[dict]
- order you have placed
def on_order_timeout(self, order)
-
The function will be invoked after an order timeout (the time to live is expired)
Args
order
:[dict]
- order you have placed
def order_amount(self, code, amount, side, price=None, stop_price=None, msg='', ioc=False, asset_type='Crypto', currency='USD', ttl='gtc', **kwargs)
-
Create an order and the quantity will depend on your placed amount.
Args
amount
:[float]
-
- The amount that you would like to place
The rest of the parameters see also
Strategy.buy()
Returns
[dict]
- order you have placed
def order_lotsize(self, code, lots, side, price=None, stop_price=None, msg='', ioc=False, asset_type='Crypto', currency='USD', ttl='gtc', **kwargs)
-
Create an order and the quantity will depend on the lots and lot size
Args
lots
:[int]
-
- The lots that you would like to place the order
- The order quantity will automatically be the
lots
timeslot_size
side
:[SideType]
-
- The side that you would like to place the order
- Must be one of the:
- SideType.BUY
- SideType.SELL
- SideType.SHORTSELL
The rest of the parameters see also
Strategy.buy()
Returns
[dict]
- order you have placed
def order_target_percent(self, code, target_percent, price=None, stop_price=None, msg='', ioc=False, asset_type='Crypto', currency='USD', ttl='gtc', **kwargs)
-
Place an order to rebalance a position to have final value of target percentage of current portfolio value
Args
target_percent
:[float]
-
- The target percentage
The rest of the parameters see also
Strategy.buy()
Returns
[dict]
- order you have placed
def order_target_quantity(self, code, overall_quantity, price=None, stop_price=None, msg='', ioc=False, asset_type='Crypto', currency='USD', ttl='gtc', **kwargs)
-
Place an order to rebalance a position to have final size of target
Args
overall_quantity
:[float]
-
- The overall quantity that this position that you would like to hold
The rest of the parameters see also
Strategy.buy()
Returns
[dict]
- order you have placed
def order_target_value(self, code, overall_amount, price=None, stop_price=None, msg='', ioc=False, asset_type='Crypto', currency='USD', ttl='gtc', **kwargs)
-
Place an order to rebalance a position to have final value of target
Args
overall_amount
:[float]
-
- The overall amount that this position that you would like to hold
The rest of the parameters see also
Strategy.buy()
Returns
[dict]
- order you have placed
def sell(self, code, quantity, price=None, stop_price=None, msg='', ioc=False, asset_type='Crypto', currency='USD', ttl='gtc', **kwargs)
-
To create a selll (short) order and send it to the broker
Args
The parameters see also
Strategy.buy()
Returns
[dict]
- order you have placed
Inherited members