quant/markets/_bitflyer.py
class Bitflyer(Market):
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)

        super(Bitflyer, self).__init__(base_currency, market_currency, pair_code, 0.0025)

        self.client = bitflyer.PublicClient()

    def update_depth(self):
        raw_depth = self.client.depth(self.pair_code)
        if raw_depth:
            self.depth = self.format_depth(raw_depth)

    @classmethod
    def sort_and_format(cls, l, reverse=False):
        l.sort(key=lambda x: float(x['price']), reverse=reverse)
        r = []
        for i in l:
            r.append({'price': float(i['price']), 'amount': float(i['size'])})
        return r

    def format_depth(self, depth):
        bids = self.sort_and_format(depth['bids'], True)
        asks = self.sort_and_format(depth['asks'], False)
        return {'asks': asks, 'bids': bids}

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'btc_jpy':
            base_currency = 'JPY'
            market_currency = 'BTC'
        elif pair_code == 'eth_btc':
            base_currency = 'BTC'
            market_currency = 'ETH'
        elif pair_code == 'bch_btc':
            base_currency = 'BTC'
            market_currency = 'BCH'
        else:
            assert False
        return base_currency, market_currency
quant/markets/_binance.py
class Binance(Market):
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)
        super(Binance, self).__init__(base_currency, market_currency, pair_code, 0.001)

        self.client = Client(None, None)

    def update_depth(self):
        raw_depth = self.client.get_order_book(symbol=self.pair_code, limit=5)
        if raw_depth:
            self.depth = self.format_depth(raw_depth)

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'BCCBTC':
            base_currency = 'BTC'
            market_currency = 'BCC'
        elif pair_code == 'BTCUSDT':
            base_currency = 'USDT'
            market_currency = 'BTC'
        elif pair_code == 'ETHBTC':
            base_currency = 'BTC'
            market_currency = 'ETH'
        elif pair_code == 'ETHUSDT':
            base_currency = 'USDT'
            market_currency = 'ETH'
        elif pair_code == 'BNBBTC':
            base_currency = 'BTC'
            market_currency = 'BNB'
        elif pair_code == 'BNBETH':
            base_currency = 'ETH'
            market_currency = 'BNB'
        elif pair_code == 'MCOBTC':
            base_currency = 'BTC'
            market_currency = 'MCO'
        elif pair_code == 'MCOETH':
            base_currency = 'ETH'
            market_currency = 'MCO'
        elif pair_code == 'QTUMBTC':
            base_currency = 'BTC'
            market_currency = 'QTUMBCH'
        elif pair_code == 'QTUMETH':
            base_currency = 'ETH'
            market_currency = 'QTUM'
        elif pair_code == 'WTCBTC':
            base_currency = 'BTC'
            market_currency = 'WTC'
        elif pair_code == 'WTCETH':
            base_currency = 'ETH'
            market_currency = 'WTC'
        elif pair_code == 'NEOBTC':
            base_currency = 'BTC'
            market_currency = 'NEO'
        elif pair_code == 'NEOETH':
            base_currency = 'ETH'
            market_currency = 'NEO'
        elif pair_code == 'IOTAETH':
            base_currency = 'ETH'
            market_currency = 'IOTA'
        elif pair_code == 'IOTABTC':
            base_currency = 'BTC'
            market_currency = 'IOTA'
        elif pair_code == 'ZRXBTC':
            base_currency = 'BTC'
            market_currency = 'ZRX'
        elif pair_code == 'ZRXETH':
            base_currency = 'ETH'
            market_currency = 'ZRX'
        else:
            assert False
        return base_currency, market_currency

    @classmethod
    def format_depth(cls, depth):
        bids = market_util.sort_and_format_list(depth['bids'], True)
        asks = market_util.sort_and_format_list(depth['asks'], False)
        return {'asks': asks, 'bids': bids}
quant/markets/_cex.py
class Cex(Market):
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)
        super(Cex, self).__init__(base_currency, market_currency, pair_code, 0.002)
        self.client = PublicClient()

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'bccbtc':
            base_currency = 'BTC'
            market_currency = 'BCH'
        else:
            assert False
        return base_currency, market_currency

    def symbol(self):
        return "%s/%s" % (self.market_currency.upper(), self.base_currency.upper())

    def update_depth(self):
        depth_raw = self.client.depth(self.symbol())
        if depth_raw:
            self.depth = self.format_depth(depth_raw)

    @classmethod
    def format_depth(cls, depth):
        bids = market_util.sort_and_format_list(depth['bids'], True)
        asks = market_util.sort_and_format_list(depth['asks'], False)
        return {'asks': asks, 'bids': bids}
