Module areixio.base

Classes

class Base

The Base class for runner

Ancestors

  • abc.ABC

Subclasses

  • areixio.broker.Broker
  • areixio.statistic.Statistic
  • Strategy

Methods

def critical(self, content: str) ‑> None

Logging function in critical level

Args

content : str
content you would like to print out
def debug(self, content: str) ‑> None

Logging function in debug level

Args

content : str
content you would like to print out
def error(self, content: str) ‑> None

Logging function in error level

Args

content : str
content you would like to print out
def execption(self, content: str) ‑> None

Logging function in exception

Args

content : str
content you would like to print out
def finish(self)

The function will be invoked after backtesting complete

def info(self, content: str) ‑> None

Logging function in info level

Args

content : str
content you would like to print out
def initialize(self)

The function will be invoked before backtesting starts

def on_bar(self, tick: datetime.datetime)

The core functon that will be invoked in every bar

The run function must be implemented.

Args

tick : [datetime]
datetime of current bar
def on_market_close(self)

The function will be invoked when market closes

def on_market_start(self)

The function will be invoked when market starts

def on_tick(self, tick_data: dict)

The core functon that will be invoked in every tick

The run function must be implemented.

Args

tick_data : [dict]
tick data
def warning(self, content: str) ‑> None

Logging function in warning level

Args

content : str
content you would like to print out
class Context (event_engine, feeds: Dict[str, areixio.datafeed.DataFeed], broker, strategy, orchestrator, exchange: Exchange, logger, benchmark=None, tradedays: List = None, initial_position: list = [], skip_datafeed: bool = False, do_print: bool = True, path: str = None)

The Context class which stored all the shared data

Instance variables

var assets_value : float

Entire asset value (portfolio value + available balance)

Returns

[float]
return the entire asset value
var default_accountAccountData

Default cash account

Returns

[AccountData]
return the default cash account
var holding_number : int

Number of holdings

Returns

[int]
return the number of holdings
var holding_value : float

Entire portfolio value

Returns

[float]
return the entire portfolio value
var now : datetime.datetime
var symbols : list

Symbol

Returns

[list]
return the list of all symbols

Methods

def add_datafeed(self, feed: areixio.datafeed.DataFeed)

add datafeed

Args

feed : DataFeed
description
def draw(self, data_point: float, graph_name: str, figure_name: str, color: str = '', is_line: bool = True, is_scatter: bool = False, is_bar: bool = False, plot_height: int = 110) ‑> None

draw custom data points and construct graph and figure.

Args

data_point : float
data point
graph_name : str
graph name (can have multiple graphs in the same figure)
figure_name : str
figure name
color : str, optional
color. Defaults to "".
is_line : bool, optional
is_line. Defaults to True.
is_scatter : bool, optional
is_scatter. Defaults to False.
is_bar : bool, optional
is_bar. Defaults to False.
plot_height : int, optional
figure height. Defaults to 110.

First layer is figure name; second layer consists of graph_name|type|color; last layer is tick and data

def draw_figure(self)

Plot custom bokeh figure into report html

def get_account(self, asset: str = None, exchange: Exchange = None, aio_account_id: str = None, force_return: bool = False) ‑> AccountData

get the selected account

Args

asset : str, optional
instrument name. Defaults to None.
exchange : Exchange, optional
exchange. Defaults to None.
position_side : PositionSide, optional
position side. Defaults to PositionSide.NET.
aio_account_id : str, optional
aio_account_id. Defaults to None.
force_return : bool, optional
if force_return an object. Defaults to False.

Returns

[PositionData]
return the requested position
def get_all_accounts(self) ‑> List[AccountData]

get the list of all accounts

Returns

List[PositionData]
return the list of all positions
def get_all_bar_data(self) ‑> List

summary

Returns

List
description
def get_all_feeds(self) ‑> List[areixio.datafeed.DataFeed]

summary

Returns

List["DataFeed"]: description

def get_all_history(self) ‑> List

summary

Returns

List
description
def get_all_open_orders(self) ‑> List[OrderData]

get the list of all open orders

Returns

List[OrderData]
return the list of all open orders
def get_all_orders(self) ‑> List[OrderData]

get the list of all orders

Returns

List[OrderData]
return the list of all orders
def get_all_pnl_books(self) ‑> List[areixio.utils.pnl.PositionPnL]

get the list of all position pnl books

Returns

List[PositionPnL]
return the list of all position pnl books
def get_all_position_margin(self) ‑> float

get the sum of position margin

Returns

float
return the total position margin
def get_all_positions(self) ‑> List[PositionData]

get the list of all positions

Returns

List[PositionData]
return the list of all positions
def get_all_trades(self) ‑> List[TradeData]

get the list of all trades

Returns

List[TradeData]
return the list of all trades
def get_asset_type(self, symbol: str = None, exchange: Exchange = None, aio_symbol: str = None) ‑> AssetType

get the asset type of selected symbol

Args

symbol : str, optional
instrument name. Defaults to None.
exchange : Exchange, optional
exchange. Defaults to None.
aio_symbol : str, optional
aio_symbol. Defaults to None.

Returns

[AssetType]
return the asset type of requested position
def get_bar_data(self, symbol: str = None, exchange: Exchange = None, aio_symbol: str = None) ‑> pandas.core.series.Series

get the bar data

Args

