|
7 | 7 | import pytest |
8 | 8 |
|
9 | 9 | from alpaca.broker.client import BrokerClient |
10 | | -from alpaca.broker.enums import AccountEntities |
| 10 | +from alpaca.broker.enums import AccountEntities, AccountSubType, AccountType |
11 | 11 | from alpaca.broker.models import Account, Contact, Identity, TradeAccount |
12 | 12 | from alpaca.broker.requests import ( |
13 | 13 | CreateAccountRequest, |
@@ -123,9 +123,125 @@ def test_create_account(reqmock, client: BrokerClient): |
123 | 123 | returned_account = client.create_account(create_data) |
124 | 124 |
|
125 | 125 | assert reqmock.called_once |
| 126 | + request_body = reqmock.request_history[0].json() |
| 127 | + assert "account_type" not in request_body |
| 128 | + assert "account_sub_type" not in request_body |
126 | 129 | assert type(returned_account) == Account |
127 | 130 | assert returned_account.id == UUID(created_id) |
128 | 131 | assert returned_account.kyc_results is None |
| 132 | + assert returned_account.account_type == AccountType.TRADING |
| 133 | + assert returned_account.account_sub_type is None |
| 134 | + |
| 135 | + |
| 136 | +def test_create_ira_account(reqmock, client: BrokerClient): |
| 137 | + created_id = "0d969814-40d6-4b2b-99ac-2e37427f1ad2" |
| 138 | + |
| 139 | + reqmock.post( |
| 140 | + "https://broker-api.sandbox.alpaca.markets/v1/accounts", |
| 141 | + text=""" |
| 142 | + { |
| 143 | + "id": "0d969814-40d6-4b2b-99ac-2e37427f1ad2", |
| 144 | + "account_number": "682389557", |
| 145 | + "status": "SUBMITTED", |
| 146 | + "crypto_status": "INACTIVE", |
| 147 | + "currency": "USD", |
| 148 | + "last_equity": "0", |
| 149 | + "created_at": "2022-04-12T17:24:31.30283Z", |
| 150 | + "contact": { |
| 151 | + "email_address": "cool_alpaca@example.com", |
| 152 | + "phone_number": "555-666-7788", |
| 153 | + "street_address": [ |
| 154 | + "20 N San Mateo Dr" |
| 155 | + ], |
| 156 | + "unit": "Apt 1A", |
| 157 | + "city": "San Mateo", |
| 158 | + "state": "CA", |
| 159 | + "postal_code": "94401" |
| 160 | + }, |
| 161 | + "identity": { |
| 162 | + "given_name": "John", |
| 163 | + "family_name": "Doe", |
| 164 | + "middle_name": "Smith", |
| 165 | + "date_of_birth": "1990-01-01", |
| 166 | + "tax_id_type": "USA_SSN", |
| 167 | + "country_of_citizenship": "USA", |
| 168 | + "country_of_birth": "USA", |
| 169 | + "country_of_tax_residence": "USA", |
| 170 | + "funding_source": [ |
| 171 | + "employment_income" |
| 172 | + ], |
| 173 | + "visa_type": null, |
| 174 | + "visa_expiration_date": null, |
| 175 | + "date_of_departure_from_usa": null, |
| 176 | + "permanent_resident": null |
| 177 | + }, |
| 178 | + "disclosures": { |
| 179 | + "is_control_person": false, |
| 180 | + "is_affiliated_exchange_or_finra": false, |
| 181 | + "is_politically_exposed": false, |
| 182 | + "immediate_family_exposed": false, |
| 183 | + "is_discretionary": false |
| 184 | + }, |
| 185 | + "agreements": [ |
| 186 | + { |
| 187 | + "agreement": "margin_agreement", |
| 188 | + "signed_at": "2020-09-11T18:09:33Z", |
| 189 | + "ip_address": "185.13.21.99", |
| 190 | + "revision": "16.2021.05" |
| 191 | + }, |
| 192 | + { |
| 193 | + "agreement": "account_agreement", |
| 194 | + "signed_at": "2020-09-11T18:13:44Z", |
| 195 | + "ip_address": "185.13.21.99", |
| 196 | + "revision": "16.2021.05" |
| 197 | + }, |
| 198 | + { |
| 199 | + "agreement": "customer_agreement", |
| 200 | + "signed_at": "2020-09-11T18:13:44Z", |
| 201 | + "ip_address": "185.13.21.99", |
| 202 | + "revision": "16.2021.05" |
| 203 | + }, |
| 204 | + { |
| 205 | + "agreement": "crypto_agreement", |
| 206 | + "signed_at": "2020-09-11T18:13:44Z", |
| 207 | + "ip_address": "185.13.21.99", |
| 208 | + "revision": "04.2021.10" |
| 209 | + } |
| 210 | + ], |
| 211 | + "trusted_contact": { |
| 212 | + "given_name": "Jane", |
| 213 | + "family_name": "Doe", |
| 214 | + "email_address": "jane.doe@example.com" |
| 215 | + }, |
| 216 | + "account_type": "ira", |
| 217 | + "account_sub_type": "traditional", |
| 218 | + "trading_configurations": null |
| 219 | + } |
| 220 | + """, |
| 221 | + ) |
| 222 | + |
| 223 | + create_data = CreateAccountRequest( |
| 224 | + account_type=AccountType.IRA, |
| 225 | + account_sub_type=AccountSubType.TRADITIONAL, |
| 226 | + agreements=factory.create_dummy_agreements(), |
| 227 | + contact=factory.create_dummy_contact(), |
| 228 | + disclosures=factory.create_dummy_disclosures(), |
| 229 | + documents=factory.create_dummy_account_documents(), |
| 230 | + identity=factory.create_dummy_identity(), |
| 231 | + trusted_contact=factory.create_dummy_trusted_contact(), |
| 232 | + ) |
| 233 | + |
| 234 | + returned_account = client.create_account(create_data) |
| 235 | + |
| 236 | + assert reqmock.called_once |
| 237 | + request_body = reqmock.request_history[0].json() |
| 238 | + assert request_body["account_type"] == "ira" |
| 239 | + assert request_body["account_sub_type"] == "traditional" |
| 240 | + assert type(returned_account) == Account |
| 241 | + assert returned_account.id == UUID(created_id) |
| 242 | + assert returned_account.kyc_results is None |
| 243 | + assert returned_account.account_type == AccountType.IRA |
| 244 | + assert returned_account.account_sub_type == AccountSubType.TRADITIONAL |
129 | 245 |
|
130 | 246 |
|
131 | 247 | def test_create_lct_account(reqmock, client: BrokerClient): |
@@ -231,10 +347,15 @@ def test_create_lct_account(reqmock, client: BrokerClient): |
231 | 347 | returned_account = client.create_account(create_data) |
232 | 348 |
|
233 | 349 | assert reqmock.called_once |
| 350 | + request_body = reqmock.request_history[0].json() |
| 351 | + assert "account_type" not in request_body |
| 352 | + assert "account_sub_type" not in request_body |
234 | 353 | assert type(returned_account) == Account |
235 | 354 | assert returned_account.id == UUID(created_id) |
236 | 355 | assert returned_account.currency == currency |
237 | 356 | assert returned_account.kyc_results is None |
| 357 | + assert returned_account.account_type == "trading" |
| 358 | + assert returned_account.account_sub_type is None |
238 | 359 |
|
239 | 360 |
|
240 | 361 | def test_get_account(reqmock, client: BrokerClient): |
|
0 commit comments