[docs]@dataclass(frozen=True)classAccountDetails:"""Represents account details and balances Attributes: account_number: Account number trade_platform: Trading platform this account is traded on margin_type: Margin type restriction: Restriction level effective on the account daytrades_count: Day trades counter account_value_total: Total account liquidation value cash: Account debit balance when negative, credit balance when positive day_trading_buying_power: Day trading buying power for marginable securities margin_buying_power: Buying power for marginable securities non_margin_buying_power: Buying power for non-marginable securities position_market_value: Sum of all positions current market values. The value is negative for short positions unsettled_cash: Unsettled cash for cash accounts cash_to_withdraw: Cash available to withdraw from the account restriction_reason: Optional description explaining why the account is restricted """account_number:strtrade_platform:strmargin_type:MarginTyperestriction:RestrictionLeveldaytrades_count:intaccount_value_total:Decimalcash:Decimalday_trading_buying_power:Decimalmargin_buying_power:Decimalnon_margin_buying_power:Decimalposition_market_value:Decimalunsettled_cash:Decimalcash_to_withdraw:Decimalrestriction_reason:str|None=None
[docs]@dataclass(frozen=True)classLeg:"""Represents leg in the multi-leg strategy Attributes: symbol: The leg security symbol quantity: Signed number of shares or option contracts for the leg average_open_price: The leg cost basis current_price: The leg current price security_type: The leg asset type """symbol:straverage_open_price:Decimalcurrent_price:Decimalquantity:intsecurity_type:SecurityType
[docs]@dataclass(frozen=True)classAccountPosition:"""Represents single account position Attributes: symbol: Security symbol quantity: Signed number of shares or option contracts. Negative for short positions average_open_price: Average historical cost basis current_price: Current price security_type: Asset type legs: Legs of the multi-leg strategy """symbol:strquantity:intaverage_open_price:Decimalcurrent_price:Decimalsecurity_type:SecurityTypelegs:list[Leg]|None=None
[docs]@dataclass(frozen=True)classAccountPositions:"""List of account positions Attributes: account: Account number positions: Account positions """account:strpositions:list[AccountPosition]
[docs]@dataclass(frozen=True)classAccountTrade:"""Represents single account trade Attributes: symbol: Security symbol timestamp: Timestamp of the trade quantity: Number of shares or option contracts, negative for sells, positive for buys price: Trade price amount: Trade amount, which is the quantity multiplied by the lot size and price side: Trade side trade_id: The trade id """symbol:strtimestamp:datetimequantity:intprice:Decimalamount:Decimalside:TradeSidetrade_id:str
[docs]@dataclass(frozen=True)classAccountTradesPage:"""Page of account trades Attributes: trades: List of trades in page count: Total count of trades """trades:list[AccountTrade]count:int
[docs]@dataclass(frozen=True)classRoute:"""Route available for account Attributes: exchange: Route name to use when placing order time_in_force: List of order duration instructions supported by a route order_type: List of order types supported by a route """exchange:strtime_in_force:list[TimeInForce]order_type:list[OrderType]
[docs]@dataclass(frozen=True)classTransactionCash:"""Describes the cash side of the transaction Attributes: gross_amount: Dollar amount not including fees, can be positive or negative net_amount: Net dollar amount including fees charged for the transaction, can be positive or negative """gross_amount:Decimalnet_amount:Decimal
[docs]@dataclass(frozen=True)classTransactionAsset:"""Describes the asset side of the transaction Attributes: symbol: Asset symbol symbol_description: Company name for stocks or human-readable name for options quantity: Transaction quantity, can be positive or negative price: Price for each unit """symbol:strsymbol_description:strquantity:intprice:Decimal
[docs]@dataclass(frozen=True)classTransactionFee:"""Represents transaction fee Attributes: name: Name of the fee. amount: Fee amount """name:stramount:Decimal
[docs]@dataclass(frozen=True)classAccountTransaction:"""Single account transaction Attributes: id: Internal transaction id, globally unique, and it is not necessarily sequentially incremented type: Transaction type description: Human-readable transaction description date: Date of transaction cash: Describes the cash side of the transaction fees: List of fees charged by the transaction asset: Structure describing the asset side of the transaction """id:strtype:strdescription:strdate:datecash:TransactionCashfees:list[TransactionFee]asset:TransactionAsset|None=None
[docs]@dataclass(frozen=True)classAccountTransactionsPage:"""Page of account transactions Attributes: transactions: List of transactions in page count: Total count of transactions """transactions:list[AccountTransaction]count:int
[docs]@dataclass(frozen=True)classToken:"""Represents access token Attributes: scope: The scopes this token grants access to token_type: Bearer means that access token should be put to the Authorization header of every web request access_token: Access token expires_in: Expiration lifetime in seconds date_created: Date when token was created. Used to determine expiry date """scope:strtoken_type:straccess_token:strexpires_in:intdate_created:datetime=field(default_factory=partial(datetime.now,tz=timezone.utc))
[docs]defexpiry_date(self,tz:timezone=timezone.utc)->datetime:""" Returns expiry date in a specific timezone Args: tz: Timezone in which to return expiry date. Default is UTC Returns: Datetime when token expires """returnself.date_created.astimezone(tz)+timedelta(seconds=self.expires_in)
[docs]defexpires_in_delta(self)->timedelta:""" Gets difference between expiry date and current date Returns: Difference between expiry date and current date """returnself.expiry_date()-datetime.now(tz=timezone.utc)
[docs]@dataclass(frozen=True)classCredentials:"""Credentials used for API authentication Attributes: username: Username password: Password client_id: Client id issued to the service client_secret: Client secret issued to the service grant_type: OAuth authorization flow to use """username:strpassword:strclient_id:strclient_secret:strgrant_type:str
[docs]@dataclass(frozen=True)classAccountFeedAction:"""Action that is sent to account feed websocket Attributes: action: Type of action account: Account number """action:AccountFeedActionTypeaccount:str
[docs]@dataclass(frozen=True)classAccountFeedError:"""Error during streaming account data Attributes: t: Type of account feed, always "e" code: Error code description: Error description """t:AccountFeedTypecode:strdescription:str