EXX API

client module

class exx.client.Client(api_key, api_secret)[source]

Bases: object

API_URL = 'https://api.exx.com/data/v1'
PRIVATE_URL = 'https://trade.exx.com/api'
SIDE_BUY = 'buy'
SIDE_SELL = 'sell'
__init__(api_key, api_secret)[source]

Exx API Client constructor

https://www.exx.com/help/restApi

Parameters:
  • api_key (string) – Api Token Id
  • api_secret (string) – Api Secret
client = Client(api_key, api_secret)
cancel_order(symbol, order_id)[source]

Cancel an order

Parameters:
  • symbol (int) – required e.g eth_hsr
  • order_id – required e.g 123456789
res = client.cancel_order('eth_hsr', 123456789)
Returns:dict
{
    "code": "100",
    "message": "操作成功。"
}
Raises:ExxResponseException, ExxAPIException
create_order(symbol, order_type, price, amount)[source]

Cancel an order

Parameters:
  • symbol (str) – e.g eth_hsr
  • order_type – type buy or sell
  • price – price to trade at
  • amount – amount to trade
order = client.create_order('eth_hsr', 'buy', '0.0012', '1023.2')
Returns:dict
{
    "code": 100,
    "message": "操作成功",
    "id": "13877"
}
Raises:ExxResponseException, ExxAPIException
get_balance()[source]

Get your balance

orders = client.get_balance()
Returns:dict
{
    "credits": [
        {
            "flatRatio": "0.1",
            "userRatio": "0.0985",
            "noticeRatio": "0.2",
            "levels": 10,
            "flatPrice": 11.01471399
        }
    ],
    "funds": {
        "BTS": {
            "total": "10",
            "freeze": "0",
            "balance": "10",
            "propTag": "BTS",
            "credit_quota": "121.938066",
            "credit_borrowed": "0",
            "credit_interest": "0"
        },
        "MONA": {
            "total": "0.966033",
            "freeze": "0.966033",
            "balance": "0",
            "propTag": "MONA",
            "credit_quota": "0",
            "credit_borrowed": "0",
            "credit_interest": "0"
        },
        ....
        "ETH": {
            "total": "10",
            "freeze": "0",
            "balance": "10",
            "propTag": "ETH",
            "credit_quota": "121.938066",
            "credit_borrowed": "0",
            "credit_interest": "0"
        },
        "LTC": {
            "total": "0",
            "freeze": "0",
            "balance": "0",
            "propTag": "LTC",
            "credit_quota": "121.938066",
            "credit_borrowed": "0",
            "credit_interest": "0"
        },
        "QTUM": {
            "total": "0.003",
            "freeze": "0.003",
            "balance": "0",
            "propTag": "QTUM",
            "credit_quota": "0",
            "credit_borrowed": "9.65",
            "credit_interest": "0.026252"
        }
    }
}
Raises:ExxResponseException, ExxAPIException
get_market_trades(symbol)[source]

Get the trades for the symbol

Parameters:symbol (str) – required e.g eth_hsr
trades = client.get_market_trades('eth_hsr')
Returns:list of dicts
[
    {
        "amount"     : 0.933,
        "price"      : 31.595,
        "tid"        : 2583932,     # Trade ID
        "type"       : "sell",      # Trade type
        "date"       : 2583932,
        "trade_type" : "ask",       # Order type
    }, ...
]
Raises:ExxResponseException, ExxAPIException
get_markets()[source]

Get a list of markets

markets = client.get_markets()
Returns:dict of dicts
{
     "eos_btc":{
         "amountScale":2,
         "priceScale":6,
         "maxLevels":0,
         "isOpen":false
     },
     "etc_hsr":{
         "amountScale":3,
         "priceScale":3,
         "maxLevels":0,
         "isOpen":true
     },
}
Raises:ExxResponseException, ExxAPIException
get_open_orders(symbol, order_type=None, page=1)[source]

Get a list of open buy or sell orders, 10 at a time

Parameters:
  • symbol (str) – e.g eth_hsr
  • order_type – optional - type buy or sell
  • page (int) – page index starting at 1
# get first page of open orders
orders = client.get_open_orders('hsr_eth')

# get first page of buy orders
orders = client.get_open_orders('hsr_eth', 'buy')

# second page of sell orders
orders = client.get_open_orders('hsr_eth', 'sell', 2)
Returns:list of dicts
{
    "fees": 0,
    "total_amount": 1,
    "trade_amount": 0,
    "price": 31,
    "currency": “eth_hsr",
    "id": "13877",
    "trade_money": 0,
    "type": "buy",
    "trade_date": 1509728383300,
    "status": 0
}
Raises:ExxResponseException, ExxAPIException
get_order(symbol, order_id)[source]

Cancel an order

Parameters:
  • symbol (int) – required e.g eth_hsr
  • order_id – required e.g 123456789
order = client.get_order('eth_hsr', 123456789)
Returns:dict
{
    "fees": 0,
    "total_amount": 1,
    "trade_amount": 0,
    "price": 31,
    "currency": “eth_hsr",
    "id": "13877",
    "trade_money": 0,
    "type": "buy",
    "trade_date": 1509728383300,
    "status": 0
}
Raises:ExxResponseException, ExxAPIException
get_order_book(symbol)[source]

Get the bid and asks for the symbol

Parameters:symbol (str) – required e.g eth_hsr
markets = client.get_order_book('eth_hsr')
Returns:dict
{
    "asks": [
        [
            "32.831",   # price
            "0.083"     # quantity
        ]...
    ],
    "bids": [
        [
            "30.434",   # price
            "10.766"    # quantity
        ]...
    ],
    "timestamp" : Timestamp
}
Raises:ExxResponseException, ExxAPIException
get_ticker(symbol)[source]

Get symbol price ticker

Parameters:symbol (str) – required e.g eth_hsr
markets = client.get_ticker('eth_hsr')
Returns:dict
{
    "ticker": {
        "vol": "1447.851",
        "last": "30.487000000",
        "sell": "30.499",
        "buy": "30.487",
        "weekRiseRate": -1.17,
        "riseRate": 9.45,
        "high": "30.812",
        "low": "27.855",
        "monthRiseRate": -0.99
    },
    "date": "1510383406453"
}
Raises:ExxResponseException, ExxAPIException
get_tickers()[source]

Get all price tickers

markets = client.get_markets()
Returns:dict of dicts
{
    "bts_btc":{
        "vol":0.0,
        "last":0,
        "sell":0.0,
        "buy":0.0,
        "weekRiseRate":0.0,
        "riseRate":0.0,
        "high":0.0,
        "low":0,
        "monthRiseRate":0.0
    },
}
Raises:ExxResponseException, ExxAPIException

exceptions module

exception exx.exceptions.ExxAPIException(response)[source]

Bases: exceptions.Exception

Exception class to handle general API Exceptions

code values

message format

__init__(response)[source]
exception exx.exceptions.ExxRequestException(message)[source]

Bases: exceptions.Exception

__init__(message)[source]