Skip to content

Commit

Permalink
feat: rename options fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hiohiohio committed Feb 20, 2024
1 parent 481331a commit d1eb7a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
14 changes: 8 additions & 6 deletions alpaca/trading/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,10 @@ class TradeAccount(ModelWithID):
sma (Optional[str]): Value of Special Memorandum Account (will be used at a later date to provide additional buying_power)
daytrade_count (Optional[int]): The current number of daytrades that have been made in the last 5 trading days
(inclusive of today)
option_approved_level (Optional[int]): The option trading level that was approved for this account.
options_buying_power (Optional[str]): Your buying power for options trading
options_approved_level (Optional[int]): The options trading level that was approved for this account.
0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long Call/Put.
option_trading_level (Optional[int]): The effective option trading level of the account. This is the minimum between account option_approved_level and account configurations max_option_trading_level.
options_trading_level (Optional[int]): The effective options trading level of the account. This is the minimum between account options_approved_level and account configurations max_options_trading_level.
0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long
"""

Expand Down Expand Up @@ -529,8 +530,9 @@ class TradeAccount(ModelWithID):
last_maintenance_margin: Optional[str] = None
sma: Optional[str] = None
daytrade_count: Optional[int] = None
option_approved_level: Optional[int] = None
option_trading_level: Optional[int] = None
options_buying_power: Optional[str] = None
options_approved_level: Optional[int] = None
options_trading_level: Optional[int] = None


class AccountConfiguration(BaseModel):
Expand All @@ -546,7 +548,7 @@ class AccountConfiguration(BaseModel):
suspend_trade (bool): If true Account becomes unable to submit new orders
trade_confirm_email (TradeConfirmationEmail): Controls whether Trade confirmation emails are sent.
ptp_no_exception_entry (bool): If set to true then Alpaca will accept orders for PTP symbols with no exception. Default is false.
max_option_trading_level (Optional[str]): The desired maximum option trading level. 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long Call/Put.
max_options_trading_level (Optional[str]): The desired maximum options trading level. 0=disabled, 1=Covered Call/Cash-Secured Put, 2=Long Call/Put.
"""

dtbp_check: DTBPCheck
Expand All @@ -557,7 +559,7 @@ class AccountConfiguration(BaseModel):
suspend_trade: bool
trade_confirm_email: TradeConfirmationEmail
ptp_no_exception_entry: bool
max_option_trading_level: Optional[str] = None
max_options_trading_level: Optional[str] = None


class CorporateActionAnnouncement(ModelWithID):
Expand Down
9 changes: 5 additions & 4 deletions examples/options-trading-basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@
"outputs": [],
"source": [
"# check trading account\n",
"# There are two new columns in the account object:\n",
"# - option_approved_level\n",
"# - option_trading_level\n",
"# There are trhee new columns in the account object:\n",
"# - options_buying_power\n",
"# - options_approved_level\n",
"# - options_trading_level\n",
"acct = trade_client.get_account()\n",
"acct"
]
Expand All @@ -147,7 +148,7 @@
"outputs": [],
"source": [
"# check account configuration\n",
"# - we have new field `max_option_trading_level`\n",
"# - we have new field `max_options_trading_level`\n",
"acct_config = trade_client.get_account_configurations()\n",
"acct_config"
]
Expand Down
14 changes: 8 additions & 6 deletions tests/trading/trading_client/test_account_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def test_get_account(reqmock: Mocker, trading_client: TradingClient):
"trade_suspended_by_user": false,
"trading_blocked": false,
"transfers_blocked": false,
"option_approved_level": "1",
"option_trading_level": "1"
"options_buying_power": "262113.632",
"options_approved_level": "1",
"options_trading_level": "1"
}
""",
)
Expand All @@ -48,8 +49,9 @@ def test_get_account(reqmock: Mocker, trading_client: TradingClient):

assert reqmock.called_once
assert isinstance(account, TradeAccount)
assert account.option_approved_level == 1
assert account.option_trading_level == 1
assert account.options_buying_power == "262113.632"
assert account.options_approved_level == 1
assert account.options_trading_level == 1


def test_get_account_configurations(reqmock: Mocker, trading_client: TradingClient):
Expand All @@ -65,15 +67,15 @@ def test_get_account_configurations(reqmock: Mocker, trading_client: TradingClie
"pdt_check": "entry",
"trade_confirm_email": "all",
"ptp_no_exception_entry": false,
"max_option_trading_level": "1"
"max_options_trading_level": "1"
}
""",
)

account_configurations = trading_client.get_account_configurations()
assert reqmock.called_once
assert isinstance(account_configurations, AccountConfiguration)
assert account_configurations.max_option_trading_level == "1"
assert account_configurations.max_options_trading_level == "1"


def test_set_account_configurations(reqmock: Mocker, trading_client: TradingClient):
Expand Down

0 comments on commit d1eb7a9

Please sign in to comment.