Python
StrategyTrader

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

💡
The 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 by OrderResponse from caling open() or order().
  • 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()

position()

async def position(self, exchange: Exchange, symbol: Symbol) -> Position

Description

Get current Position for specified exchange and trading pair.


Function Parameters

  • exchange - the Exchange to perform on in Live/LiveTestnet.
  • symbol - the Symbol to retrieve for.
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_open_orders()

async def get_open_orders(self, exchange: Exchange, symbol: Symbol) -> List[ActiveOrder]

Description

Get all current open (unplaced) orders on the specific exchange.


Function Parameters

  • exchange - the Exchange to perform on in Live/LiveTestnet.
  • symbol - the Symbol to check for.
get_order_book()

get_order_book()

async def get_order_book(self, exchange: Exchange, symbol: Symbol) -> OrderBookSnapshot

Description

Get latest order book snapshot for specified symbol on the specific exchange.

This convenience method does not work in RuntimeMode.Backtest.


Function Parameters

  • exchange - the Exchange to perform on in Live/LiveTestnet.
  • symbol - the Symbol to check for.
get_current_available_balance()

get_current_available_balance()

async def get_current_available_balance(self, exchange: Exchange, symbol: Symbol) -> float

Description

Get current available balance in wallet.


Function Parameters

  • exchange - the Exchange to perform on in Live/LiveTestnet.
  • symbol - the Symbol to check for.
get_current_price()

get_current_price()

async def get_current_price(self, exchange: Exchange, symbol: Symbol) -> float

Description

Get current price for the trading pair in specified exchange.


Function Parameters

  • exchange - the Exchange to perform on in Live/LiveTestnet.
  • symbol - the Symbol to check for.
get_order_details()

get_order_details()

async def get_order_details(self, exchange: Exchange, symbol: Symbol, client_order_id: str) -> OrderUpdate 

Description

Get order details of the order with the client order id passed.

In Backtest mode this function does not achieve anything.


Function Parameters

  • exchange - the Exchange to perform on in Live/LiveTestnet.
  • symbol - the Symbol to check for.
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.


Function Parameters

  • exchange - the Exchange to perform on in Live/LiveTestnet.
  • symbol - the Symbol to check for.