Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# self.submit_order

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
      >>> asset = Asset(
      >>>    "ES",
      >>>    asset_type="future",
      >>>    expiration_date="2020-01-01",
      >>>    multiplier=100)
      >>> order = self.create_order(asset, 100, "buy")
      >>> self.submit_order(order)

      >>> # For selling a future
      >>> asset = Asset(
      >>>    "ES",
      >>>    asset_type="future",
      >>>    expiration_date="2020-01-01"
      >>>    multiplier=100)
      >>> order = self.create_order(asset, 100, "sell")
      >>> self.submit_order(order)

      >>> # For buying an option
      >>> asset = Asset(
      >>>    "SPY",
      >>>    asset_type="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
      >>> asset = Asset(
      >>>    "SPY",
      >>>    asset_type="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
      >>> base_asset = Asset(
          symbol="GBP,
          asset_type="forex",
      )
      >>> quote_asset = Asset(
          symbol="USD",
          asset_type="forex",
      )
      >>> order = self.create_order(asset, 10, "buy", quote=quote_asset)
      >>> self.submit_order(order)

      >>> # For selling FOREX
      >>> base_asset = Asset(
          symbol="EUR",
          asset_type="forex",
      )
      >>> quote_asset = Asset(
          symbol="USD",
          asset_type="forex",
      )
      >>> order = self.create_order(asset, 10, "sell", quote=quote_asset)
      >>> self.submit_order(order)

      >>> # For buying an option with a limit price
      >>> asset = Asset(
      >>>    "SPY",
      >>>    asset_type="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
      >>> asset = Asset(
      >>>    "SPY",
      >>>    asset_type="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
      >>> asset = Asset(
      >>>    "SPY",
      >>>    asset_type="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
      >>> asset_base = Asset(
      >>>    "BTC",
      >>>    asset_type="crypto",
      >>> )
      >>> asset_quote = Asset(
      >>>    "USD",
      >>>    asset_type="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
      >>> asset_base = Asset(
      >>>    "BTC",
      >>>    asset_type="crypto",
      >>> )
      >>> asset_quote = Asset(
      >>>    "USD",
      >>>    asset_type="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
      >>> asset_base = Asset(
      >>>    "BTC",
      >>>    asset_type="crypto",
      >>> )
      >>> asset_quote = Asset(
      >>>    "USD",
      >>>    asset_type="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)