asynctradier.clients.trading_client module

class asynctradier.clients.trading_client.TradingClient(session: WebUtil, account_id: str, token: str, sandbox: bool = False)[source]

Bases: object

A client for trading operations.

Parameters:
  • session (WebUtil) – The session object for making HTTP requests.

  • account_id (str) – The account ID associated with the client.

  • token (str) – The authentication token for accessing the trading API.

  • sandbox (bool, optional) – Whether to use the sandbox environment. Defaults to False.

async buy_option(symbol: str, expiration_date: str, strike: float | int, option_type: OptionType, quantity: int, order_type: OrderType = OrderType.market, order_duration: Duration = Duration.day, tag: str | None = None, price: float | None = None, stop: float | None = None) Order[source]

Place a buy option order.

Parameters:
  • symbol (str) – The symbol of the option.

  • expiration_date (str) – The expiration date of the option (YYYY-MM-DD).

  • strike (float | int) – The strike price of the option.

  • option_type (OptionType) – The type of the option (call or put).

  • quantity (int) – The quantity of the option contracts to buy.

  • order_type (OrderType, optional) – The type of the order. Defaults to OrderType.market.

  • order_duration (Duration, optional) – The duration of the order. Defaults to Duration.day.

  • tag (str, optional) – An optional tag for the order. Defaults to None.

  • price (float, optional) – The price at which to place the order. Required for limit orders. Defaults to None.

  • stop (float, optional) – The stop price for the order. Required for stop orders. Defaults to None.

Returns:

The Order object.

Return type:

Order

async buy_stock(symbol: str, quantity: int, order_type: OrderType = OrderType.market, order_duration: Duration = Duration.day, tag: str | None = None, price: float | None = None, stop: float | None = None)[source]

Place a buy stock order.

Parameters:
  • symbol (str) – The symbol of the stock.

  • quantity (int) – The quantity of the stock to buy.

  • order_type (OrderType, optional) – The type of the order. Defaults to OrderType.market.

  • order_duration (Duration, optional) – The duration of the order. Defaults to Duration.day.

  • tag (str, optional) – An optional tag for the order. Defaults to None.

  • price (float, optional) – The price at which to place the order. Required for limit orders. Defaults to None.

  • stop (float, optional) – The stop price for the order. Required for stop orders. Defaults to None.

Returns:

The Order object.

Return type:

Order

async cancel_order(order_id: str | int) Order[source]

Cancel an order by its ID.

Parameters:

order_id (str | int) – The ID of the order.

Returns:

The Order object.

Return type:

Order

async combo(symbol: str, order_type: OrderType, duration: Duration, order_sides: List[OptionContract], price: float | None = None) Order[source]

Executes a combo order.

Parameters:
  • symbol (str) – The symbol of the order.

  • order_type (OrderType) – The type of the order.

  • duration (Duration) – The duration of the order.

  • order_sides (List[OptionContract]) – The list of option contracts for the combo order.

  • price (Optional[float]) – The price of the order (required for debit and credit orders).

Returns:

The executed order.

Return type:

Order

Raises:
async modify_order(order_id: str | int, order_type: OrderType | None = None, order_duration: Duration | None = None, price: float | None = None, stop: float | None = None) Order[source]

Modify an order by its ID.

Parameters:
  • order_id (str | int) – The ID of the order.

  • order_type (OrderType, optional) – The new type of the order. Defaults to None.

  • order_duration (Duration, optional) – The new duration of the order. Defaults to None.

  • price (float, optional) – The new price for the order. Defaults to None.

  • stop (float, optional) – The new stop price for the order. Defaults to None.

Returns:

The Order object.

Return type:

Order

async multileg(symbol: str, order_type: OrderType, duration: Duration, legs: List[OptionContract], price: float | None = None) Order[source]

Executes a multileg order.

Parameters:
  • symbol (str) – The symbol of the order.

  • order_type (OrderType) – The type of the order.

  • duration (Duration) – The duration of the order.

  • legs (List[OptionContract]) – The list of option contracts for the multileg order.

  • price (Optional[float]) – The price of the order (required for spread orders).

Returns:

The executed order.

Return type:

Order

Raises:

MissingRequiredParameter – If price is not specified for spread orders.

async sell_option(symbol: str, expiration_date: str, strike: float | int, option_type: OptionType, quantity: int, order_type: OrderType = OrderType.market, order_duration: Duration = Duration.day, tag: str | None = None, price: float | None = None, stop: float | None = None) Order[source]

Place a sell option order.

Parameters:
  • symbol (str) – The symbol of the option.

  • expiration_date (str) – The expiration date of the option (YYYY-MM-DD).

  • strike (float | int) – The strike price of the option.

  • option_type (OptionType) – The type of the option (call or put).

  • quantity (int) – The quantity of the option contracts to sell.

  • order_type (OrderType, optional) – The type of the order. Defaults to OrderType.market.

  • order_duration (Duration, optional) – The duration of the order. Defaults to Duration.day.

  • tag (str, optional) – An optional tag for the order. Defaults to None.

  • price (float, optional) – The price at which to place the order. Required for limit orders. Defaults to None.

  • stop (float, optional) – The stop price for the order. Required for stop orders. Defaults to None.

Returns:

The Order object.

Return type:

Order

async sell_stock(symbol: str, quantity: int, order_type: OrderType = OrderType.market, order_duration: Duration = Duration.day, tag: str | None = None, price: float | None = None, stop: float | None = None)[source]

Sell a stock with the specified parameters.

Parameters:
  • symbol (str) – The symbol of the stock to sell.

  • quantity (int) – The quantity of shares to sell.

  • order_type (OrderType, optional) – The type of order to place. Defaults to OrderType.market.

  • order_duration (Duration, optional) – The duration of the order. Defaults to Duration.day.

  • tag (str, optional) – An optional tag for the order. Defaults to None.

  • price (float, optional) – The price at which to sell the stock. Defaults to None.

  • stop (float, optional) – The stop price for a stop order. Defaults to None.

Returns:

The result of the stock operation.