quant/markets/_bithumb.py
class Bithumb(Market):
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)

        super(Bithumb, self).__init__(base_currency, market_currency, pair_code, 0.0025)

        self.client = bithumb.PublicClient()

    def update_depth(self):
        raw_depth = self.client.depth(self.pair_code)
        if raw_depth and 'data' in raw_depth:
            raw_depth = raw_depth['data']
            if raw_depth:
                self.depth = self.format_depth(raw_depth)

    @classmethod
    def sort_and_format(cls, l, reverse=False):
        l.sort(key=lambda x: float(x['price']), reverse=reverse)
        r = []
        for i in l:
            r.append({'price': float(i['price']), 'amount': float(i['quantity'])})
        return r

    def format_depth(self, depth):
        bids = self.sort_and_format(depth['bids'], True)
        asks = self.sort_and_format(depth['asks'], False)
        return {'asks': asks, 'bids': bids}

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'btc':
            base_currency = 'KRW'
            market_currency = 'BTC'
        elif pair_code == 'eth':
            base_currency = 'KRW'
            market_currency = 'ETH'
        elif pair_code == 'bch':
            base_currency = 'KRW'
            market_currency = 'BCH'
        else:
            assert False
        return base_currency, market_currency
quant/markets/_coinegg.py
class Coinegg(Market):
    """XBT就是BTC"""
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)
        super(Coinegg, self).__init__(base_currency, market_currency, pair_code, 0.001)
        self.client = PublicClient()

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'bcc':
            base_currency = 'BTC'
            market_currency = 'BCC'
        elif pair_code == 'eth':
            base_currency = 'BTC'
            market_currency = 'ETH'
        elif pair_code == 'neo':
            base_currency = 'BTC'
            market_currency = 'NEO'
        elif pair_code == 'etc':
            base_currency = 'BTC'
            market_currency = 'ETC'
        else:
            assert False
        return base_currency, market_currency

    def update_depth(self):
        depth_raw = self.client.depth(self.pair_code)
        if depth_raw:
            self.depth = self.format_depth(depth_raw)

    @classmethod
    def format_depth(cls, depth):
        bids = market_util.sort_and_format_list(depth['bids'], True)
        asks = market_util.sort_and_format_list(depth['asks'], False)
        return {'asks': asks, 'bids': bids}
quant/markets/_kkex.py
class Kkex(Market):
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)
        super(Kkex, self).__init__(base_currency, market_currency, pair_code, 0.0025)
        self.client = Client()

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'BCHBTC':
            base_currency = 'BTC'
            market_currency = 'BCH'
        else:
            assert False
        return base_currency, market_currency

    def update_depth(self):
        depth_raw = self.client.depth(self.pair_code)

        if depth_raw:
            self.depth = self.format_depth(depth_raw)

    @classmethod
    def format_depth(cls, depth):
        bids = market_util.sort_and_format_list(depth['bids'], True)
        asks = market_util.sort_and_format_list(depth['asks'], False)
        return {'asks': asks, 'bids': bids}
quant/markets/_gate.py
class Gate(Market):
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)
        super(Gate, self).__init__(base_currency, market_currency, pair_code, 0.002)
        self.client = PublicClient()

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'eth_btc':
            base_currency = 'BTC'
            market_currency = 'ETH'
        elif pair_code == 'bcc_btc':
            base_currency = 'BTC'
            market_currency = 'BCC'
        else:
            assert False
        return base_currency, market_currency

    def update_depth(self):
        depth_raw = self.client.depth(self.pair_code)
        if depth_raw:
            self.depth = self.format_depth(depth_raw)

    @classmethod
    def format_depth(cls, depth):
        bids = market_util.sort_and_format_list(depth['bids'], True)
        asks = market_util.sort_and_format_list(depth['asks'], False)
        return {'asks': asks, 'bids': bids}
