Module areixio.brokers.backtest_broker
Classes
class BackTestBroker (commission_rate: float = 0.0, min_commission: float = 0, commission_scheme=None, balance: float = 1000, initial_position: list = [], trade_at='close', short_cash: bool = False, slippage: float = 0.0, base_currency: str = 'USDT', exchange: Union[str, Exchange, ForwardRef(None)] = None, version: int = None, asset_type: Union[str, AssetType, ForwardRef(None)] = None, **kwargs)
-
Broker Base
Broker + Fund Administrator Parameters:
trade_at (str, optional): - The moment of price that would be executed for
Market
order. - Defaults to 'close'. slippage (float, optional): - The percentage of slippage that would be happened during backtesting. - Defaults to 0.0. short_cash (bool, optional): - If short_cash is True, theBroker
will allow to perform short selling - Defaults to False. balance (int, optional): - The balance amount that you would like to exercise in the backtesting - Defaults to 200000. initial_position (list, optional): - attributes: { # 'symbol':'', 'code':'', 'exchange':'', 'asset_type':'', 'position_side':'', 'quantity': ''} trade_at: only accept open, close & adj_close (open & close will take dividend into account) short_cash: allow to conduct short sellingAncestors
- areixio.broker.Broker
- Base
- abc.ABC
Methods
def add_balance(self, amount: float)
def add_commission_scheme(self, scheme: areixio.utils.pnl.CommissionScheme, symbol: str = '', exchange: Exchange = None) ‑> None
def add_connection(self, exchange: str, asset_type: Union[str, AssetType], key: str = '', secret: str = '', user_id: str = None, passphrase: str = None, is_testnet: bool = False, leverage: float = None, mode: str = 'oneway', is_isolated: bool = True, version: int = None, on_account_callback: Callable = None, on_order_callback: Callable = None, on_trade_callback: Callable = None, on_position_callback: Callable = None)
def cancel_order(self, order: OrderData) ‑> OrderData
-
Cancel an existing order. implementation should finish the tasks blow: * send request to server
def close(self) ‑> None
-
Close broker connection.
def connect(self, is_testnet: bool = False) ‑> None
-
Start broker connection.
to implement this method, you must: * connect to server if necessary * log connected if all necessary connection is established * do the following query and response corresponding on_xxxx and write_log * contracts : on_contract * account asset : on_account * account holding: on_position * orders of account: on_order * trades of account: on_trade * if any of query above is failed, write log.
future plan: response callback/change status instead of write_log
def get_commission_rate(self, symbol: str = '', exchange: Exchange = None) ‑> float
def get_commission_scheme(self, symbol: str = '') ‑> float
def reset(self)
def send_order(self, order: OrderData) ‑> OrderData
-
Send a new order to server.
implementation should finish the tasks blow: * create an OrderData from req using OrderRequest.create_order_data * assign a unique(gateway instance scope) id to OrderData.orderid * send request to server * if request is sent, OrderData.status should be set to Status.SUBMITTING * if request is failed to sent, OrderData.status should be set to Status.REJECTED * response on_order: * return vt_orderid
:return str vt_orderid for created OrderData
def subscribe(self, symbol, exchange=None, asset_type=None) ‑> None
-
Subscribe tick data update.
Inherited members