Today, I was exploring the features of the Alpaca broker and delving into the Alpaca Py SDK and found an example of creating a new account. I’ve just changed a bit the original example and tried to send a request through BrokerClient() with active sandox=True, the server responds to me every time with 500 status code, original details are: “code”: 50010000 and “message”: “internal server error occurred”
These are the headers used in the request:
{‘Date’: ‘Tue, 17 Oct 2023 18:52:39 GMT’, ‘Content-Type’: ‘application/json; charset=UTF-8’, ‘Content-Length’: ‘60’, ‘Connection’: ‘keep-alive’, ‘Access-Control-Allow-Origin’: ‘*’, ‘Vary’: ‘Origin’, ‘X-Ratelimit-Limit’: ‘1000’, ‘X-Ratelimit-Remaining’: ‘999’, ‘X-Ratelimit-Reset’: ‘1697568759’, ‘X-Request-Id’: ‘82077de6730adb1ea6a847f65ce5f0e5’, ‘Strict-Transport-Security’: ‘max-age=31536000; includeSubDomains’, ‘Access-Control-Allow-Credentials’: ‘true’, ‘Access-Control-Allow-Methods’: ‘GET, OPTIONS, PUT, DELETE, POST, PATCH’, ‘Access-Control-Allow-Headers’: ‘Apca-Api-Key-Id, Apca-Api-Secret-Key, Authorization’, ‘Access-Control-Max-Age’: ‘1728000’}
Here is my code:
broker_client = BrokerClient(
api_key=ALPACA_TOKEN,
secret_key=ALPACA_SECRET_KEY,
sandbox=True
)
def create_alpaca_account(broker_client: BrokerClient):
# Contact
contact_data = Contact(
email_address="example@gmail.com",
phone_number=“+000000000000”,
street_address=,
city=“Dubai”,
state=“Dubai”,
postal_code=“11800”,
country=“UAE”
)
# Identity
identity_data = Identity(
given_name=“John”,
middle_name=“Smith”,
family_name=“Doe”,
date_of_birth=“1993-01-01”,
tax_id=“000000000”,
tax_id_type=TaxIdType.NOT_SPECIFIED,
country_of_citizenship=“UAE”,
country_of_birth=“UAE”,
country_of_tax_residence=“UAE”,
funding_source=[FundingSource.EMPLOYMENT_INCOME]
)
# Disclosures
disclosure_data = Disclosures(
is_control_person=False,
is_affiliated_exchange_or_finra=False,
is_politically_exposed=False,
immediate_family_exposed=False,
)
# Agreements
agreement_data = [
Agreement(
agreement=AgreementType.ACCOUNT,
signed_at="2023-09-11T18:13:44Z",
ip_address="185.13.21.99",
revision=None
),
Agreement(
agreement=AgreementType.CUSTOMER,
signed_at="2023-09-11T18:13:44Z",
ip_address="185.13.21.99",
revision=None
),
]
# ## CreateAccountRequest ## #
account_data = CreateAccountRequest(
contact=contact_data,
identity=identity_data,
disclosures=disclosure_data,
agreements=agreement_data,
enabled_assets=["us_equity"]
)
# Make a request to create a new brokerage account
account = broker_client.create_account(account_data)
print(account)