infrastructure.providers.alpaca.api.accounts_api¶
src.infrastructure.providers.alpaca.api.accounts_api
¶
Alpaca Accounts API client.
HTTP client for Alpaca Trading API account and positions endpoints. Uses API Key authentication headers.
Endpoints
GET /v2/account - Get account information GET /v2/positions - Get all open positions
Reference
- https://docs.alpaca.markets/docs/trading-api
- https://docs.alpaca.markets/reference/getaccount-1
Attributes¶
Classes¶
AlpacaAccountsAPI
¶
Bases: BaseProviderAPIClient
HTTP client for Alpaca Trading API account and positions endpoints.
Extends BaseProviderAPIClient with Alpaca API Key authentication. Returns raw JSON responses - mapping to domain types is done by mappers.
Thread-safe: Uses httpx.AsyncClient per-request (no shared state).
Example
api = AlpacaAccountsAPI( ... base_url="https://paper-api.alpaca.markets", ... timeout=30.0, ... ) result = await api.get_account(api_key="...", api_secret="...")
Source code in src/infrastructure/providers/alpaca/api/accounts_api.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
Functions¶
__init__
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Alpaca Trading API base URL. |
required |
timeout
|
float
|
HTTP request timeout in seconds. |
PROVIDER_TIMEOUT_DEFAULT
|
Source code in src/infrastructure/providers/alpaca/api/accounts_api.py
get_account
async
¶
Fetch account information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
Alpaca API Key ID. |
required |
api_secret
|
str
|
Alpaca API Secret Key. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Success |
dict
|
Account JSON object from Alpaca. |
Failure |
ProviderAuthenticationError
|
If credentials are invalid. |
Failure |
ProviderUnavailableError
|
If Alpaca API is unreachable. |
Source code in src/infrastructure/providers/alpaca/api/accounts_api.py
get_positions
async
¶
Fetch all open positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
Alpaca API Key ID. |
required |
api_secret
|
str
|
Alpaca API Secret Key. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Success |
list[dict]
|
List of position JSON objects. |
Failure |
ProviderAuthenticationError
|
If credentials are invalid. |
Failure |
ProviderUnavailableError
|
If Alpaca API is unreachable. |