quant/markets/_bitfinex.py
class Bitfinex(Market):
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)
        super(Bitfinex, self).__init__(base_currency, market_currency, pair_code, 0.002)
        self.client = Client()

    def update_depth(self):
        try:
            depth_raw = self.client.depth(self.pair_code)
            if depth_raw:
                self.depth = self.format_depth(depth_raw)
            else:
                raise ValueError('response is None')
        except Exception as e:
            raise e

    @classmethod
    def format_depth(cls, depth):
        bids = market_util.sort_and_format_dict(depth['bids'], True)
        asks = market_util.sort_and_format_dict(depth['asks'], False)
        return {'asks': asks, 'bids': bids}

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'ethusd':
            base_currency = 'USD'
            market_currency = 'ETH'
        elif pair_code == 'ethbtc':
            base_currency = 'BTC'
            market_currency = 'ETH'
        elif pair_code == 'etcbtc':
            base_currency = 'BTC'
            market_currency = 'ETC'
        elif pair_code == 'etcusd':
            base_currency = 'USD'
            market_currency = 'ETC'
        elif pair_code == 'bchbtc':
            base_currency = 'BTC'
            market_currency = 'BCH'
        elif pair_code == 'btcusd':
            base_currency = 'USD'
            market_currency = 'BTC'
        elif pair_code == 'bt1usd':
            base_currency = 'USD'
            market_currency = 'BT1'
        elif pair_code == 'bt2usd':
            base_currency = 'USD'
            market_currency = 'BT2'
        elif pair_code == 'bt1btc':
            base_currency = 'BTC'
            market_currency = 'BT1'
        elif pair_code == 'bt2btc':
            base_currency = 'BTC'
            market_currency = 'BT2'
        elif pair_code == 'bchusd':
            base_currency = 'USD'
            market_currency = 'BCH'
        elif pair_code == 'eosusd':
            base_currency = 'USD'
            market_currency = 'EOS'
        elif pair_code == 'eoseth':
            base_currency = 'ETH'
            market_currency = 'EOS'
        elif pair_code == 'zecusd':
            base_currency = 'USD'
            market_currency = 'ZEC'
        elif pair_code == 'neousd':
            base_currency = 'USD'
            market_currency = 'NEO'
        elif pair_code == 'neobtc':
            base_currency = 'BTC'
            market_currency = 'NEO'
        elif pair_code == 'neoeth':
            base_currency = 'ETH'
            market_currency = 'NEO'
        elif pair_code == 'iotusd':
            base_currency = 'USD'
            market_currency = 'IOT'
        elif pair_code == 'iotbtc':
            base_currency = 'BTC'
            market_currency = 'IOT'
        elif pair_code == 'zrxeth':
            base_currency = 'ETH'
            market_currency = 'ZRX'
        elif pair_code == 'zrxbtc':
            base_currency = 'BTC'
            market_currency = 'ZRX'
        else:
            assert False
        return base_currency, market_currency
quant/markets/_huobi.py
class Huobi(Market):
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)
        super(Huobi, self).__init__(base_currency, market_currency, pair_code, 0.002)
        self.client = Client()

    def update_depth(self):
        try:
            depth_raw = self.client.depth(self.pair_code)
            if depth_raw:
                if 'status' not in depth_raw and depth_raw['status'] != 'ok':
                    raise Exception('status not exist in raw response or is not ok')
                if 'tick' not in depth_raw:
                    raise Exception('tick not exist in raw response')
                self.depth = self.format_depth(depth_raw['tick'])
            else:
                raise Exception('response is None')
        except Exception as e:
            raise e

    @classmethod
    def format_depth(cls, depth):
        bids = market_util.sort_and_format_list(depth['bids'], True)
        asks = market_util.sort_and_format_list(depth['asks'], False)
        return {'asks': asks, 'bids': bids}

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'ethusdt':
            base_currency = 'USDT'
            market_currency = 'ETH'
        elif pair_code == 'ethbtc':
            base_currency = 'BTC'
            market_currency = 'ETH'
        elif pair_code == 'etcbtc':
            base_currency = 'BTC'
            market_currency = 'ETC'
        elif pair_code == 'etcusdt':
            base_currency = 'USDT'
            market_currency = 'ETC'
        elif pair_code == 'bchbtc':
            base_currency = 'BTC'
            market_currency = 'BCH'
        elif pair_code == 'btcusdt':
            base_currency = 'USDT'
            market_currency = 'BTC'
        else:
            assert False
        return base_currency, market_currency
quant/markets/_liqui.py
class Liqui(Market):
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)
        super(Liqui, self).__init__(base_currency, market_currency, pair_code, 0.002)
        self.client = PublicClient()

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'bcc_btc':
            base_currency = 'BTC'
            market_currency = 'BCC'
        elif pair_code == 'bcc_eth':
            base_currency = 'ETH'
            market_currency = 'BCC'
        elif pair_code == 'eos_btc':
            base_currency = 'BTC'
            market_currency = 'EOS'
        else:
            assert False
        return base_currency, market_currency

    def update_depth(self):
        depth_raw = self.client.depth(self.pair_code)
        if depth_raw and self.pair_code in depth_raw:
            self.depth = self.format_depth(depth_raw[self.pair_code])

    @classmethod
    def format_depth(cls, depth):
        bids = market_util.sort_and_format_list(depth['bids'], True)
        asks = market_util.sort_and_format_list(depth['asks'], False)
        return {'asks': asks, 'bids': bids}
