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)#
Methods
__init__
(position_id[, trades, opened_at, ...])add_trade
(t)can_trade_close_position
(t)What was the price when the first entry buy for this position was made.
What was the time when the last sell for this position was executd.
Get the largest size of this position over the time
Get the total amount of swap fees paid in the position.
How many individual trades was done to manage this position.
Do we have legacy / incompatible data issues.
is_closed
()is_lose
()is_open
()Was stop loss triggered for this position
Was trake profit triggered for this position
is_win
()Did we win this trade.
Attributes
buy_value
buys
At what price we exited this position.
Closing the position could be deducted from the trades themselves, but we cache it by hand to speed up processing
How long this position was held.
At what price we opened this position.
open_quantity
The current value of this open position, with the price at the time of opening.
Closing the position could be deducted from the trades themselves, but we cache it by hand to speed up processing
Position id is the same as the opening trade id.
Calculated life-time profit over this position.
Calculated life-time profit over this position.
sell_value
sells
Position id of the trade Used to be self.trades[0].trade_id
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 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:
- get_last_exit_price()[source]#
What was the time when the last sell for this position was executd.
- Return type:
- property close_price: float#
At what price we exited this position.
Supports only simple enter/exit positions.
- get_trade_count()[source]#
How many individual trades was done to manage this position.
- Return type: