maicoin.v3¶
REST v3 client for the MaiCoin MAX API.
Client¶
Client
¶
Client(
api_key=None,
api_secret=None,
*,
base_url=BASE_URL,
timeout=DEFAULT_TIMEOUT,
session=None,
nonce_factory=generate_nonce,
retry_policy=None,
)
Async-first REST v3 client for the MaiCoin MAX exchange.
Construct without credentials for public endpoints, or pass api_key and
api_secret to call authenticated (signed) endpoints.
Examples:
Public-only client:
>>> from maicoin.v3 import Client
>>> async with Client() as client:
... await client.ticker("btctwd")
Authenticated client:
Build a REST v3 client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
MAX API access key. Required for authenticated endpoints. |
None
|
api_secret
|
str | None
|
MAX API secret used to sign authenticated requests. |
None
|
base_url
|
str
|
API base URL. Override for staging or test environments. |
BASE_URL
|
timeout
|
float
|
Per-request timeout in seconds. |
DEFAULT_TIMEOUT
|
session
|
RequestSession | None
|
Custom HTTP session implementing |
None
|
nonce_factory
|
Callable[[], int]
|
Callable returning a strictly increasing integer nonce in milliseconds. Override in tests. |
generate_nonce
|
retry_policy
|
RetryPolicy | None
|
Retry/backoff policy for transient failures. Pass
|
None
|
Source code in src/maicoin/v3/client.py
session
property
writable
¶
Underlying async HTTP session, created lazily for default clients.
aclose
async
¶
Close the underlying async HTTP session when it supports closing.
Source code in src/maicoin/v3/client.py
request_sync
¶
Synchronous convenience wrapper.
markets_sync
¶
currencies_sync
¶
timestamp_sync
¶
kline_sync
¶
Synchronous convenience wrapper.
depth_sync
¶
Synchronous convenience wrapper.
trades_sync
¶
Synchronous convenience wrapper.
tickers_sync
¶
ticker_sync
¶
info_sync
¶
accounts_sync
¶
Synchronous convenience wrapper.
wallet_trades_sync
¶
wallet_trades_sync(
*,
wallet_type="spot",
market=None,
timestamp=None,
from_id=None,
order=None,
limit=None,
)
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
open_orders_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
closed_orders_sync
¶
closed_orders_sync(
*,
wallet_type="spot",
market=None,
timestamp=None,
order_by=None,
limit=None,
)
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
order_history_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
order_sync
¶
create_order_sync
¶
create_order_sync(
market,
side,
volume,
*,
wallet_type="spot",
price=None,
client_oid=None,
stop_price=None,
ord_type=None,
group_id=None,
)
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
cancel_order_sync
¶
Synchronous convenience wrapper.
cancel_orders_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
order_trades_sync
¶
Synchronous convenience wrapper.
withdrawal_sync
¶
create_withdrawal_sync
¶
Synchronous convenience wrapper.
create_twd_withdrawal_sync
¶
withdrawals_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
withdraw_addresses_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
deposit_sync
¶
deposits_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
deposit_address_sync
¶
internal_transfers_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
rewards_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
fund_transaction_deposits_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
fund_transaction_deposit_sync
¶
fund_transaction_withdrawals_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
fund_transaction_withdrawal_sync
¶
fund_transaction_transfers_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
fund_transaction_transfer_sync
¶
create_convert_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
convert_sync
¶
converts_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
m_wallet_index_prices_sync
¶
m_wallet_historical_index_prices_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
m_wallet_limits_sync
¶
m_wallet_interest_rates_sync
¶
create_m_wallet_loan_sync
¶
m_wallet_loans_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
create_m_wallet_transfer_sync
¶
Synchronous convenience wrapper.
m_wallet_transfers_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
create_m_wallet_repayment_sync
¶
Synchronous convenience wrapper.
m_wallet_repayments_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
m_wallet_liquidations_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
m_wallet_liquidation_sync
¶
m_wallet_interests_sync
¶
Synchronous convenience wrapper.
Source code in src/maicoin/v3/client.py
m_wallet_ad_ratio_sync
¶
request
async
¶
Send a raw REST v3 request and return the parsed JSON payload.
Use this escape hatch when you need an endpoint that the typed wrappers below don't cover. Auth headers, nonce injection, and error handling work the same way as for the typed methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
HTTP method, case-insensitive (e.g. |
required |
path
|
str
|
Request path. Leading |
required |
params
|
Mapping[str, object] | None
|
Query parameters (GET) or JSON body (other methods).
Use |
None
|
auth
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
object
|
The parsed JSON response, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
MaxHTTPError
|
Non-2xx HTTP response. |
MaxAPIError
|
MAX-shaped error payload ( |
Source code in src/maicoin/v3/client.py
markets
async
¶
currencies
async
¶
List all supported currencies, including network info (GET /api/v3/currencies).
timestamp
async
¶
kline
async
¶
Fetch OHLCV candles for market (GET /api/v3/k).
Source code in src/maicoin/v3/client.py
depth
async
¶
Fetch the order book depth for market (GET /api/v3/depth).
Source code in src/maicoin/v3/client.py
trades
async
¶
Fetch recent public trades for market (GET /api/v3/trades).
Source code in src/maicoin/v3/client.py
tickers
async
¶
Fetch tickers for several markets in one request (GET /api/v3/tickers).
ticker
async
¶
info
async
¶
accounts
async
¶
wallet_trades
async
¶
wallet_trades(
*,
wallet_type="spot",
market=None,
timestamp=None,
from_id=None,
order=None,
limit=None,
)
List the authenticated user's trades for a wallet.
Source code in src/maicoin/v3/client.py
open_orders
async
¶
List the user's open orders.
Source code in src/maicoin/v3/client.py
closed_orders
async
¶
List the user's closed (filled or cancelled) orders.
Source code in src/maicoin/v3/client.py
order_history
async
¶
Page through the full order history for a market.
Source code in src/maicoin/v3/client.py
iter_wallet_trades
async
¶
iter_wallet_trades(
*,
wallet_type="spot",
market=None,
timestamp=None,
from_id=None,
order="asc",
page_limit=100,
max_items=None,
max_pages=None,
)
Iterate wallet trades using the from_id cursor.
Source code in src/maicoin/v3/client.py
iter_order_history
async
¶
iter_order_history(
market,
*,
wallet_type="spot",
from_id=None,
page_limit=100,
max_items=None,
max_pages=None,
)
Iterate order history using the from_id cursor.
Source code in src/maicoin/v3/client.py
order
async
¶
Fetch a single order by order_id or client_oid.
create_order
async
¶
create_order(
market,
side,
volume,
*,
wallet_type="spot",
price=None,
client_oid=None,
stop_price=None,
ord_type=None,
group_id=None,
)
Place a new order.
Source code in src/maicoin/v3/client.py
cancel_order
async
¶
Cancel an order by order_id or client_oid.
cancel_orders
async
¶
Bulk-cancel orders. Filters compose: omit them all to cancel everything in the wallet.
Source code in src/maicoin/v3/client.py
order_trades
async
¶
List the executed trades for one order.
withdrawal
async
¶
create_withdrawal
async
¶
Submit a crypto withdrawal to a pre-approved address.
Source code in src/maicoin/v3/client.py
create_twd_withdrawal
async
¶
withdrawals
async
¶
List withdrawal history.
Source code in src/maicoin/v3/client.py
withdraw_addresses
async
¶
List the user's whitelisted withdrawal addresses for currency.
Source code in src/maicoin/v3/client.py
deposit
async
¶
deposits
async
¶
List deposit history.
Source code in src/maicoin/v3/client.py
deposit_address
async
¶
Get the deposit address for a specific currency/network version.
internal_transfers
async
¶
List internal transfers between MAX users.
Source code in src/maicoin/v3/client.py
rewards
async
¶
List reward history (referrals, mining, staking, etc.).
Source code in src/maicoin/v3/client.py
fund_transaction_deposits
async
¶
List fund-transaction deposits (off-exchange settlement).
Source code in src/maicoin/v3/client.py
fund_transaction_deposit
async
¶
fund_transaction_withdrawals
async
¶
List fund-transaction withdrawals.
Source code in src/maicoin/v3/client.py
fund_transaction_withdrawal
async
¶
fund_transaction_transfers
async
¶
List fund-transaction transfers.
Source code in src/maicoin/v3/client.py
fund_transaction_transfer
async
¶
create_convert
async
¶
Submit a convert order between two currencies.
Source code in src/maicoin/v3/client.py
convert
async
¶
converts
async
¶
List convert order history.
Source code in src/maicoin/v3/client.py
m_wallet_index_prices
async
¶
m_wallet_historical_index_prices
async
¶
Fetch historical M-Wallet index prices for market.
Source code in src/maicoin/v3/client.py
m_wallet_limits
async
¶
m_wallet_interest_rates
async
¶
create_m_wallet_loan
async
¶
Borrow amount of currency into the M-Wallet.
m_wallet_loans
async
¶
List M-Wallet loans for currency.
Source code in src/maicoin/v3/client.py
create_m_wallet_transfer
async
¶
Transfer between spot and M-Wallet.
m_wallet_transfers
async
¶
List M-Wallet transfer history.
Source code in src/maicoin/v3/client.py
create_m_wallet_repayment
async
¶
m_wallet_repayments
async
¶
List M-Wallet repayment history for currency.
Source code in src/maicoin/v3/client.py
m_wallet_liquidations
async
¶
List M-Wallet liquidation events.
Source code in src/maicoin/v3/client.py
m_wallet_liquidation
async
¶
Look up a single M-Wallet liquidation, including order/repayment details.
m_wallet_interests
async
¶
List M-Wallet interest accruals.
Source code in src/maicoin/v3/client.py
m_wallet_ad_ratio
async
¶
Return the M-Wallet account debt ratio (asset-to-debt and margin level).
RequestSession
¶
Bases: Protocol
Minimal HTTP session protocol used by Client.
Anything with a request(method, url, **kwargs) -> Response shape works,
so you can swap in httpx.AsyncClient, a mocked session for tests, or a custom
async transport.
Constants¶
Errors¶
MaxAPIError
¶
Bases: Exception
Raised when MAX returns a structured {"error": ...} payload.
Attributes:
| Name | Type | Description |
|---|---|---|
status_code |
HTTP status code, when known. |
|
payload |
Raw response body that triggered the error, useful for
inspecting MAX's |
Source code in src/maicoin/v3/errors.py
MaxHTTPError
¶
Bases: MaxAPIError
Raised for non-2xx HTTP responses without a recognized MAX error body.
Behaves like MaxAPIError — catch it as a
subclass when you want to distinguish HTTP-level failures (network,
rate-limit, gateway) from API-level failures.
Source code in src/maicoin/v3/errors.py
Auth helpers¶
build_auth_headers
¶
Build the full set of MAX authentication headers for a request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
MAX API access key. |
required |
api_secret
|
str
|
MAX API secret. |
required |
path
|
str
|
Request path beginning with |
required |
params
|
Mapping[str, object] | None
|
Request parameters that will be sent (must match the payload actually transmitted, otherwise the signature is rejected). |
None
|
nonce
|
int | None
|
Optional millisecond nonce. Generated when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A dict containing |
dict[str, str]
|
|
Source code in src/maicoin/v3/auth.py
encode_payload
¶
Build the base64-encoded payload that goes in the X-MAX-PAYLOAD header.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Request path beginning with |
required |
params
|
Mapping[str, object] | None
|
Request parameters merged into the payload (typically the query string for GET requests, or the JSON body for POST/DELETE). |
None
|
nonce
|
int | None
|
Millisecond nonce. Generated via |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Base64-encoded JSON ready to assign to |
Source code in src/maicoin/v3/auth.py
generate_nonce
¶
Return the current UTC time as a millisecond UNIX nonce.
MAX rejects any nonce that is not strictly greater than the previous one
used by the key, so reusing this helper across processes that share an API
key can race. Pass a custom nonce_factory to Client
if you need monotonic generation.
Source code in src/maicoin/v3/auth.py
sign_payload
¶
Return the HMAC-SHA256 hex digest of payload keyed with api_secret.
The result is what MAX expects in the X-MAX-SIGNATURE header.
Source code in src/maicoin/v3/auth.py
Models¶
Account
¶
Bases: MaxBaseModel
ConvertOrder
¶
Bases: MaxBaseModel
Currency
¶
Bases: MaxBaseModel
CurrencyNetwork
¶
Bases: MaxBaseModel
Deposit
¶
Bases: MaxBaseModel
DepositAddress
¶
Bases: MaxBaseModel
Depth
¶
FundTransactionDeposit
¶
Bases: MaxBaseModel
from_
class-attribute
instance-attribute
¶
FundTransactionSource
¶
Bases: MaxBaseModel
FundTransactionTransfer
¶
Bases: MaxBaseModel
from_
class-attribute
instance-attribute
¶
FundTransactionWithdrawal
¶
Bases: MaxBaseModel
HistoricalIndexPrice
¶
Bases: MaxBaseModel
InterestRate
¶
Bases: MaxBaseModel
InternalTransfer
¶
Bases: MaxBaseModel
from_
class-attribute
instance-attribute
¶
KLine
¶
MWalletADRatio
¶
Bases: MaxBaseModel
MWalletForcedLiquidation
¶
MWalletInterest
¶
MWalletLiquidation
¶
MWalletLiquidationDetail
¶
Bases: MWalletLiquidation
MWalletLiquidationRepayment
¶
MWalletLoan
¶
MWalletRepayment
¶
MWalletTransfer
¶
Market
¶
Bases: MaxBaseModel
Order
¶
Bases: MaxBaseModel
OrderSide
¶
OrderState
¶
OrderType
¶
Bases: StrEnum
PrivateTrade
¶
Bases: MaxBaseModel
self_trade_bid_fee_discounted
class-attribute
instance-attribute
¶
PublicTrade
¶
Reward
¶
Staking
¶
Bases: MaxBaseModel
Ticker
¶
Bases: MaxBaseModel
Timestamp
¶
Bases: MaxBaseModel
UserInfo
¶
VipLevel
¶
WithdrawAddress
¶
Bases: MaxBaseModel
Withdrawal
¶
Bases: MaxBaseModel