quant/markets/_kraken.py
class Kraken(Market):
    """XBT就是BTC"""
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)
        super(Kraken, self).__init__(base_currency, market_currency, pair_code, 0.002)
        self.client = PublicClient()

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'xbteur':
            base_currency = 'EUR'
            market_currency = 'XBT'
        elif pair_code == 'xbtusd':
            base_currency = 'USD'
            market_currency = 'XBT'
        elif pair_code == 'etheur':
            base_currency = 'EUR'
            market_currency = 'ETH'
        elif pair_code == 'ethusd':
            base_currency = 'USD'
            market_currency = 'ETH'
        elif pair_code == 'bcheur':
            base_currency = 'EUR'
            market_currency = 'BCH'
        elif pair_code == 'bchusd':
            base_currency = 'USD'
            market_currency = 'BCH'
        elif pair_code == 'eoseur':
            base_currency = 'EUR'
            market_currency = 'EOS'
        elif pair_code == 'eosusd':
            base_currency = 'USD'
            market_currency = 'EOS'
        else:
            assert False
        return base_currency, market_currency

    def update_depth(self):
        depth_raw = self.client.depth(self.pair_code)
        if depth_raw and 'result' in depth_raw:
            depth_raw = depth_raw['result']
            if len(depth_raw) > 0:
                depth_raw = depth_raw.values()[0]
                self.depth = self.format_depth(depth_raw)

    @classmethod
    def format_depth(cls, depth):
        bids = market_util.sort_and_format_list(depth['bids'], True)
        asks = market_util.sort_and_format_list(depth['asks'], False)
        return {'asks': asks, 'bids': bids}
quant/common/constant.py
ORDER_STATE_PENDING = 1
ORDER_STATE_CLOSED = 2
ORDER_STATE_CANCELED = 4
ORDER_STATE_UNKNOWN = 8
EX_OKEX = 'Okex'
EX_BFX = 'Bitfinex'
EX_LQ = 'Liqui'
EX_GDAX = 'Gdax'
EX_BINANCE = 'Binance'
EX_CEX = 'Cex'
EX_EXMO = 'Exmo'
EX_KKEX = 'Kkex'
EX_HITBITC = 'Hitbtc'
EX_BITTREX = 'Bittrex'
EX_GATE = 'Gate'
EX_BITFLYER = 'Bitflyer'
EX_KRAKEN = 'Kraken'
EX_COINEGG = 'Coinegg'
EX_BITHUMB = 'Bithumb'
EX_HUOBI = 'Huobi'
EX_SET = (
    EX_OKEX,
    EX_BFX,
    EX_LQ,
    EX_GDAX,
    EX_BINANCE,
    EX_CEX,
    EX_EXMO,
    EX_BITTREX,
    EX_BITFLYER,
    EX_KRAKEN,
    EX_COINEGG,
    EX_BITHUMB
)
CODE_LQ_SELL_NOT_ENOUGH = 832
CODE_LQ_BUY_NOT_ENOUGH = 831
quant/markets/_hitbtc.py
class Hitbtc(Market):
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)
        super(Hitbtc, self).__init__(base_currency, market_currency, pair_code, 0.002)
        self.client = PublicClient()

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'bccbtc':
            base_currency = 'BTC'
            market_currency = 'BCC'
        else:
            assert False
        return base_currency, market_currency

    def symbol(self):
        return "%s%s" % (self.market_currency.upper(), self.base_currency.upper())

    def update_depth(self):
        depth_raw = self.client.depth(self.symbol())
        if depth_raw:
            self.depth = self.format_depth(depth_raw)

    @classmethod
    def format_depth(cls, depth):
        bids = market_util.sort_and_format_list(depth['bids'], True)
        asks = market_util.sort_and_format_list(depth['asks'], False)
        return {'asks': asks, 'bids': bids}
