API clients¶
-
exception
crix.client.
APIError
(operation, code, text)[source]¶ General exception for API calls
-
static
async_ensure
(operation, req)[source]¶ Ensure status code of HTTP request and raise exception if needed (asyncio version)
Parameters: - operation (
str
) – logical operation name - req (
ClientResponse
) – request’s response object
- operation (
-
code
= None¶ HTTP response code
-
static
ensure
(operation, req)[source]¶ Ensure status code of HTTP request and raise exception if needed
Parameters: - operation (
str
) – logical operation name - req (
Response
) – request’s response object
- operation (
-
operation
= None¶ operation name
-
text
= None¶ error description
-
static
-
class
crix.client.
AuthorizedClient
(token, secret, *, env='mvp', cache_market=True)[source]¶ HTTP client to the exchange for non-authorized and authorized requests.
Supported environments:
- ‘mvp’ - testnet sandbox with full-wipe each 2nd week (usually)
- ‘prod’ - mainnet, production environment with real currency
Expects API token and API secret provided by CRIX.IO exchange as part of bot API.
-
cancel_order
(order_id, symbol)[source]¶ Cancel placed order
Parameters: - order_id (
int
) – order id generated by the exchange - symbol (
str
) – symbol names same as in placed order
Return type: Returns: order definition with filled field (also includes filled quantity)
- order_id (
-
create_order
(new_order)[source]¶ Create and place order to the exchange
Parameters: new_order ( NewOrder
) – order parametersReturn type: Order
Returns: order definition with filled fields from the exchange
-
fetch_balance
()[source]¶ Get all balances for the user
Return type: List
[Account
]Returns: list of all accounts
-
fetch_closed_orders
(*symbols, limit=1000)[source]¶ Get complete (filled, canceled) orders for user
Note
One request per each symbol will be made plus additional request to query all supported symbols if symbols parameter not specified.
Parameters: - symbols (
str
) – filter orders by symbols. if not specified - all symbols queried and used - limit (
int
) – maximum number of orders for each symbol
Return type: Iterator
[Order
]Returns: iterator of orders definitions
- symbols (
-
fetch_history
(begin, end, currency)[source]¶ Get historical minute tickers for specified time range and currency There are several caveats:
- it requires additional permission
- end param should be not more then server time, otherwise error returned
- maximum difference between earliest and latest date should be no more then 366 days
- it could be slow for a long time range
- mostly all points have 1 minute tick however in a very few cases gap can be a bit bigger
Parameters: - begin (
datetime
) – earliest interesting time - end (
datetime
) – latest interesting time - currency (
str
) – currency name in upper case
Return type: Iterator
[Ticker
]Returns: iterator of parsed tickers
-
fetch_my_trades
(*symbols, limit=1000)[source]¶ Get all trades for the user. There is some gap (a few ms) between time when trade is actually created and time when it becomes visible for the user.
Note
One request per each symbol will be made plus additional request to query all supported symbols if symbols parameter not specified.
Parameters: - symbols (
str
) – filter trades by symbols. if not specified - used all symbols - limit (
int
) – maximum number of trades for each symbol
Return type: Iterator
[Trade
]Returns: iterator of trade definition
- symbols (
-
fetch_open_orders
(*symbols, limit=1000)[source]¶ Get all open orders for the user.
Note
One request per each symbol will be made plus additional request to query all supported symbols if symbols parameter not specified.
Parameters: - symbols (
str
) – filter orders by symbols. if not specified - all symbols queried and used - limit (
int
) – maximum number of orders for each symbol
Return type: Iterator
[Order
]Returns: iterator of orders definitions
- symbols (
-
fetch_order
(order_id, symbol_name)[source]¶ Fetch single open order info
Parameters: - order_id (
int
) – order id generated by server during ‘create_order’ phase - symbol_name (
str
) – symbol name same as in order
Return type: Optional
[Order
]Returns: order definition or None if nothing found
- order_id (
-
fetch_orders
(*symbols, limit=1000)[source]¶ Get opened and closed orders filtered by symbols. If no symbols specified - all symbols are used. Basically the function acts as union of fetch_open_orders and fetch_closed_orders.
Note
Two requests per each symbol will be made plus additional request to query all supported symbols if symbols parameter not specified.
Parameters: - symbols (
str
) – symbols: filter orders by symbols. if not specified - used all symbols - limit (
int
) – maximum number of orders for each symbol for each state (open, close)
Return type: Iterator
[Order
]Returns: iterator of orders definitions sorted from open to close
- symbols (
-
class
crix.client.
Client
(*, env='mvp', cache_market=True)[source]¶ HTTP client to the exchange for non-authorized requests.
Supported environments:
- ‘mvp’ - testnet sandbox with full-wipe each 2nd week (usually)
- ‘prod’ - mainnet, production environment with real currency
Disable cache_market if latest symbols info are always required
-
fetch_currency_codes
()[source]¶ Get list of currencies codes in quote_base format (ex. btc_bch)
Return type: List
[str
]Returns: list of formatted currencies codes
-
fetch_markets
(force=False)[source]¶ Get list of all symbols on the exchange. Also includes symbol details like precision, quote, base and e.t.c. It’s a good idea to cache result of this function after first invoke
Parameters: force ( bool
) – don’t use cached symbolsReturn type: Tuple
[Symbol
]Returns: list of supported symbols
-
fetch_ohlcv
(symbol, utc_start_time, utc_end_time, resolution=<Resolution.one_minute: '1'>, limit=10)[source]¶ Get K-Lines for specific symbol in a time frame.
Latest OHLCV ticks representing interval up to current minute (ex: now: 10:15:32, then latest OHLCV with minute resolution will be from 10:14:00 to 10:15:00).
Parameters: - symbol (
str
) – K-Line symbol name - utc_start_time (
datetime
) – earliest interesting time - utc_end_time (
datetime
) – latest interesting time - resolution (
Resolution
) – K-line resolution (by default 1-minute) - limit (
int
) – maximum number of entries in a response
Return type: List
[Ticker
]Returns: list of ticker
- symbol (
-
fetch_order_book
(symbol, level_aggregation=None)[source]¶ Get order book for specific symbol and level aggregation
import os import crix client = crix.AuthorizedClient(token=os.getenv('TOKEN'), secret=os.getenv('SECRET'), env='mvp') # get all symbols symbols = client.fetch_markets() for symbol in symbols: # get order book for symbol order_book = client.fetch_order_book(symbol.name)
Parameters: - symbol (
str
) – interesting symbol name - level_aggregation (
Optional
[int
]) – aggregate by rounding numbers (if not defined - no aggregation)
Return type: Returns: order depth book
- symbol (