BitEx API Reference¶
Core Modules¶
bitex.session Module¶
A customized version of requests.Session, tailored to the bitex-framework library.
-
class
bitex.session.BitexSession(auth: Optional[bitex.auth.BitexAuth] = None)[source]¶ Custom
requests.Sessionobject for keep-alive http connections to API endpoints.It expects a
BitexAuthinstance or subclass thereof on instantiation, and assigns it as the default authentication object for any requests made via this class’s instance.Using one of these methods requires an adequate plugin to be installed for exchange. If no such plugin is present, an
bitex.exceptions.MissingPluginexception is raised bybitex.request.BitexPreparedRequest.Using the bitex short-hand is not mandatory, but supported. You may as well construct the entire url of an endpoint you’d like to reach manually, and
bitex-frameworkwill do the right thing.-
cancel_order(exchange: str, pair: str, method: str = 'DELETE', **kwargs) → bitex.response.BitexResponse[source]¶ Cancel an order with the given order_id for pair at the given exchange.
- Parameters
exchange (str) – The exchange you’d like to request data from.
pair (str) – The currency pair to place the order for.
order_id – The order id of the order you’d like to cancel.
method (str) – The HTTP method to use when placing the order. This defaults to DELETE.
kwargs (Any) – Additional keyword arguments which are passed on to
requests.Session.request().
- Return type
-
deposit(exchange: str, currency: str, method: str = 'GET', **kwargs) → bitex.response.BitexResponse[source]¶ Request the deposit address of the given currency’s wallet.
-
new_order(exchange: str, pair: str, method: str = 'POST', **kwargs) → bitex.response.BitexResponse[source]¶ Create a new order for pair at the given exchange.
- Parameters
- Return type
-
order_status(exchange: str, pair: str, method: str = 'GET', **kwargs) → bitex.response.BitexResponse[source]¶ Request the order status for order_id and pair at the given exchange.
- Parameters
- Return type
-
orderbook(exchange: str, pair: str, method: str = 'GET', **kwargs) → bitex.response.BitexResponse[source]¶ Request order book data for the given pair at the given exchange.
- Parameters
-
prepare_request(request: bitex.request.BitexRequest) → bitex.request.BitexPreparedRequest[source]¶ Prepare a
BitexPreparedRequestobject for transmission.This implementation extends
requests.Session.prepare_requestby making a call tobitex.PLUGINSand checking if we have any plugins that may provide a customBitexPreparedRequestclass.
-
request(method, url, private=False, params=None, data=None, headers=None, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, proxies=None, hooks=None, stream=None, verify=None, cert=None, json=None) → bitex.response.BitexResponse[source]¶ Construct a
BitexRequest, prepare and send it.url may either be a URL starting with http/https, or a
bitex-frameworkshort-hand url in the format of <exchange>:<instrument>/<data>/<action>.
-
ticker(exchange: str, pair: str, method: str = 'GET', **kwargs) → bitex.response.BitexResponse[source]¶ Request ticker data for the given pair at the given exchange.
- Parameters
-
trades(exchange: str, pair: str, method: str = 'GET', **kwargs) → bitex.response.BitexResponse[source]¶ Request trade data for the given pair at the given exchange.
- Parameters
-
wallet(exchange: str, currency: str, method: str = 'GET', **kwargs) → bitex.response.BitexResponse[source]¶ Request wallet data for the given pair at the given exchange.
- Parameters
-
withdraw(exchange: str, currency: str, amount: str, method: str = 'PUT', **kwargs) → bitex.response.BitexResponse[source]¶ Request a withdrawal of the given currency at the given exchange.
- Parameters
exchange (str) – The exchange you’d like to request data from.
currency (str) – The currency to withdraw.
amount (str) – The amount to withdraw.
method (str) – The HTTP method to use when requesting the data. This defaults to GET.
kwargs (Any) – Additional keyword arguments which are passed on to
requests.Session.request().
-
bitex.auth Module¶
Basic auth class for bitex-framework.
-
class
bitex.auth.BitexAuth(key: str, secret: str)[source]¶ Authentication Meta Class for API authentication.
Takes care of generating a signature and preparing data to be sent, headers and URLs as required by the exchange this class is subclassed for.
-
static
decode_body(request: bitex.request.BitexPreparedRequest) → Tuple[Tuple[str, List[Any]], …][source]¶ Decode the urlencoded body of the given request and return it.
Some signature algorithms require us to use parameters supplied via the request body. Since the body is already urlencoded using
requests.PreparedRequest.prepare(), we need to undo its work before returning the request body’s contents.We must accommodate for the case that in some cases the body may be a JSON encoded string. We expect the parsed JSON to be a dictionary of objects.
- Parameters
request (BitexPreparedRequest) – The request whose body we should decode.
-
property
key_as_bytes¶ Return the key encoded as bytes.
-
static
nonce() → str[source]¶ Create a Nonce value for signature generation.
By default, this is a unix timestamp with millisecond resolution.
converted to a str.
- Return type
-
property
secret_as_bytes¶ Return the secret encoded as bytes.
-
static
bitex.request Module¶
bitex-framework extension for requests.Request & requests.PreparedRequest classes.
-
class
bitex.request.BitexPreparedRequest(exchange)[source]¶ Bitex extension of :cls”requests.PreparedRequest.
Implements a checker function for short-hand urls.
-
static
check_url_for_shorthand(url) → Optional[Dict[str, Optional[str]]][source]¶ Check if the given URL is a bitex short-hand.
If it is, we return the value of
re.Match.groupdict(); otherwise we return None instead.
-
static
-
class
bitex.request.BitexRequest(private: bool = False, **kwargs)[source]¶ Bitex extension of :cls”requests.Request.
Implements a parser function for exchange names from a given URL.
Additionally re-implements
requests.Request.prepare(), replacing the instantiation of the requests.PreparedRequest class with an instance ofBitexPreparedRequest.-
parse_target_exchange() → Optional[str][source]¶ Check the URL for its scheme and extract an exchange name, if any.
If the url starts with http/https we set
BitexRequest.exchangeto None. Otherwise we store the exchange in said attribute.
-
prepare() → bitex.request.BitexPreparedRequest[source]¶ Construct a
BitexPreparedRequestfor transmission and return it.Note
Unlike
BitexSession.prepare_request(), this method does not apply a custom auth class automatically, if no auth object was given.
-
bitex.response Module¶
Customized requests.Response class for the bitex-framework framework.
-
class
bitex.response.BitexResponse[source]¶ Custom
requests.Responseclass.Supplies additional format outputs of the underlying JSON data, as returned by
json().
bitex.adapter Module¶
Custom requests.HTTPAdapter for bitex-framework.
-
class
bitex.adapter.BitexHTTPAdapter(pool_connections=10, pool_maxsize=10, max_retries=0, pool_block=False)[source]¶ Custom HTTP Adapter for
Bitex.It replaces
requests.Responseas the default response class when building the response, with either an adequate plugin-supplied class orbitex-framework‘s own defaultBitexResponseclass.-
build_response(req: bitex.request.BitexPreparedRequest, resp: urllib3.response.HTTPResponse) → bitex.response.BitexResponse[source]¶ Build a
BitexResponsefrom the given req and resp.The method is largely identical to
HTTPAdapter.build_response(), and only differs in the class type used when constructing a response.This class is taken firstly from any valid plugin that supplies an adequate class for the exchange that was queried (as stated in
BitexPreparedRequest.exchange), orbitex-framework‘s own defaultBitexResponseclass.- Parameters
req (BitexPreparedRequest) – The
BitexPreparedRequestused to generate the response.resp (HTTPResponse) – The urllib3 response object.
-
bitex.constants Module¶
-
bitex.constants= <module 'bitex.constants' from '/home/docs/checkouts/readthedocs.org/user_builds/bitex-framework/envs/stable/lib/python3.6/site-packages/bitex_framework-1.1.0-py3.6.egg/bitex/constants/__init__.py'>¶ Constants used across the :mod`bitex` code base.