BitEx Code Reference¶
BitEx - Crypto-Exchange REST API Framework.
API Objects¶
-
class
bitex.api.base.
BaseAPI
(*, addr, key, secret, version, config)[source]¶ BaseAPI provides lowest-common-denominator methods used in all API types.
It provides a nonce() method, basic configuration loading and credential validity checking method check_auth_requirements(), which should be extended in subclasses to cover any additional parameters that are necessary.
-
check_auth_requirements
()[source]¶ Check that neither self.key nor self.secret are None.
If so, this method raises an IncompleteCredentialsError. Otherwise returns None.
Extend this in child classes if you need to check for further required values.
Raise: IncompleteCredentialsError Returns: None
-
-
class
bitex.api.REST.rest.
RESTAPI
(addr, timeout=None, key=None, secret=None, version=None, config=None)[source]¶ Generic REST API interface.
Supplies private and public query methods, as well as building blocks to customize the signature generation process.
-
generate_uri
(endpoint)[source]¶ Generate a Unique Resource Identifier (API Version + Endpoint).
Parameters: endpoint – str, endpoint path (i.e. /market/btcusd) Returns: str, URI
-
generate_url
(uri)[source]¶ Generate a Unique Resource Locator (API Address + URI).
Parameters: uri – str, URI Returns: str, URL
-
sign_request_kwargs
(endpoint, **kwargs)[source]¶ Generate dummy Request Kwarg Signature.
Extend this to implement signing of requests for private API calls. By default, it supplies a default URL using generate_uri and generate_url.
Parameters: - endpoint – str, API Endpoint
- kwargs – Kwargs meant for requests.Request()
Returns: dict, request kwargs
-
private_query
(method_verb, endpoint, **request_kwargs)[source]¶ Query a private API endpoint requiring signing of the request.
Parameters: - method_verb – valid HTTP Verb (GET, PUT, DELETE, etc.)
- endpoint – str, API Endpoint
- request_kwargs – kwargs for request.Request()
Returns: request.Response() object
-
public_query
(method_verb, endpoint, **request_kwargs)[source]¶ Query a public (i.e. unauthenticated) API endpoint and return the result.
Parameters: - method_verb – valid HTTP Verb (GET, PUT, DELETE, etc.)
- endpoint – str, API Endpoint
- request_kwargs – kwargs for request.Request()
Returns: request.Response() object
-
Trading Pairs already implemented¶
Includes the base class for crypto currency pairs and the PairFormatter class.
It also provides convencience wrappers for commonly used Pairs: these can be imported to avoid typos by the user, and can be directly passed to the APIs.
If the pair you want to query isn’t present in here, creating such a pair is simple enough - simply initialize the PairFormatter class with the currencies you want:
>>> my_pair = PairFormatter('BaseCurrency', 'QuoteCurrency')
The object my_pair
now takes care of all formatting of any exchange,
supported by Bitex, you pass it to.
-
class
bitex.pairs.
PairFormatter
(base, quote)[source]¶ Container Class which features formatting function for all supported exchanges.
These Formatter functions apply any changes to make a given pair, pased as quote and base currency, compatible with an exchange. This does NOT include an availability check of the pair. It is therefore possible to format a given pair, even though it is not supported by the requested exchange.
-
static
kraken_formatter
(base, quote)[source]¶ Format the currencies for Kraken.
Generally speaking, Kraken prefixes digital currencies with a capital ‘X’, and fiat Currencies with a capital ‘Z’. There exceptions to this rule, unfortunately, which should be handled as well.
-
static
bitfinex_formatter
(base, quote)[source]¶ Format currencies for bitfinex.
- Edgecase:
DASH
- This symbol is shortened to
DSH
.
- Edgecase:
-
static
itbit_formatter
(base, quote)[source]¶ Format currencies for ItBit.
- Edge case:
BTC
- BTC is denoted as
XBT
.
- Edge case:
-
static
Interface Objects¶
-
class
bitex.interface.base.
Interface
(*, name, rest_api)[source]¶ Base class for Interface objects.
-
supported_pairs
¶ Return a list of supported currncy pairs.
Returns: list
-
is_supported
(pair)[source]¶ Check if the given pair is present in self._supported_pairs.
Input can either be a string or a PairFormatter Obj (or child thereof). If it is the latter two, we’ll call the format() method with the Interface’s name attribute to acquire proper formatting.
Parameters: pair – Str, or bitex.pairs.PairFormatter Object Returns: Bool
-
request
(verb, endpoint, authenticate=False, **req_kwargs)[source]¶ Query the API and return its result.
Parameters: - verb – HTTP verb (GET, PUT, DELETE, etc)
- endpoint – Str
- authenticate – Bool, whether to call private_query or public_query method.
- req_kwargs – Kwargs to pass to _query /
requests.Request()
Raise: UnsupportedPairError
Returns: requests.Response() Obj
-
-
class
bitex.interface.rest.
RESTInterface
(name, rest_api)[source]¶ REST Interface base class.
-
ticker
(pair, *args, **kwargs)[source]¶ Return the ticker for the given pair.
Parameters: - pair – Str, pair to request data for.
- args – additional arguments.
- kwargs – additional kwargs, passed to requests.Requests() as ‘param’ kwarg.
Returns: requests.Response()
object.
-
order_book
(pair, *args, **kwargs)[source]¶ Return the order book for the given pair.
Parameters: - pair – Str, pair to request data for.
- args – additional arguments.
- kwargs – additional kwargs, passed to requests.Requests() as ‘param’ kwarg.
Returns: requests.Response()
object.
-
trades
(pair, *args, **kwargs)[source]¶ Return the trades for the given pair.
Parameters: - pair – Str, pair to request data for.
- args – additional arguments.
- kwargs – additional kwargs, passed to requests.Requests() as ‘param’ kwarg.
Returns: requests.Response()
object.
-
ask
(pair, price, size, *args, **kwargs)[source]¶ Place an ask order.
Parameters: - pair – Str, pair to post order for.
- price – Float or str, price you’d like to ask.
- size – Float or str, amount of currency you’d like to sell.
- args – additional arguments.
- kwargs – additional kwargs, passed to requests.Requests() as ‘param’ kwarg.
Returns: requests.Response()
object.
-
bid
(pair, price, size, *args, **kwargs)[source]¶ Place a bid order.
Parameters: - pair – Str, pair to post order for.
- price – Float or str, price you’d like to bid.
- size – Float or str, amount of currency you’d like to buy.
- args – additional arguments.
- kwargs – additional kwargs, passed to requests.Requests() as ‘param’ kwarg.
Returns: requests.Response()
object.
-
order_status
(order_id, *args, **kwargs)[source]¶ Return the status of an order with the given id.
Parameters: - order_id – Order ID of the order you’d like to have a status for.
- args – additional arguments.
- kwargs – additional kwargs, passed to requests.Requests() as ‘param’ kwarg.
Returns: requests.Response()
object.
-
open_orders
(*args, **kwargs)[source]¶ Return all open orders.
Parameters: - args – additional arguments.
- kwargs – additional kwargs, passed to requests.Requests() as ‘param’ kwarg.
Returns: requests.Response()
object.
-