TradePosition#

tradeexecutor.analysis.trade_analyser.TradePosition Python class in Trading Strategy framework.

class TradePosition[source]#

Bases: object

How a particular asset traded.

Each asset can have multiple entries (buys) and exits (sells)

For a simple strategies there can be only one or two trades per position.

  • Enter (buy)

  • Exit (sell optionally)

__init__(position_id, trades=<factory>, opened_at=None, closed_at=None)#
Parameters:
Return type:

None

Methods

__init__(position_id[, trades, opened_at, ...])

add_trade(t)

can_trade_close_position(t)

get_first_entry_price()

What was the price when the first entry buy for this position was made.

get_last_exit_price()

What was the time when the last sell for this position was executd.

get_max_size()

Get the largest size of this position over the time

get_total_lp_fees_paid()

Get the total amount of swap fees paid in the position.

get_trade_count()

How many individual trades was done to manage this position.

has_bad_data_issues()

Do we have legacy / incompatible data issues.

is_closed()

is_lose()

is_open()

is_stop_loss()

Was stop loss triggered for this position

is_take_profit()

Was trake profit triggered for this position

is_win()

Did we win this trade.

Attributes

buy_value

buys

close_price

At what price we exited this position.

closed_at

Closing the position could be deducted from the trades themselves, but we cache it by hand to speed up processing

duration

How long this position was held.

open_price

At what price we opened this position.

open_quantity

open_value

The current value of this open position, with the price at the time of opening.

opened_at

Closing the position could be deducted from the trades themselves, but we cache it by hand to speed up processing

pair_id

Position id is the same as the opening trade id.

realised_profit

Calculated life-time profit over this position.

realised_profit_percent

Calculated life-time profit over this position.

sell_value

sells

position_id

Position id of the trade Used to be self.trades[0].trade_id

trades

List of all trades done for this position

position_id: int#

Position id of the trade Used to be self.trades[0].trade_id

trades: List[SpotTrade]#

List of all trades done for this position

opened_at: Optional[Timestamp] = None#

Closing the position could be deducted from the trades themselves, but we cache it by hand to speed up processing

closed_at: Optional[Timestamp] = None#

Closing the position could be deducted from the trades themselves, but we cache it by hand to speed up processing

property pair_id: int#

Position id is the same as the opening trade id.

property duration: Optional[timedelta]#

How long this position was held.

Returns:

None if the position is still open

property open_value: float#

The current value of this open position, with the price at the time of opening.

property open_price: float#

At what price we opened this position.

Supports only simple enter/exit positions.

get_first_entry_price()[source]#

What was the price when the first entry buy for this position was made.

Return type:

float

get_last_exit_price()[source]#

What was the time when the last sell for this position was executd.

Return type:

float

property close_price: float#

At what price we exited this position.

Supports only simple enter/exit positions.

property realised_profit: float#

Calculated life-time profit over this position.

property realised_profit_percent: float#

Calculated life-time profit over this position.

is_win()[source]#

Did we win this trade.

is_stop_loss()[source]#

Was stop loss triggered for this position

Return type:

bool

is_take_profit()[source]#

Was trake profit triggered for this position

Return type:

bool

get_max_size()[source]#

Get the largest size of this position over the time

Return type:

float

get_trade_count()[source]#

How many individual trades was done to manage this position.

Return type:

int

get_total_lp_fees_paid()[source]#

Get the total amount of swap fees paid in the position. Includes all trades.

Return type:

int

has_bad_data_issues()[source]#

Do we have legacy / incompatible data issues.

Return type:

bool

__init__(position_id, trades=<factory>, opened_at=None, closed_at=None)#
Parameters:
Return type:

None