symbol : str, optional
instrument name. Defaults to None.
exchange : Exchange, optional
exchange. Defaults to None.
aio_symbol : str, optional
aio_symbol. Defaults to None.

Returns

[pd.Series]
return the bar data
def get_datafeed(self, symbol: str = None, exchange: Exchange = None, aio_symbol: str = None) ‑> areixio.datafeed.DataFeed

get the data feed

Args

symbol : str, optional
instrument name. Defaults to None.
exchange : Exchange, optional
exchange. Defaults to None.
aio_symbol : str, optional
aio_symbol. Defaults to None.

Returns

[DataFeed]
return the datafeed
def get_exchange(self, symbol: str = None, exchange: Exchange = None, aio_symbol: str = None) ‑> Exchange

get the exchange of selected symbol

Args

symbol : str, optional
instrument name. Defaults to None.
exchange : Exchange, optional
exchange. Defaults to None.
aio_symbol : str, optional
aio_symbol. Defaults to None.

Returns

[Exchange]
return the asset type of requested position
def get_history(self, symbol: str = None, exchange: Exchange = None, aio_symbol: str = None, start: datetime.datetime = None, end: datetime.datetime = None) ‑> pandas.core.frame.DataFrame

get the historical bar data

Args

symbol : str, optional
instrument name. Defaults to None.
exchange : Exchange, optional
exchange. Defaults to None.
aio_symbol : str, optional
aio_symbol. Defaults to None.
start : datetime, optional
start time. Defaults to None.
end : datetime, optional
end time. Defaults to None.

Returns

[pd.DataFrame]
return the historical bar data
def get_latest_price(self, symbol: str = None, exchange: Exchange = None, aio_symbol: str = None) ‑> float

get the latest price

Args

symbol : str, optional
instrument name. Defaults to None.
exchange : Exchange, optional
exchange. Defaults to None.
aio_symbol : str, optional
aio_symbol. Defaults to None.

Returns

[float]
return the lastest price data
def get_logger(self)
def get_market_value(self, symbol: str = None, exchange: Exchange = None, position_side: PositionSide = PositionSide.NET, aio_position_id: str = None) ‑> float

get the market value of selected position

Args

symbol : str, optional
instrument name. Defaults to None.
exchange : Exchange, optional
exchange. Defaults to None.
position_side : PositionSide, optional
position side. Defaults to PositionSide.NET.
aio_position_id : str, optional
aio_position_id. Defaults to None.

Returns

[float]
return the market value of requested position
def get_open_order(self, order_id: str) ‑> OrderData

get the selected open order

Args

order_id : str, optional
order_id. Defaults to None.

Returns

[OrderData]
return the requested order
def get_order(self, order_id: str = None, order_seq: int = None) ‑> OrderData

get the selected order

Args

order_id : str, optional
order_id. Defaults to None.
order_seq : str, optional
order_seq. Defaults to None.

Returns

[OrderData]
return the requested order
def get_pnlbook(self, symbol: str = None, exchange: Exchange = None, position_side: PositionSide = PositionSide.NET, aio_position_id: str = None) ‑> areixio.utils.pnl.PositionPnL

get the pnl book of selected position

Args

symbol : str, optional
instrument name. Defaults to None.
exchange : Exchange, optional
exchange. Defaults to None.
position_side : PositionSide, optional
position side. Defaults to PositionSide.NET.
aio_position_id : str, optional
aio_position_id. Defaults to None.

Returns

[PositionPnL]
return the pnl book of requested position
def get_position(self, symbol: str = None, exchange: Exchange = None, position_side: PositionSide = PositionSide.NET, aio_position_id: str = None, force_return: bool = False) ‑> PositionData

get the selected position

Args

symbol : str, optional
instrument name. Defaults to None.
exchange : Exchange, optional
exchange. Defaults to None.
position_side : PositionSide, optional
position side. Defaults to PositionSide.NET.
aio_position_id : str, optional
aio_position_id. Defaults to None.
force_return : bool, optional
if force_return an object. Defaults to False.

Returns

[PositionData]
return the requested position
def get_quantity(self, symbol: str = None, exchange: Exchange = None, position_side: PositionSide = PositionSide.NET, aio_position_id: str = None) ‑> float

get the selected position quantity

Args

symbol : str, optional
instrument name. Defaults to None.
exchange : Exchange, optional
exchange. Defaults to None.
position_side : PositionSide, optional
position side. Defaults to PositionSide.NET.
aio_position_id : str, optional
aio_position_id. Defaults to None.

Returns

[flaot]
return the requested position quantity
def get_trade(self, order_id: str = None, order_seq: int = None) ‑> TradeData

get the selected order

Args

order_id : str, optional
order_id. Defaults to None.
order_seq : str, optional
order_seq. Defaults to None.

Returns

[TradeData]
return the requested trade
def plot(self, path: str = None, interactive: bool = True, open_browser: bool = None, **kwargs)

Plot html report

Args

path : str, optional
path. Defaults to None.
interactive : bool, optional
is interactive. Defaults to True.
open_browser : bool, optional
if open browser. Defaults to None.
def set_leverage(self, leverage: float, symbol: str = None, exchange: Exchange = None, position_side: PositionSide = None, aio_position_id: str = None) ‑> areixio.utils.pnl.PositionPnL
def set_margin_mode(self, is_isolated: bool, symbol: str = None, exchange: Exchange = None, position_side: PositionSide = None, aio_position_id: str = None) ‑> areixio.utils.pnl.PositionPnL