Trigger#

API documentation for tradeexecutor.state.trigger.Trigger Python class in Trading Strategy framework.

class Trigger[source]#

Bases: object

Trigger data for market orders.

Triggers can be on both on

  • Unopened positions, see tradeeexecutor.state.portfolio.Portfolio.pending_positions where the trigger is on the trade that will open the position (market limit order case)

  • Opened positions, see tradeeexecutor.state.position.TradingPosition.pending_positions where the trigger order is on the increase/reduce position (partial take profit case)

  • Trigger orders can be created to make trades to happen outside the strategy decision cycle

  • Market limit order is the most famous trigger order from the TradFi markets, used to enter into breakout positions

  • Triggers are executed in the s

  • Nested structure inside tradeexecutor.state.trade.TradeExecution

  • Any price structure estimations on trigger trades is based on the time of the trigger creation, and maybe very different when the trigger is executed

__init__(type, condition, price=None, triggering_at=None, triggering_at_delta=None, expires_at=None, expired_at=None, triggered_at=None)#
Parameters:
Return type:

None

Methods

__init__(type, condition[, price, ...])

is_executed()

This trigged is already executed.

is_expired(ts)

This trigger has expired.

is_triggering(market_price, timestamp, ...)

Is the given price triggering a tride.

Attributes

type

Do we trigger when price crossed above or below

condition

When this trigger is executed

price

When to take action

triggering_at

Always executed at a certain time.

triggering_at_delta

Always executed at a certain time.

expires_at

After expiration, this trade execution is removed from the hanging queue

expired_at

When this trigger was marked as expired

triggered_at

When the trigger happened

type: TriggerType#

Do we trigger when price crossed above or below

condition: TriggerCondition#

When this trigger is executed

price: float | None#

When to take action

triggering_at: datetime.datetime | None#

Always executed at a certain time.

See TriggerType.timed_absolute

triggering_at_delta: datetime.timedelta | None#

Always executed at a certain time.

See TriggerType.timed_relative_to_open

expires_at: datetime.datetime | None#

After expiration, this trade execution is removed from the hanging queue

expired_at: datetime.datetime | None#

When this trigger was marked as expired

triggered_at: datetime.datetime | None#

When the trigger happened

is_expired(ts)[source]#

This trigger has expired.

Expired triggers must not be executed, and must be moved to past triggers.

Parameters:

ts (datetime) –

Return type:

bool

is_executed()[source]#

This trigged is already executed.

Return type:

bool

is_triggering(market_price, timestamp, position_open_time)[source]#

Is the given price triggering a tride.

Parameters:
Return type:

bool

__init__(type, condition, price=None, triggering_at=None, triggering_at_delta=None, expires_at=None, expired_at=None, triggered_at=None)#
Parameters:
Return type:

None