-
Notifications
You must be signed in to change notification settings - Fork 0
Orders
This guide provides further details about the available order types for the platform, along with the execution instructions supported for each.
本指南详细介绍了平台可用的订单类型,以及每种类型支持的执行指令。
Orders are one of the fundamental building blocks of any algorithmic trading strategy. NautilusTrader has unified a large set of order types and execution instructions from standard to more advanced, to offer as much of an exchanges available functionality as possible. This enables traders to define certain conditions and instructions for order execution and management, facilitating the creation of virtually any type of trading strategy.
订单是任何算法交易策略的基本组成部分之一。NautilusTrader 统一了大量从标准到更高级的订单类型和执行指令,以尽可能多地提供交易所的可用功能。这使得交易者能够为订单执行和管理定义某些条件和指令,从而促进创建几乎任何类型的交易策略。
The two main types of orders are Market orders and Limit orders. All the other order types are built from these two fundamental types, in terms of liquidity provision they are exact opposites. Market orders demand liquidity and require immediate trading at the best price available. Conversely, Limit orders provide liquidity, they act as standing orders in a limit order book at a specified limit price.
两种主要的订单类型是市价订单和限价订单。所有其他订单类型都是基于这两种基本类型构建的,就流动性提供而言,它们是完全相反的。市价单要求流动性,并要求以可获得的最佳价格立即交易。相反,限价单提供流动性,它们在限价订单簿中充当指定限价的待执行订单。
The core order types available for the platform are (using the enum values):
平台可用的核心订单类型是(使用枚举值):
- MARKET 市价
- LIMIT 限价
- STOP_MARKET 市价止损
- STOP_LIMIT 限价止损
- MARKET_TO_LIMIT 市价转限价
- MARKET_IF_TOUCHED 触价市价单
- LIMIT_IF_TOUCHED 触价限价单
- TRAILING_STOP_MARKET 追踪止损市价单
- TRAILING_STOP_LIMIT 追踪止损限价单
NautilusTrader has unified the API for a large set of order types and execution instructions. Not all of these are available for every exchange. If an order is submitted where an instruction or option is not available, the system will NOT submit the order and an error will be logged with a clear explanatory message.
NautilusTrader 统一了大量订单类型和执行指令的 API。并非所有交易所都提供所有这些功能。如果提交的订单中包含不可用的指令或选项,则系统将不会提交该订单,并且会记录一个带有清晰解释消息的错误。
An order is aggressive if the type is MARKET or if its executing like a MARKET order (taking liquidity).
An order is passive if the type is not MARKET (providing liquidity).
An order is active local if it is still within the local system boundary in one of the following three (non-terminal) status:
- INITIALIZED 已初始化
- EMULATED 已模拟
- RELEASED 已发布
An order is in-flight when in one of the following status:
- SUBMITTED 已提交
- PENDING_UPDATE 等待更新
- PENDING_CANCEL 等待取消
An order is open when in one of the following (non-terminal) status:
- ACCEPTED 已接受
- TRIGGERED 已触发
- PENDING_UPDATE 等待更新
- PENDING_CANCEL 等待取消
- PARTIALLY_FILLED 部分成交
An order is closed when in one of the following (terminal) status:
- DENIED 已拒绝
- REJECTED 已拒绝
- CANCELED 已取消
- EXPIRED 已过期
- FILLED 已成交
如果订单类型为 MARKET 或其执行方式类似于 MARKET 订单(获取流动性),则该订单为主动订单。
如果订单类型不是 MARKET(提供流动性),则该订单为被动订单。
如果订单仍在本地系统边界内,并且处于以下三种(非最终)状态之一,则该订单为本地活动订单:
- INITIALIZED 已初始化
- EMULATED 已模拟
- RELEASED 已发布
订单处于以下状态之一时,该订单为正在传输的订单:
- SUBMITTED 已提交
- PENDING_UPDATE 等待更新
- PENDING_CANCEL 等待取消
订单处于以下(非最终)状态之一时,该订单为未完成订单:
- ACCEPTED 已接受
- TRIGGERED 已触发
- PENDING_UPDATE 等待更新
- PENDING_CANCEL 等待取消
- PARTIALLY_FILLED 部分成交
订单处于以下(最终)状态之一时,该订单为已完成订单:
- DENIED 已拒绝
- REJECTED 已拒绝
- CANCELED 已取消
- EXPIRED 已过期
- FILLED 已成交
Certain exchanges allow a trader to specify conditions and restrictions on how an order will be processed and executed. The following is a brief summary of the different execution instructions available.
某些交易所允许交易者指定订单如何处理和执行的条件和限制。以下是可用的不同执行指令的简要概述。
The orders time in force is an instruction to specify how long the order will remain open or active, before any remaining quantity is canceled.
订单的有效期是指订单在剩余数量被取消之前将保持未完成或活动状态的时间。
- GTC (Good 'til Canceled): The order remains in force until canceled by the trader or the exchange. GTC(撤销前有效):订单一直有效,直到被交易者或交易所取消。
- IOC (Immediate or Cancel / Fill and Kill): The order will execute immediately with any portion of the order quantity which cannot be executed being canceled. IOC(立即成交或取消/全部成交或取消):订单将立即执行,无法执行的任何部分订单数量将被取消。
- FOK (Fill or Kill): The order will execute immediately, and in full, or not at all. FOK(全部成交或取消):订单将立即全部执行,否则全部取消。
- GTD (Good 'til Date): The order remains in force until reaching the specified expiration date and time. GTD(到期日有效):订单一直有效,直到达到指定的到期日期和时间。
- DAY (Good for session/day): The order remains in force until the end of the current trading session. DAY(当日有效):订单在当前交易时段结束前一直有效。
- AT_THE_OPEN (OPG): The order is only in force at the trading session open. AT_THE_OPEN (OPG):订单仅在交易时段开始时有效。
- AT_THE_CLOSE: The order is only in force at the trading session close. AT_THE_CLOSE:订单仅在交易时段结束时有效。
This instruction is to be used in conjunction with the GTD time in force to specify the time at which the order will expire and be removed from the exchanges order book (or order management system).
此指令与 GTD 有效期结合使用,用于指定订单到期并从交易所订单簿(或订单管理系统)中删除的时间。
An order which is marked as
post_only
will only ever participate in providing liquidity to the limit order book, and never initiating a trade which takes liquidity as an aggressor. This option is important for market makers, or traders seeking to restrict the order to a liquidity maker fee tier.标有
post_only
的订单将只参与为限价订单簿提供流动性,而从不作为主动方发起获取流动性的交易。此选项对做市商或希望将订单限制在流动性提供者费用等级的交易者非常重要。
An order which is set as
reduce_only
will only ever reduce an existing position on an instrument, and never open a new position (if already flat). The exact behavior of this instruction can vary between exchanges, however the behavior as per the Nautilus SimulatedExchange is typical of a live exchange.设置为
reduce_only
的订单将只减少Instrument的现有头寸,而从不建立新头寸(如果已经平仓)。此指令的确切行为可能因交易所而异,但是 Nautilus SimulatedExchange 的行为是典型的实时交易所行为。
- Order will be canceled if the associated position is closed (becomes flat) 如果相关头寸平仓(变为平仓),则订单将被取消
- Order quantity will be reduced as the associated positions size reduces 订单数量将随着相关头寸规模的减少而减少
The
display_qty
specifies the portion of a Limit order which is displayed on the limit order book. These are also known as iceberg orders as there is a visible portion to be displayed, with more quantity which is hidden. Specifying a display quantity of zero is also equivalent to setting an order as hidden.
display_qty
指定限价订单中显示在限价订单簿上的部分。这些订单也称为冰山订单,因为有一部分是可见的,而更多的数量是隐藏的。指定显示数量为零也等同于将订单设置为隐藏。
Also known as trigger method which is applicable to conditional trigger orders, specifying the method of triggering the stop price.
也称为触发方法,适用于条件触发订单,用于指定触发止损价格的方法。
- DEFAULT: The default trigger type for the exchange (typically LAST or BID_ASK) 默认值:交易所的默认触发类型(通常为 LAST 或 BID_ASK)
- LAST: The trigger price will be based on the last traded price. 最后价:触发价格将基于最后成交价格。
- BID_ASK: The trigger price will be based on the BID for buy orders and ASK for sell orders. 买卖盘:买入订单的触发价格将基于买盘,卖出订单的触发价格将基于卖盘。
- DOUBLE_LAST: The trigger price will be based on the last two consecutive LAST prices. 双最后价:触发价格将基于最后两个连续的最后价。
- DOUBLE_BID_ASK: The trigger price will be based on the last two consecutive BID or ASK prices as applicable. 双买卖盘:触发价格将基于最后两个连续的买盘或卖盘价格(如适用)。
- LAST_OR_BID_ASK: The trigger price will be based on the LAST or BID/ASK. 最后价或买卖盘:触发价格将基于最后价或买/卖盘。
- MID_POINT: The trigger price will be based on the mid-point between the BID and ASK. 中间价:触发价格将基于买盘和卖盘的中间价。
- MARK: The trigger price will be based on the exchanges mark price for the instrument. 标记价:触发价格将基于交易所对该Instrument的标记价格。
- INDEX: The trigger price will be based on the exchanges index price for the instrument. 指数价:触发价格将基于交易所对该Instrument的指数价格。
Applicable to conditional trailing-stop trigger orders, specifies the method of triggering modification of the stop price based on the offset from the 'market' (bid, ask or last price as applicable).
适用于条件追踪止损触发订单,指定根据与“市场”(买盘、卖盘或最后价格,如适用)的偏移量触发止损价格修改的方法。
- DEFAULT: The default offset type for the exchange (typically PRICE) 默认值:交易所的默认偏移类型(通常为 PRICE)
- PRICE: The offset is based on a price difference. 价格:偏移量基于价格差异。
- BASIS_POINTS: The offset is based on a price percentage difference expressed in basis points (100bp = 1%). 基点:偏移量基于以基点表示的价格百分比差异(100bp = 1%)。
- TICKS: The offset is based on a number of ticks. 跳动点:偏移量基于跳动点数。
- PRICE_TIER: The offset is based on an exchange specific price tier. 价格等级:偏移量基于特定于交易所的价格等级。
More advanced relationships can be specified between orders such as assigning child order(s) which will only trigger when the parent order is activated or filled, or linking orders together which will cancel or reduce in quantity contingent on each other. More documentation for these options can be found in the advanced order guide.
可以在订单之间指定更高级的关系,例如分配仅在父订单被激活或成交时才会触发的子订单,或者将订单链接在一起,这些订单将根据彼此的情况取消或减少数量。有关这些选项的更多文档,请参阅高级订单指南。
The easiest way to create new orders is by using the built-in
OrderFactory
, which is automatically attached to everyStrategy
class. This factory will take care of lower level details - such as ensuring the correct trader ID and strategy ID are assigned, generation of a necessary initialization ID and timestamp, and abstracts away parameters which don't necessarily apply to the order type being created, or are only needed to specify more advanced execution instructions.创建新订单的最简单方法是使用内置的
OrderFactory
,它会自动附加到每个Strategy
类。此工厂将处理较低级别的细节 - 例如确保分配了正确的交易者 ID 和策略 ID,生成必要的初始化 ID 和时间戳,并抽象出不一定适用于正在创建的订单类型的参数,或者只需要指定更高级的执行指令。
This leaves the factory with simpler order creation methods to work with, all the examples will leverage an
OrderFactory
from within aStrategy
context.这使得工厂可以使用更简单的订单创建方法,所有示例都将在
Strategy
上下文中利用OrderFactory
。
See the OrderFactory API Reference for further details.
有关更多详细信息,请参阅 OrderFactory API 参考。
The following describes the order types which are available for the platform with a code example. Any optional parameters will be clearly marked with a comment which includes the default value.
下面将通过代码示例描述平台可用的订单类型。任何可选参数都将用注释清楚地标记,注释中包含默认值。
A Market order is an instruction by the trader to immediately trade the given quantity at the best price available. You can also specify several time in force options, and indicate whether this order is only intended to reduce a position.
市价订单是交易者发出的指令,要求以可获得的最佳价格立即交易给定数量的商品。您还可以指定多个有效期选项,并指示此订单是否仅用于减少头寸。
In the following example we create a Market order on the Interactive Brokers IdealPro Forex ECN to BUY 100,000 AUD using USD:
在以下示例中,我们在 Interactive Brokers IdealPro 外汇 ECN 上创建了一个市价单,以使用 USD 购买 100,000 AUD:
from nautilus_trader.model.enums import OrderSide
from nautilus_trader.model.enums import TimeInForce
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.model.objects import Quantity
from nautilus_trader.model.orders import MarketOrder
order: MarketOrder = self.order_factory.market(
instrument_id=InstrumentId.from_str("AUD/USD.IDEALPRO"),
order_side=OrderSide.BUY,
quantity=Quantity.from_int(100_000),
time_in_force=TimeInForce.IOC, # <-- optional (default GTC) 可选(默认 GTC)
reduce_only=False, # <-- optional (default False) 可选(默认 False)
tags=["ENTRY"], # <-- optional (default None) 可选(默认 None)
)
See the MarketOrder API Reference for further details.
有关更多详细信息,请参阅 MarketOrder API 参考。
A Limit order is placed on the limit order book at a specific price, and will only execute at that price (or better).
限价单以特定价格放置在限价订单簿中,并且仅在该价格(或更好)执行。
In the following example we create a Limit order on the Binance Futures Crypto exchange to SELL 20 ETHUSDT-PERP Perpetual Futures contracts at a limit price of 5000 USDT, as a market maker.
在以下示例中,我们在 Binance Futures Crypto 交易所上创建了一个限价单,以 5000 USDT 的限价作为做市商卖出 20 个 ETHUSDT-PERP 永续期货合约。
from nautilus_trader.model.enums import OrderSide
from nautilus_trader.model.enums import TimeInForce
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.model.objects import Price
from nautilus_trader.model.objects import Quantity
from nautilus_trader.model.orders import LimitOrder
order: LimitOrder = self.order_factory.limit(
instrument_id=InstrumentId.from_str("ETHUSDT-PERP.BINANCE"),
order_side=OrderSide.SELL,
quantity=Quantity.from_int(20),
price=Price.from_str("5_000.00"),
time_in_force=TimeInForce.GTC, # <-- optional (default GTC) 可选(默认 GTC)
expire_time=None, # <-- optional (default None) 可选(默认 None)
post_only=True, # <-- optional (default False) 可选(默认 False)
reduce_only=False, # <-- optional (default False) 可选(默认 False)
display_qty=None, # <-- optional (default None which indicates full display) 可选(默认 None,表示完全显示)
tags=None, # <-- optional (default None) 可选(默认 None)
)
See the LimitOrder API Reference for further details.
有关更多详细信息,请参阅 LimitOrder API 参考。
A Stop-Market order is a conditional order which once triggered, will immediately place a Market order. This order type is often used as a stop-loss to limit losses, either as a SELL order against LONG positions, or as a BUY order against SHORT positions.
市价止损单是一种条件订单,一旦触发,将立即 placing a 市价单。这种订单类型通常用作止损单,以限制损失,可以是针对多头头寸的卖出订单,也可以是针对空头头寸的买入订单。
In the following example we create a Stop-Market order on the Binance Spot/Margin exchange to SELL 1 BTC at a trigger price of 100,000 USDT, active until further notice:
在以下示例中,我们在 Binance 现货/保证金交易所上创建了一个市价止损单,以在触发价为 100,000 USDT 时卖出 1 个 BTC,该订单一直有效,直到另行通知:
from nautilus_trader.model.enums import OrderSide
from nautilus_trader.model.enums import TimeInForce
from nautilus_trader.model.enums import TriggerType
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.model.objects import Price
from nautilus_trader.model.objects import Quantity
from nautilus_trader.model.orders import StopMarketOrder
order: StopMarketOrder = self.order_factory.stop_market(
instrument_id=InstrumentId.from_str("BTCUSDT.BINANCE"),
order_side=OrderSide.SELL,
quantity=Quantity.from_int(1),
trigger_price=Price.from_int(100_000),
trigger_type=TriggerType.LAST_TRADE, # <-- optional (default DEFAULT) 可选(默认 DEFAULT)
time_in_force=TimeInForce.GTC, # <-- optional (default GTC) 可选(默认 GTC)
expire_time=None, # <-- optional (default None) 可选(默认 None)
reduce_only=False, # <-- optional (default False) 可选(默认 False)
tags=None, # <-- optional (default None) 可选(默认 None)
)
See the StopMarketOrder API Reference for further details.
有关更多详细信息,请参阅 StopMarketOrder API 参考。
A Stop-Limit order is a conditional order which once triggered will immediately place a Limit order at the specified price.
限价止损单是一种条件订单,一旦触发,将立即以指定价格 placing a 限价单。
In the following example we create a Stop-Limit order on the Currenex FX ECN to BUY 50,000 GBP at a limit price of 1.3000 USD once the market hits the trigger price of 1.30010 USD, active until midday 6th June, 2022 (UTC):
在以下示例中,我们在 Currenex FX ECN 上创建了一个限价止损单,以便在市场触及 1.30010 美元的触发价后,以 1.3000 美元的限价购买 50,000 英镑,该订单一直有效到 2022 年 6 月 6 日中午(UTC):
import pandas as pd
from nautilus_trader.model.enums import OrderSide
from nautilus_trader.model.enums import TimeInForce
from nautilus_trader.model.enums import TriggerType
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.model.objects import Price
from nautilus_trader.model.objects import Quantity
from nautilus_trader.model.orders import StopLimitOrder
order: StopLimitOrder = self.order_factory.stop_limit(
instrument_id=InstrumentId.from_str("GBP/USD.CURRENEX"),
order_side=OrderSide.BUY,
quantity=Quantity.from_int(50_000),
price=Price.from_str("1.30000"),
trigger_price=Price.from_str("1.30010"),
trigger_type=TriggerType.BID, # <-- optional (default DEFAULT) 可选(默认 DEFAULT)
time_in_force=TimeInForce.GTD, # <-- optional (default GTC) 可选(默认 GTC)
expire_time=pd.Timestamp("2022-06-06T12:00"),
post_only=True, # <-- optional (default False) 可选(默认 False)
reduce_only=False, # <-- optional (default False) 可选(默认 False)
tags=None, # <-- optional (default None) 可选(默认 None)
)
See the StopLimitOrder API Reference for further details.
有关更多详细信息,请参阅 StopLimitOrder API 参考。
A Market-To-Limit order is submitted as a market order to execute at the current best market price. If the order is only partially filled, the remainder of the order is canceled and re-submitted as a Limit order with the limit price equal to the price at which the filled portion of the order executed.
市价转限价订单作为市价订单提交,以当前最佳市场价格执行。如果订单仅部分成交,则剩余订单将被取消,并重新提交为限价订单,限价等于订单已成交部分的执行价格。
In the following example we create a Market-To-Limit order on the Interactive Brokers IdealPro Forex ECN to BUY 200,000 USD using JPY:
在以下示例中,我们在 Interactive Brokers IdealPro 外汇 ECN 上创建了一个市价转限价单,以使用 JPY 购买 200,000 美元:
from nautilus_trader.model.enums import OrderSide
from nautilus_trader.model.enums import TimeInForce
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.model.objects import Quantity
from nautilus_trader.model.orders import MarketToLimitOrder
order: MarketToLimitOrder = self.order_factory.market_to_limit(
instrument_id=InstrumentId.from_str("USD/JPY.IDEALPRO"),
order_side=OrderSide.BUY,
quantity=Quantity.from_int(200_000),
time_in_force=TimeInForce.GTC, # <-- optional (default GTC) 可选(默认 GTC)
reduce_only=False, # <-- optional (default False) 可选(默认 False)
display_qty=None, # <-- optional (default None which indicates full display) 可选(默认 None,表示完全显示)
tags=None, # <-- optional (default None) 可选(默认 None)
)
See the MarketToLimitOrder API Reference for further details.
有关更多详细信息,请参阅 MarketToLimitOrder API 参考。
A Market-If-Touched order is a conditional order which once triggered will immediately place a Market order. This order type is often used to enter a new position on a stop price in the market orders direction, or to take profits for an existing position, either as a SELL order against LONG positions, or as a BUY order against SHORT positions.
触价市价单是一种条件订单,一旦触发,将立即 placing a 市价单。此订单类型通常用于在市价单方向上的止损价进入新头寸,或用于现有头寸获利,可以是针对多头头寸的卖出订单,也可以是针对空头头寸的买入订单。
In the following example we create a Market-If-Touched order on the Binance Futures exchange to SELL 10 ETHUSDT-PERP Perpetual Futures contracts at a trigger price of 10,000 USDT, active until further notice:
在以下示例中,我们在 Binance Futures 交易所上创建了一个触价市价单,以在触发价为 10,000 USDT 时卖出 10 个 ETHUSDT-PERP 永续期货合约,该订单一直有效,直到另行通知:
from nautilus_trader.model.enums import OrderSide
from nautilus_trader.model.enums import TimeInForce
from nautilus_trader.model.enums import TriggerType
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.model.objects import Price
from nautilus_trader.model.objects import Quantity
from nautilus_trader.model.orders import MarketIfTouchedOrder
order: MarketIfTouchedOrder = self.order_factory.market_if_touched(
instrument_id=InstrumentId.from_str("ETHUSDT-PERP.BINANCE"),
order_side=OrderSide.SELL,
quantity=Quantity.from_int(10),
trigger_price=Price.from_str("10_000.00"),
trigger_type=TriggerType.LAST_TRADE, # <-- optional (default DEFAULT) 可选(默认 DEFAULT)
time_in_force=TimeInForce.GTC, # <-- optional (default GTC) 可选(默认 GTC)
expire_time=None, # <-- optional (default None) 可选(默认 None)
reduce_only=False, # <-- optional (default False) 可选(默认 False)
tags=["ENTRY"], # <-- optional (default None) 可选(默认 None)
)
See the MarketIfTouchedOrder API Reference for further details.
有关更多详细信息,请参阅 MarketIfTouchedOrder API 参考。
A Limit-If-Touched order is a conditional order which once triggered will immediately place a Limit order at the specified price.
触价限价单是一种条件订单,一旦触发,将立即以指定价格 placing a 限价单。
In the following example we create a Stop-Limit order to BUY 5 BTCUSDT-PERP Perpetual Futures contracts on the Binance Futures exchange at a limit price of 30,100 USDT (once the market hits the trigger price of 30,150 USDT), active until midday 6th June, 2022 (UTC):
在以下示例中,我们在 Binance Futures 交易所上创建了一个限价止损单,以便在市场触及 30,150 USDT 的触发价后,以 30,100 USDT 的限价购买 5 个 BTCUSDT-PERP 永续期货合约,该订单一直有效到 2022 年 6 月 6 日中午(UTC):
import pandas as pd
from nautilus_trader.model.enums import OrderSide
from nautilus_trader.model.enums import TimeInForce
from nautilus_trader.model.enums import TriggerType
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.model.objects import Price
from nautilus_trader.model.objects import Quantity
from nautilus_trader.model.orders import StopLimitOrder
order: StopLimitOrder = self.order_factory.limit_if_touched(
instrument_id=InstrumentId.from_str("BTCUSDT-PERP.BINANCE"),
order_side=OrderSide.BUY,
quantity=Quantity.from_int(5),
price=Price.from_str("30_100"),
trigger_price=Price.from_str("30_150"),
trigger_type=TriggerType.LAST_TRADE, # <-- optional (default DEFAULT) 可选(默认 DEFAULT)
time_in_force=TimeInForce.GTD, # <-- optional (default GTC) 可选(默认 GTC)
expire_time=pd.Timestamp("2022-06-06T12:00"),
post_only=True, # <-- optional (default False) 可选(默认 False)
reduce_only=False, # <-- optional (default False) 可选(默认 False)
tags=["TAKE_PROFIT"], # <-- optional (default None) 可选(默认 None)
)
See the StopLimitOrder API Reference for further details.
有关更多详细信息,请参阅 StopLimitOrder API 参考。
A Trailing-Stop-Market order is a conditional order which trails a stop trigger price a fixed offset away from the defined market price. Once triggered a Market order will immediately be placed.
追踪止损市价单是一种条件订单,它会追踪止损触发价,该触发价与定义的市场价格相差一个固定的偏移量。一旦触发,将立即 placing a 市价单。
In the following example we create a Trailing-Stop-Market order on the Binance Futures exchange to SELL 10 ETHUSD-PERP COIN_M margined Perpetual Futures Contracts activating at a trigger price of 5,000 USD, then trailing at an offset of 1% (in basis points) away from the current last traded price:
在以下示例中,我们在 Binance Futures 交易所上创建了一个追踪止损市价单,以在触发价为 5,000 美元时卖出 10 个 ETHUSD-PERP COIN_M 保证金永续期货合约,然后以距离当前最后交易价格 1%(以基点为单位)的偏移量进行追踪:
import pandas as pd
from decimal import Decimal
from nautilus_trader.model.enums import OrderSide
from nautilus_trader.model.enums import TimeInForce
from nautilus_trader.model.enums import TriggerType
from nautilus_trader.model.enums import TrailingOffsetType
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.model.objects import Price
from nautilus_trader.model.objects import Quantity
from nautilus_trader.model.orders import TrailingStopMarketOrder
order: TrailingStopMarketOrder = self.order_factory.trailing_stop_market(
instrument_id=InstrumentId.from_str("ETHUSD-PERP.BINANCE"),
order_side=OrderSide.SELL,
quantity=Quantity.from_int(10),
trigger_price=Price.from_str("5_000"),
trigger_type=TriggerType.LAST_TRADE, # <-- optional (default DEFAULT) 可选(默认 DEFAULT)
trailing_offset=Decimal(100),
trailing_offset_type=TrailingOffsetType.BASIS_POINTS,
time_in_force=TimeInForce.GTC, # <-- optional (default GTC) 可选(默认 GTC)
expire_time=None, # <-- optional (default None) 可选(默认 None)
reduce_only=True, # <-- optional (default False) 可选(默认 False)
tags=["TRAILING_STOP-1"], # <-- optional (default None) 可选(默认 None)
)
See the TrailingStopMarketOrder API Reference for further details.
有关更多详细信息,请参阅 TrailingStopMarketOrder API 参考。
A Trailing-Stop-Limit order is a conditional order which trails a stop trigger price a fixed offset away from the defined market price. Once triggered a Limit order will immediately be placed at the defined price (which is also updated as the market moves until triggered).
追踪止损限价单是一种条件订单,它会追踪止损触发价,该触发价与定义的市场价格相差一个固定的偏移量。一旦触发,将立即以定义的价格 placing a 限价单(该价格也会随着市场的波动而更新,直到触发)。
In the following example we create a Trailing-Stop-Limit order on the Currenex FX ECN to BUY 1,250,000 AUD using USD at a limit price of 0.71000 USD, activating at 0.72000 USD then trailing at a stop offset of 0.00100 USD away from the current ask price, active until further notice:
在以下示例中,我们在 Currenex FX ECN 上创建了一个追踪止损限价单,以 0.71000 美元的限价使用美元购买 1,250,000 澳元,在 0.72000 美元时激活,然后以距离当前卖价 0.00100 美元的止损偏移量进行追踪,该订单一直有效,直到另行通知:
import pandas as pd
from decimal import Decimal
from nautilus_trader.model.enums import OrderSide
from nautilus_trader.model.enums import TimeInForce
from nautilus_trader.model.enums import TriggerType
from nautilus_trader.model.enums import TrailingOffsetType
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.model.objects import Price
from nautilus_trader.model.objects import Quantity
from nautilus_trader.model.orders import TrailingStopLimitOrder
order: TrailingStopLimitOrder = self.order_factory.trailing_stop_limit(
instrument_id=InstrumentId.from_str("AUD/USD.CURRENEX"),
order_side=OrderSide.BUY,
quantity=Quantity.from_int(1_250_000),
price=Price.from_str("0.71000"),
trigger_price=Price.from_str("0.72000"),
trigger_type=TriggerType.BID_ASK, # <-- optional (default DEFAULT) 可选(默认 DEFAULT)
limit_offset=Decimal("0.00050"),
trailing_offset=Decimal("0.00100"),
trailing_offset_type=TrailingOffsetType.PRICE,
time_in_force=TimeInForce.GTC, # <-- optional (default GTC) 可选(默认 GTC)
expire_time=None, # <-- optional (default None) 可选(默认 None)
reduce_only=True, # <-- optional (default False) 可选(默认 False)
tags=["TRAILING_STOP"], # <-- optional (default None) 可选(默认 None)
)
See the TrailingStopLimitOrder API Reference for further details.
有关更多详细信息,请参阅 TrailingStopLimitOrder API 参考。