self.submit_order#

lumibot.strategies.strategy.Strategy.submit_order(self, order)#

Submit an order for an asset

Submits an order object for processing by the active broker.

Parameters:

order (Order object) – Order object containing the asset and instructions for executing the order.

Returns:

Processed order object.

Return type:

Order object

Example

>>> # For a market buy order
>>> order = self.create_order("SPY", 100, "buy")
>>> self.submit_order(order)
>>> # For a limit buy order
>>> order = self.create_order("SPY", 100, "buy", limit_price=100.00)
>>> self.submit_order(order)
>>> # For a stop loss order
>>> order = self.create_order("SPY", 100, "buy", stop_price=100.00)
>>> self.submit_order(order)
>>> # For a stop limit order
>>> order = self.create_order("SPY", 100, "buy", limit_price=100.00, stop_price=100.00)
>>> self.submit_order(order)
>>> # For a market sell order
>>> order = self.create_order("SPY", 100, "sell")
>>> self.submit_order(order)
>>> # For a limit sell order
>>> order = self.create_order("SPY", 100, "sell", limit_price=100.00)
>>> self.submit_order(order)
>>> # For buying a future
>>> from lumibot.entities import Asset
>>>
>>> asset = Asset(
>>>    "ES",
>>>    asset_type=Asset.AssetType.FUTURE,
>>>    expiration_date="2020-01-01",
>>>    multiplier=100)
>>> order = self.create_order(asset, 100, "buy")
>>> self.submit_order(order)
>>> # For selling a future
>>> from lumibot.entities import Asset
>>>
>>> asset = Asset(
>>>    "ES",
>>>    asset_type=Asset.AssetType.FUTURE,
>>>    expiration_date="2020-01-01"
>>>    multiplier=100)
>>> order = self.create_order(asset, 100, "sell")
>>> self.submit_order(order)
>>> # For buying an option
>>> from lumibot.entities import Asset
>>>
>>> asset = Asset(
>>>    "SPY",
>>>    asset_type=Asset.AssetType.OPTION,
>>>    expiration_date="2020-01-01",
>>>    strike_price=100.00,
>>>    right="call")
>>> order = self.create_order(asset, 10, "buy")
>>> self.submit_order(order)
>>> # For selling an option
>>> from lumibot.entities import Asset
>>>
>>> asset = Asset(
>>>    "SPY",
>>>    asset_type=Asset.AssetType.OPTION,
>>>    expiration_date="2020-01-01",
>>>    strike_price=100.00,
>>>    right="call")
>>> order = self.create_order(asset, 10, "sell")
>>> self.submit_order(order)
>>> # For buying a stock
>>> asset = Asset("SPY")
>>> order = self.create_order(asset, 10, "buy")
>>> self.submit_order(order)
>>> # For selling a stock
>>> asset = Asset("SPY")
>>> order = self.create_order(asset, 10, "sell")
>>> self.submit_order(order)
>>> # For buying a stock with a limit price
>>> asset = Asset("SPY")
>>> order = self.create_order(asset, 10, "buy", limit_price=100.00)
>>> self.submit_order(order)
>>> # For selling a stock with a limit price
>>> asset = Asset("SPY")
>>> order = self.create_order(asset, 10, "sell", limit_price=100.00)
>>> self.submit_order(order)
>>> # For buying a stock with a stop price
>>> asset = Asset("SPY")
>>> order = self.create_order(asset, 10, "buy", stop_price=100.00)
>>> self.submit_order(order)
>>> # For buying FOREX
>>> from lumibot.entities import Asset
>>>
>>> base_asset = Asset(
    symbol="GBP,
    asset_type=Asset.AssetType.FOREX,
)
>>> quote_asset = Asset(
    symbol="USD",
    asset_type=Asset.AssetType.FOREX,
)
>>> order = self.create_order(asset, 10, "buy", quote=quote_asset)
>>> self.submit_order(order)
>>> # For selling FOREX
>>> from lumibot.entities import Asset
>>>
>>> base_asset = Asset(
    symbol="EUR",
    asset_type=Asset.AssetType.FOREX,
)
>>> quote_asset = Asset(
    symbol="USD",
    asset_type=Asset.AssetType.FOREX,
)
>>> order = self.create_order(asset, 10, "sell", quote=quote_asset)
>>> self.submit_order(order)
>>> # For buying an option with a limit price
>>> from lumibot.entities import Asset
>>>
>>> asset = Asset(
>>>    "SPY",
>>>    asset_type=Aset.AssetType.OPTION,
>>>    expiration_date="2020-01-01",
>>>    strike_price=100.00,
>>>    right="call")
>>> order = self.create_order(asset, 10, "buy", limit_price=100.00)
>>> self.submit_order(order)
>>> # For selling an option with a limit price
>>> from lumibot.entities import Asset
>>>
>>> asset = Asset(
>>>    "SPY",
>>>    asset_type=Asset.AssetType.OPTION,
>>>    expiration_date="2020-01-01",
>>>    strike_price=100.00,
>>>    right="call")
>>> order = self.create_order(asset, 10, "sell", limit_price=100.00)
>>> self.submit_order(order)
>>> # For buying an option with a stop price
>>> from lumibot.entities import Asset
>>>
>>> asset = Asset(
>>>    "SPY",
>>>    asset_type=Asset.AssetType.OPTION,
>>>    expiration_date="2020-01-01",
>>>    strike_price=100.00,
>>>    right="call")
>>> order = self.create_order(asset, 10, "buy", stop_price=100.00)
>>> # For selling a stock with a stop price
>>> asset = Asset("SPY")
>>> order = self.create_order(asset, 10, "sell", stop_price=100.00)
>>> self.submit_order(order)
>>> # For buying a stock with a trailing stop price
>>> asset = Asset("SPY")
>>> order = self.create_order(asset, 10, "buy", trailing_stop_price=100.00)
>>> self.submit_order(order)
>>> # For selling a stock with a trailing stop price
>>> asset = Asset("SPY")
>>> order = self.create_order(asset, 10, "sell", trailing_stop_price=100.00)
>>> self.submit_order(order)
>>> # For buying a crypto with a market price
>>> from lumibot.entities import Asset
>>>
>>> asset_base = Asset(
>>>    "BTC",
>>>    asset_type=Asset.AssetType.CRYPTO,
>>> )
>>> asset_quote = Asset(
>>>    "USD",
>>>    asset_type=Asset.AssetType.CRYPTO,
>>> )
>>> order = self.create_order(asset_base, 0.1, "buy", quote=asset_quote)
>>> or...
>>> order = self.create_order((asset_base, asset_quote), 0.1, "buy")
>>> self.submit_order(order)
>>> # For buying a crypto with a limit price
>>> from lumibot.entities import Asset
>>>
>>> asset_base = Asset(
>>>    "BTC",
>>>    asset_type=Asset.AssetType.CRYPTO,
>>> )
>>> asset_quote = Asset(
>>>    "USD",
>>>    asset_type=Asset.AssetType.CRYPTO,
>>> )
>>> order = self.create_order(asset_base, 0.1, "buy", limit_price="41250", quote=asset_quote)
>>> or...
>>> order = self.create_order((asset_base, asset_quote), 0.1, "buy", limit_price="41250")
>>> self.submit_order(order)
>>> # For buying a crypto with a stop limit price
>>> from lumibot.entities import Asset
>>>
>>> asset_base = Asset(
>>>    "BTC",
>>>    asset_type=Asset.AssetType.CRYPTO,
>>> )
>>> asset_quote = Asset(
>>>    "USD",
>>>    asset_type=Asset.AssetType.CRYPTO,
>>> )
>>> order = self.create_order(asset_base, 0.1, "buy", limit_price="41325", stop_price="41300", quote=asset_quote)
>>> or...
>>> order = self.create_order((asset_base, asset_quote), 0.1, "buy", limit_price="41325", stop_price="41300",)
>>> self.submit_order(order)
>>> # For an OCO order
>>> order = self.create_order(
>>>                "SPY",
>>>                100,
>>>                "sell",
>>>                take_profit_price=limit,
>>>                stop_loss_price=stop_loss,
>>>                type="oco",
>>>            )
>>> self.submit_order(order)