quant/markets/_bittrex.py
class Bittrex(Market):
    def __init__(self, pair_code):
        base_currency, market_currency = self.get_available_pairs(pair_code)

        super(Bittrex, self).__init__(base_currency, market_currency, pair_code, 0.0025)

        self.client = bittrex.Bittrex(None, None)

    def update_depth(self):
        raw_depth = self.client.get_orderbook(self.pair_code, 'both')
        self.depth = self.format_depth(raw_depth)

    # override method
    def sort_and_format(self, l, reverse=False):
        l.sort(key=lambda x: float(x['Rate']), reverse=reverse)
        r = []
        for i in l:
            r.append({'price': float(i['Rate']), 'amount': float(i['Quantity'])})
        return r

    # override method
    def format_depth(self, depth):
        bids = self.sort_and_format(depth['result']['buy'], True)
        asks = self.sort_and_format(depth['result']['sell'], False)
        return {'asks': asks, 'bids': bids}

    @classmethod
    def get_available_pairs(cls, pair_code):
        if pair_code == 'BTC-BCC':
            base_currency = 'BTC'
            market_currency = 'BCH'
        elif pair_code == 'BTC-ZEC':
            base_currency = 'BTC'
            market_currency = 'ZEC'
        else:
            assert False
        return base_currency, market_currency


Question: import logging
from quant.common import constant
from ._bitfinex import Bitfinex
from ._kkex import Kkex
from ._liqui import Liqui
from ._hitbtc import Hitbtc
from ._cex import Cex
from ._bittrex import Bittrex
from ._binance import Binance
from ._gate import Gate
from ._bitflyer import Bitflyer
from ._kraken import Kraken
from ._coinegg import Coinegg
from ._bithumb import Bithumb
from ._huobi import Huobi
#!/usr/bin/env python
# -*- coding: UTF-8 -*-




def create_markets(exchange_names):
    """
    [
        'Bitfinex_BCH_BTC'
        ...
    ]
    """
    markets = {}
    for name in exchange_names:
        if name == "%s_ETH_USD" % constant.EX_BFX:
            ex = Bitfinex('ethusd')
        elif name == "%s_ETC_BTC" % constant.EX_BFX:
            ex = Bitfinex('etcbtc')
        elif name == "%s_ETC_USD" % constant.EX_BFX:
            ex = Bitfinex('etcusd')
        elif name == "%s_ETH_BTC" % constant.EX_BFX:
            ex = Bitfinex('ethbtc')
        elif name == "%s_BCH_USD" % constant.EX_BFX:
            ex = Bitfinex('bchusd')
        elif name == "%s_ZEC_USD" % constant.EX_BFX:
            ex = Bitfinex('zecusd')
        elif name == "%s_BCH_BTC" % constant.EX_BFX:
            ex = Bitfinex('bchbtc')
        elif name == "%s_BTC_USD" % constant.EX_BFX:
            ex = Bitfinex('btcusd')
        elif name == "%s_BT1_USD" % constant.EX_BFX:
            ex = Bitfinex('bt1usd')
        elif name == "%s_BT2_USD" % constant.EX_BFX:
            ex = Bitfinex('bt2usd')
        elif name == "%s_BT1_BTC" % constant.EX_BFX:
            ex = Bitfinex('bt1btc')
        elif name == "%s_BT2_BTC" % constant.EX_BFX:
            ex = Bitfinex('bt2btc')
        elif name == "%s_EOS_USD" % constant.EX_BFX:
            ex = Bitfinex('eosusd')
        elif name == "%s_EOS_BTC" % constant.EX_BFX:
            ex = Bitfinex('eosbtc')
        elif name == "%s_EOS_ETH" % constant.EX_BFX:
            ex = Bitfinex('eoseth')
        elif name == "%s_NEO_BTC" % constant.EX_BFX:
            ex = Bitfinex('neobtc')
        elif name == "%s_NEO_ETH" % constant.EX_BFX:
            ex = Bitfinex('neoeth')
        elif name == "%s_NEO_USD" % constant.EX_BFX:
            ex = Bitfinex('neousd')
        elif name == "%s_IOT_USD" % constant.EX_BFX:
            ex = Bitfinex('iotusd')
        elif name == "%s_IOT_BTC" % constant.EX_BFX:
            ex = Bitfinex('iotbtc')
        elif name == "%s_ZRX_ETH" % constant.EX_BFX:
            ex = Bitfinex('zrxeth')
        elif name == "%s_ZRX_BTC" % constant.EX_BFX:
            ex = Bitfinex('zrxbtc')
        elif name == "%s_BCH_BTC" % constant.EX_KKEX:
            ex = Kkex('BCHBTC')
        elif name == "%s_BCC_BTC" % constant.EX_LQ:
            ex = Liqui('bcc_btc')
        elif name == "%s_BCC_ETH" % constant.EX_LQ:
            ex = Liqui('bcc_eth')
        elif name == "%s_EOS_BTC" % constant.EX_LQ:
            ex = Liqui('eos_btc')
        elif name == "%s_BCC_BTC" % constant.EX_HITBITC:

Answer:             ex = Hitbtc('bccbtc')