StrategyTrader
You will be able to interact with the Cybotrade runtime to perform actions against an Exchange of your choice by using the StrategyTrader
and it's
provided methods.
Methods
exchange
parameter does not affect anything in Backtest mode. open()
open()
async def open(
self,
exchange: Exchange,
side: OrderSide,
quantity: float,
symbol: Symbol,
is_hedge_mode: bool,
is_post_only: bool,
limit: float | None,
time_in_force: TimeInForce | None,
take_profit: float | None,
stop_loss: float| None
) -> OrderResponse:
Description
Opens a trade with the given side, quantity, limit, take_profit and stop_loss.
If the limit
parameter is provided this will place a limit order, otherwise, if no value is provided to limit
the order will be place as a market order.
Note that using this function guarantees that the take profit and stop loss order is placed with the exchange native api and not using Limit/Stop orders. This is not true for
Strategy.order()
.
Function Parameters
exchange
- the Exchange to perform on in Live/LiveTestnet.side
- the OrderSide to open on.symbol
- the Symbol to open for.quantity
- the quantity of asset to open on.is_hedge_mode
- whether the account trading the asset is set to Hedge.is_post_only
- whether to turn the Limit order into a post-only order..limit
- the limit price to open at.time_in_force
- the TimeInForce factor an order will remain active.take_profit
- take profit price.stop_loss
- stop loss price.
order()
order()
async def order(self, params: OrderParams) -> OrderResponse
Description
Places an order with a customized OrderParams
.
Do note that this is a more primitive method and it's use should be reserved for advanced use-cases and/or for total control over the strategy.
Take-profit and Stop-loss orders must be handled manually if a trade is opened using this method.
Function parameters
params
- the OrderParams for the desired order to be placed.
cancel()
cancel()
async def cancel(self, exchange: Exchange, id: str) -> OrderResponse
Description
Cancels a specific order by its id.
Function parameters
id
- the id of an existing trade.
This id is returned byOrderResponse
from calingopen()
ororder()
.exchange
- the Exchange to perform on in Live/LiveTestnet.
close()
close()
async def close(
self,
exchange: Exchange,
side: OrderSide,
size: OrderSize,
is_hedge_mode: bool,
time_in_force: TimeInForce
)
Description
Closes an *existing position on the given side and quantity. This function closes the trade with market order.
Note that this function will fail if there is no position to close.
Function parameters
exchange
- the Exchange to perform on in Live/LiveTestnet.side
- the OrderSide of the close order.size
- the OrderSize of the close order.is_hedge_mode
- whether the account trading the asset is set to Hedge.time_in_force
- the TimeInForce factor an order will remain active.
position()
all_position()
all_position()
async def all_position(self, exchange: Exchange) -> List[Position]
Description
Get all current holding Positions on the provided exchange.
This function will return an empty List
if there are currently no positions being held.
In Backtest mode this will get all positions for all symbols provided in
candle_topics
.
Function Parameters
exchange
- the Exchange to perform on in Live/LiveTestnet.
get_open_orders()
get_order_book()
get_current_available_balance()
get_current_price()
get_order_details()
get_balance_data()
get_balance_data()
async def get_balance_data(self, exchange: Exchange, symbol: Symbol) -> Balance
Description
Get current balance data of the trading pair in specified exchange.
In Backtest mode this function can be used to retrieve only the current available balance in
RuntimeMode.Backtest
.