Crypto API Reference¶
CryptoClient¶
pyhood.crypto.client.CryptoClient
¶
Robinhood Crypto Trading API v2 client.
Handles ED25519 authentication, rate limiting, and pagination.
Usage
client = CryptoClient(api_key, private_key_base64) account = client.get_account() quote = client.get_best_bid_ask("BTC-USD")
__init__(api_key=None, private_key_base64=None, timeout=30.0)
¶
Initialize crypto client with API credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
Robinhood Crypto API key. If omitted, resolved from the RH_CRYPTO_API_KEY environment variable or ~/.pyhood/crypto.env. |
None
|
private_key_base64
|
str | None
|
Base64-encoded ED25519 private key. Resolved the same way when omitted. |
None
|
timeout
|
float
|
Request timeout in seconds |
30.0
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If credentials cannot be resolved. |
make_request(method, path, body='', params=None, retries=3)
¶
Make an authenticated request to the Crypto API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
HTTP method (GET, POST, etc.) |
required |
path
|
str
|
API path (e.g., '/api/v2/crypto/trading/accounts/') |
required |
body
|
str
|
Request body as JSON string |
''
|
params
|
dict[str, Any] | None
|
Query parameters |
None
|
retries
|
int
|
Number of retries on rate limit/server errors |
3
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed JSON response |
Raises:
| Type | Description |
|---|---|
RateLimitError
|
Rate limited and no retries left |
AuthError
|
Authentication failed |
APIError
|
API returned an error |
get_account()
¶
Get crypto trading account information.
Returns:
| Type | Description |
|---|---|
CryptoAccount
|
CryptoAccount with account details |
get_trading_pairs(*symbols)
¶
Get trading pair information for crypto symbols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*symbols
|
str
|
Crypto symbols (e.g., 'BTC-USD', 'ETH-USD') |
()
|
Returns:
| Type | Description |
|---|---|
list[TradingPair]
|
List of TradingPair objects |
get_best_bid_ask(*symbols)
¶
Get best bid/ask prices for crypto symbols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*symbols
|
str
|
Crypto symbols (e.g., 'BTC-USD', 'ETH-USD') |
()
|
Returns:
| Type | Description |
|---|---|
list[CryptoQuote]
|
List of CryptoQuote objects |
get_estimated_price(symbol, side, quantity)
¶
Get estimated price for a crypto trade.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Crypto symbol (e.g., 'BTC-USD') |
required |
side
|
str
|
'buy' or 'sell' |
required |
quantity
|
float
|
Trade quantity |
required |
Returns:
| Type | Description |
|---|---|
EstimatedPrice
|
EstimatedPrice object |
get_historicals(symbol, interval='hour', span='week')
¶
Deprecated — the Crypto Trading API has no historicals endpoint.
Raises:
| Type | Description |
|---|---|
APIError
|
Always. |
Verified 2026-08-09: every candidate path returns 404
(marketdata/historicals/, marketdata/candles/,
trading/historicals/, on both /api/v1/ and /api/v2/), and the
endpoint is absent from Robinhood's published OpenAPI spec.
For crypto price history, use the unofficial endpoints via
PyhoodClient rather than the official Crypto Trading API.
get_holdings(account_number, *asset_codes)
¶
Get crypto holdings for account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_number
|
str
|
Crypto account number |
required |
*asset_codes
|
str
|
Asset codes to filter by (e.g., 'BTC', 'ETH') |
()
|
Returns:
| Type | Description |
|---|---|
list[CryptoHolding]
|
List of CryptoHolding objects |
place_order(account_number, side, order_type, symbol, order_config, client_order_id=None)
¶
Place a crypto order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_number
|
str
|
Crypto account number |
required |
side
|
str
|
'buy' or 'sell' |
required |
order_type
|
str
|
'market', 'limit', 'stop_loss' or 'stop_limit' |
required |
symbol
|
str
|
Crypto symbol (e.g., 'BTC-USD') |
required |
order_config
|
dict[str, Any]
|
Configuration for this order type, e.g.
|
required |
client_order_id
|
str | None
|
Idempotency key. Generated if omitted — resending the same value returns the original order rather than placing a second one. |
None
|
Returns:
| Type | Description |
|---|---|
CryptoOrder
|
CryptoOrder object |
Note
Only pairs with api_tradable set can be ordered through this API;
a pair can be tradable in the app but not here.
get_order(account_number, order_id)
¶
Get a specific crypto order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_number
|
str
|
Crypto account number |
required |
order_id
|
str
|
Order ID |
required |
Returns:
| Type | Description |
|---|---|
CryptoOrder
|
CryptoOrder object |
get_orders(account_number)
¶
Get all crypto orders for account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_number
|
str
|
Crypto account number |
required |
Returns:
| Type | Description |
|---|---|
list[CryptoOrder]
|
List of CryptoOrder objects |
cancel_order(order_id)
¶
Cancel a crypto order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_id
|
str
|
Order ID to cancel |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
API response data |
Authentication¶
pyhood.crypto.auth.generate_keypair()
¶
Generate an ED25519 keypair for crypto API authentication.
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
Tuple of (private_key_base64, public_key_base64) |
pyhood.crypto.auth.sign_request(api_key, private_key_base64, method, path, body='')
¶
Sign a Crypto API request using ED25519.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
Robinhood Crypto API key |
required |
private_key_base64
|
str
|
Base64-encoded private key |
required |
method
|
str
|
HTTP method (GET, POST, etc.) |
required |
path
|
str
|
URL path (e.g., '/api/v2/crypto/trading/accounts/') |
required |
body
|
str
|
Request body JSON string (empty for GET requests) |
''
|
Returns:
| Type | Description |
|---|---|
tuple[str, str, str]
|
Tuple of (api_key_header, signature_header, timestamp_header) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If private key is invalid |
Models¶
pyhood.crypto.models
¶
Crypto data models — typed dataclasses for Robinhood Crypto API responses.
CryptoQuote
dataclass
¶
Crypto quote data with best bid/ask.
CryptoHolding
dataclass
¶
Crypto asset holding information.
CryptoAccount
dataclass
¶
Crypto trading account information.
Fee information arrives as a fee_tier_status object rather than a tier
name, so fee_tier is rendered from fee_ratio — e.g. '0.95%'.
TradingPair
dataclass
¶
Trading pair configuration and limits.
tradable reflects Robinhood's status; api_tradable reflects
is_api_tradable, which is the one that governs API orders. A pair can be
tradable in the app but not through the API.
EstimatedPrice
dataclass
¶
Estimated price for a crypto trade.
CryptoCandle
dataclass
¶
Single OHLCV price candle for a crypto asset.
CryptoOrder
dataclass
¶
Crypto order information.