PositionManager#

tradeexecutor.strategy.pandas_trader.position_manager.PositionManager class.

class PositionManager[source]#

Bases: object

Open/closing of positions.

Abstracts the complex logic with prices and such from the strategy writer.

Takes the price feed and current execution state as an input and produces the execution instructions to change positions.

__init__(timestamp, universe, state, pricing_model)[source]#
Parameters

Methods

__init__(timestamp, universe, state, ...)

close_all()

Close all open positions.

close_position(position[, trade_type])

Close a single position.

is_any_open()

Do we have any positions open.

open_1x_long(pair, value[, take_profit_pct, ...])

Open a long.

__init__(timestamp, universe, state, pricing_model)[source]#
Parameters
is_any_open()[source]#

Do we have any positions open.

Return type

bool

open_1x_long(pair, value, take_profit_pct=None, stop_loss_pct=None)[source]#

Open a long.

  • For simple buy and hold trades

  • Open a spot market buy.

  • Checks that there is not existing position - cannot increase position

Parameters
  • pair (DEXPair) – Trading pair where we take the position

  • value (USDollarAmount) – How large position to open, in US dollar terms

  • take_profit_pct (Optional[float]) – If set, set the position take profit relative to the current market price. 1.0 is the current market price. If asset opening price is $1000, take_profit_pct=1.05 will sell the asset when price reaches $1050.

  • stop_loss_pct (Optional[float]) – If set, set the position to trigger stop loss relative to the current market price. 1.0 is the current market price. If asset opening price is $1000, stop_loss_pct=0.95 will sell the asset when price reaches 950.

Returns

A list of new trades. Opening a position may general several trades for complex DeFi positions, though usually the result contains only a single trade.

Return type

List[TradeExecution]

close_position(position, trade_type=TradeType.rebalance)[source]#

Close a single position.

The position may already have piled up selling trades. In this case calling close_position() again on the same position does nothing and None is returned.

Parameters
  • position (TradingPosition) – Position to be closed

  • trade_type (TradeType) – What’s the reason to close the position

Returns

A trade that will close the position fully. If there is nothing left to close, return None.

Return type

Optional[TradeExecution]

close_all()[source]#

Close all open positions.

Returns

List of trades that will close existing positions

Return type

List[TradeExecution]