Ejemplo n.º 1
0
class Bithumb():
    """
    Bithumb
    https://www.bithumb.com/u1/US127
    """
    def __init__(self):
        self._http = HttpUtil()

    def ticker(self, currency):
        '''
        bithumb 거래소 마지막 거래 정보
        https://www.bithumb.com/u1/US127
        :param str currency: BTC, ETH, DASH, LTC, ETC, XRP, BCH, XMR, ZEC, QTUM, BTG, EOS, ICX, VEN, TRX, ELF, MITH, MCO, OMG, KNC, GNT, HSR, ZIL, ETHOS, PAY, WAX, POWR, LRC, GTO, STEEM, STRAT, ZRX, REP, AE, XEM, SNT, ADA (기본값: BTC), ALL(전체)
        :return: json object
        '''
        URL = 'https://api.bithumb.com/public/ticker/'
        return self._http.get(URL + currency)

    def orderbook(self, currency, group_orders=1, count=5):
        '''
        bithumb 거래소 판/구매 등록 대기 또는 거래 중 내역 정보
        https://www.bithumb.com/u1/US127
        :param str currency: BTC, ETH, DASH, LTC, ETC, XRP, BCH, XMR, ZEC, QTUM, BTG, EOS, ICX, VEN, TRX, ELF, MITH, MCO, OMG, KNC, GNT, HSR, ZIL, ETHOS, PAY, WAX, POWR, LRC, GTO, STEEM, STRAT, ZRX, REP, AE, XEM, SNT, ADA (기본값: BTC), ALL(전체)
        :param int group_orders: Value : 0 또는 1 (Default : 1)
        :param int count: Value : 1 ~ 50 (Default : 20), ALL : 1 ~ 5(Default : 5)
        :return: json object
        '''
        URL = 'https://api.bithumb.com/public/orderbook/'
        if group_orders not in [0, 1]:
            raise InvalidParamException('invalid group_orders: %d' %
                                        group_orders)
        if count < 1 or count > 50:
            raise InvalidParamException('invalid count: %d' % count)
        params = {'group_orders': group_orders, 'count': count}
        return self._http.get(URL + currency, params=params)

    def transaction_history(self, currency, cont_no=None, count=20):
        '''
        bithumb 거래소 거래 체결 완료 내역
        https://www.bithumb.com/u1/US127
        :param str currency: BTC, ETH, DASH, LTC, ETC, XRP, BCH, XMR, ZEC, QTUM, BTG, EOS, ICX, VEN, TRX, ELF, MITH, MCO, OMG, KNC, GNT, HSR, ZIL, ETHOS, PAY, WAX, POWR, LRC, GTO, STEEM, STRAT, ZRX, REP, AE, XEM, SNT, ADA (기본값: BTC)
        :param int cont_no: Value : 체결 번호
        :param int count: Value : 1 ~ 100 (Default : 20)
        :return: json object
        '''
        URL = 'https://api.bithumb.com/public/transaction_history/'
        if count < 1 or count > 100:
            raise InvalidParamException('invalid count: %d' % count)
        params = {'count': count}
        if cont_no != 0:
            params['cont_no'] = cont_no
        return self._http.get(URL + currency, params=params)
Ejemplo n.º 2
0
class Coinone():
    """
    Coinone
    https://doc.coinone.co.kr
    """
    def __init__(self):
        self._http = HttpUtil()

    def get_ticker(self, currency):
        '''
        Ticker
        https://doc.coinone.co.kr/#api-Public-Ticker
        :param str currency: default(btc), btc, bch, eth, etc, xrp, qtum, iota, ltc, btg, omg, eos, data, zil, knc, zrx, all
        :return: json object
        '''
        URL = 'https://api.coinone.co.kr/ticker/'
        params = {'currency': currency}
        return self._http.get(URL, params)

    def get_ticker_utc(self, currency):
        '''
        Ticker UTC
        https://doc.coinone.co.kr/#api-Public-Ticker_UTC
        :param str currency: default(btc), btc, bch, eth, etc, xrp, qtum, iota, ltc, btg, omg, eos, data, zil, knc, zrx, all
        :return: json object
        '''
        URL = 'https://api.coinone.co.kr/ticker/'
        params = {'currency': currency}
        return self._http.get(URL, params)

    def get_orderbook(self, currency):
        '''
        Orderbook
        https://doc.coinone.co.kr/#api-Public-Orderbook
        :param str currency: default(btc), btc, bch, eth, etc, xrp, qtum, iota, ltc, btg, omg, eos, data, zil, knc, zrx
        :return: json object
        '''
        URL = 'https://api.coinone.co.kr/orderbook/'
        params = {'currency': currency}
        return self._http.get(URL, params)

    def get_trades(self, currency, period):
        '''
        Recent Complete Orders
        https://doc.coinone.co.kr/#api-Public-RecentTransactions
        :param str currency: default(btc), btc, bch, eth, etc, xrp, qtum, iota, ltc, btg, omg, eos, data, zil, knc, zrx
        :param str period: default(hour), hour/day
        :return: json object
        '''
        URL = 'https://api.coinone.co.kr/trades/'
        params = {'currency': currency, 'period': period}
        return self._http.get(URL, params)
Ejemplo n.º 3
0
class LBank():
    """
    LBank
    https://github.com/LBank-exchange/lbank-official-api-docs
    """
    def __init__(self):
        self._http = HttpUtil()

    def get_ticker_all(self):
        '''
        Get all ticker
        https://github.com/LBank-exchange/lbank-official-api-docs/blob/master/API-For-Spot-CN/%E5%B8%81%E5%B8%81%E4%BA%A4%E6%98%93REST%20API(%E8%A1%8C%E6%83%85).md#%E5%B8%81%E5%B8%81%E8%A1%8C%E6%83%85-api
        :return: json array
        '''
        URL = 'http://api.lbank.info/v1/ticker.do'
        params = {'symbol': 'all'}
        return self._http.get(URL, params)

    def get_ticker(self, symbol):
        '''
        Get all ticker
        https://github.com/LBank-exchange/lbank-official-api-docs/blob/master/API-For-Spot-CN/%E5%B8%81%E5%B8%81%E4%BA%A4%E6%98%93REST%20API(%E8%A1%8C%E6%83%85).md#%E5%B8%81%E5%B8%81%E8%A1%8C%E6%83%85-api
        :param str symbol:
        :return: json object
        '''
        URL = 'http://api.lbank.info/v1/ticker.do'
        params = {'symbol': symbol}
        return self._http.get(URL, params)

    def get_currency_pairs(self):
        '''
        Get currency pairs
        https://github.com/LBank-exchange/lbank-official-api-docs/blob/master/API-For-Spot-CN/%E5%B8%81%E5%B8%81%E4%BA%A4%E6%98%93REST%20API(%E8%A1%8C%E6%83%85).md#%E5%B8%81%E5%B8%81%E8%A1%8C%E6%83%85-api
        :return: json array
        '''
        URL = 'http://api.lbank.info/v1/currencyPairs.do'
        return self._http.get(URL)

    def get_depth(self, symbol, size, merge=None):
        '''
        Get depth
        https://github.com/LBank-exchange/lbank-official-api-docs/blob/master/API-For-Spot-CN/%E5%B8%81%E5%B8%81%E4%BA%A4%E6%98%93REST%20API(%E8%A1%8C%E6%83%85).md#%E5%B8%81%E5%B8%81%E8%A1%8C%E6%83%85-api
        :param str symbol: symbol
        :param int size: 1-60 (default 60)
        :param int merge: 0, 1 (default 0)
        :return: json array
        '''
        URL = 'http://api.lbank.info/v1/depth.do'
        params = {'symbol': symbol, 'size': size}
        if merge is not None:
            params['merge'] = merge
        return self._http.get(URL, params)

    def get_trades(self, symbol, size, time=None):
        '''
        Get trades
        https://github.com/LBank-exchange/lbank-official-api-docs/blob/master/API-For-Spot-CN/%E5%B8%81%E5%B8%81%E4%BA%A4%E6%98%93REST%20API(%E8%A1%8C%E6%83%85).md#%E5%B8%81%E5%B8%81%E8%A1%8C%E6%83%85-api
        :param str symbol: symbol
        :param int size: 1-600 (default 600)
        :param str time:
        :return: json array
        '''
        URL = 'http://api.lbank.info/v1/trades.do'
        params = {'symbol': symbol, 'size': size}
        return self._http.get(URL, params)

    def get_kline(self, symbol, size, type, time=None):
        '''
        Get kline
        https://github.com/LBank-exchange/lbank-official-api-docs/blob/master/API-For-Spot-CN/%E5%B8%81%E5%B8%81%E4%BA%A4%E6%98%93REST%20API(%E8%A1%8C%E6%83%85).md#%E5%B8%81%E5%B8%81%E8%A1%8C%E6%83%85-api
        :param str symbol: symbol
        :param int size: 1-2880
        :param str type:
            minute1:1分钟
            minute5:5分钟
            minute15:15分钟
            minute30:30分钟
            hour1:1小时
            hour4:4小时
            hour8:8小时
            hour12:12小时
            day1:1日
            week1:1周
        :param string time:
        :return: json array
        '''
        URL = 'http://api.lbank.info/v1/kline.do'
        params = {'symbol': symbol, 'size': size, 'type': type, 'time': time}
        return self._http.get(URL, params)
Ejemplo n.º 4
0
class Bitforex():
    """
    Bitforex
    https://github.com/bitforexapi/API_Doc_en/wiki
    """

    def __init__(self):
        self._http = HttpUtil()

    def get_symbols(self):
        '''
        Symbol Information
        https://github.com/bitforexapi/API_Doc_en/wiki/Symbol-Information
        :return: json object
        '''
        URL = 'https://api.bitforex.com/api/v1/market/symbols'
        return self._http.get(URL)

    def get_ticker(self, symbol):
        '''
        Ticker Information
        https://github.com/bitforexapi/API_Doc_en/wiki/Ticker-Information
        :param str symbol: Trading pairs such as coin-usd-btc, coin-usd-eth, etc.
        :return: json object
        '''
        URL = 'https://api.bitforex.com/api/v1/market/ticker'
        params = {'symbol': symbol}
        return self._http.get(URL, params)

    def get_depth(self, symbol, size=None):
        '''
        Depth information
        https://github.com/bitforexapi/API_Doc_en/wiki/Depth-information
        :param str symbol: Trading pairs such as coin-usd-btc, coin-usd-eth, etc.
        :param int size: Orders Depth Quantity 1-200, default(5)
        :return: json object
        '''
        URL = 'https://api.bitforex.com/api/v1/market/depth'
        params = {'symbol': symbol}
        if size is not None:
            params['size'] = size
        return self._http.get(URL, params)

    def get_trades(self, symbol, size=None):
        '''
        Trading record information
        https://github.com/bitforexapi/API_Doc_en/wiki/Trading-record-information
        :param str symbol: Trading pairs such as coin-usd-btc, coin-usd-eth, etc.
        :param int size: The number of transactions is 1-600, default(1)
        :return: json object
        '''
        URL = 'https://api.bitforex.com/api/v1/market/trades'
        params = {'symbol': symbol}
        if size is not None:
            params['size'] = size
        return self._http.get(URL, params)

    def get_kline(self, symbol, ktype, size=None):
        '''
        K Line information
        https://github.com/bitforexapi/API_Doc_en/wiki/K-Line-information
        :param str symbol: Trading pairs such as coin-usd-btc, coin-usd-eth, etc.
        :param str ktype: K line type:
            1min: one minute K line
            5min: five minutes K line
            15min: 15 minutes K line
            30min: thirty minutes K line
            1hour: one hour K Line
            2hour: Two hours K line
            4hour: Four hours K line
            12hour: 12 hours K line
            1day: Daily K line
            1 week: Weekly K line
            1month: monthly K line
        :param int size: Number of K lines 1-600, default(1)
        :return: json object
        '''
        URL = 'https://api.bitforex.com/api/v1/market/kline'
        params = {'symbol': symbol, 'ktype': ktype}
        if size is not None:
            params['size'] = size
        return self._http.get(URL, params)
Ejemplo n.º 5
0
class Upbit:
    """
    Upbit
    https://docs.upbit.com/v1.0/reference
    """

    def __init__(self):
        self._http = HttpUtil()

    def get_market_all(self):
        '''
        마켓 코드 조회
        업비트에서 거래 가능한 마켓 목록
        https://docs.upbit.com/v1.0/reference#%EB%A7%88%EC%BC%93-%EC%BD%94%EB%93%9C-%EC%A1%B0%ED%9A%8C
        :return: json array
        '''
        URL = 'https://api.upbit.com/v1/market/all'
        return self._http.get(URL)

    def get_minutes_candles(self, unit, market, to=None, count=None):
        '''
        분(Minute) 캔들
        https://docs.upbit.com/v1.0/reference#%EB%B6%84minute-%EC%BA%94%EB%93%A4-1
        :param int unit: 분 단위. 가능한 값 : 1, 3, 5, 15, 10, 30, 60, 240
        :param str market: 마켓 코드 (ex. KRW-BTC, BTC-BCC)
        :param str to: 마지막 캔들 시각 (exclusive). 포맷 : yyyy-MM-dd'T'HH:mm:ssXXX. 비워서 요청시 가장 최근 캔들
        :param int count: 캔들 개수
        :return: json array
        '''
        URL = 'https://api.upbit.com/v1/candles/minutes/%s' % str(unit)
        if unit not in [1, 3, 5, 10, 15, 30, 60, 240]:
            raise InvalidParamException('invalid unit: %s' % str(unit))

        params = {'market': market}
        if to is not None:
            params['to'] = to
        if count is not None:
            params['count'] = count
        return self._http.get(URL, params=params)

    def get_days_candles(self, market, to=None, count=None):
        '''
        일(Day) 캔들
        https://docs.upbit.com/v1.0/reference#%EC%9D%BCday-%EC%BA%94%EB%93%A4-1
        :param str market: 마켓 코드 (ex. KRW-BTC, BTC-BCC)
        :param str to: 마지막 캔들 시각 (exclusive). 포맷 : yyyy-MM-dd'T'HH:mm:ssXXX. 비워서 요청시 가장 최근 캔들
        :param int count: 캔들 개수
        :return: json array
        '''
        URL = 'https://api.upbit.com/v1/candles/days'
        params = {'market': market}
        if to is not None:
            params['to'] = to
        if count is not None:
            params['count'] = count
        return self._http.get(URL, params=params)

    def get_weeks_candles(self, market, to=None, count=None):
        '''
        주(Weeks) 캔들
        https://docs.upbit.com/v1.0/reference#%EC%A3%BCweek-%EC%BA%94%EB%93%A4-1
        :param str market: 마켓 코드 (ex. KRW-BTC, BTC-BCC)
        :param str to: 마지막 캔들 시각 (exclusive). 포맷 : yyyy-MM-dd'T'HH:mm:ssXXX. 비워서 요청시 가장 최근 캔들
        :param int count: 캔들 개수
        :return: json array
        '''
        URL = 'https://api.upbit.com/v1/candles/weeks'
        params = {'market': market}
        if to is not None:
            params['to'] = to
        if count is not None:
            params['count'] = count
        return self._http.get(URL, params=params)

    def get_months_candles(self, market, to=None, count=None):
        '''
        월(Months) 캔들
        https://docs.upbit.com/v1.0/reference#%EC%9B%94month-%EC%BA%94%EB%93%A4-1
        :param str market: 마켓 코드 (ex. KRW-BTC, BTC-BCC)
        :param str to: 마지막 캔들 시각 (exclusive). 포맷 : yyyy-MM-dd'T'HH:mm:ssXXX. 비워서 요청시 가장 최근 캔들
        :param int count: 캔들 개수
        :return: json array
        '''
        URL = 'https://api.upbit.com/v1/candles/months'
        params = {'market': market}
        if to is not None:
            params['to'] = to
        if count is not None:
            params['count'] = count
        return self._http.get(URL, params=params)

    def get_trades_ticks(self, market, to=None, count=None, cursor=None):
        '''
        당일 체결 내역
        https://docs.upbit.com/v1.0/reference#%EC%8B%9C%EC%84%B8-%EC%B2%B4%EA%B2%B0-%EC%A1%B0%ED%9A%8C
        :param str market: 마켓 코드 (ex. KRW-BTC, BTC-BCC)
        :param str to: 마지막 체결 시각. 형식 : [HHmmss 또는 HH:mm:ss]. 비워서 요청시 가장 최근 데이터
        :param int count: 체결 개수
        :param str cursor: 페이지네이션 커서 (sequentialId)
        :return: json array
        '''
        URL = 'https://api.upbit.com/v1/trades/ticks'
        params = {'market': market}
        if to is not None:
            params['to'] = to
        if count is not None:
            params['count'] = count
        if cursor is not None:
            params['cursor'] = cursor
        return self._http.get(URL, params=params)

    def get_ticker(self, markets):
        '''
        현재가 정보
        요청 당시 종목의 스냅샷을 반환한다.
        https://docs.upbit.com/v1.0/reference#%EC%8B%9C%EC%84%B8-ticker-%EC%A1%B0%ED%9A%8C
        :param str[] markets: 반점으로 구분되는 마켓 코드 (ex. KRW-BTC, BTC-BCC)
        :return: json array
        '''
        URL = 'https://api.upbit.com/v1/ticker'
        if not isinstance(markets, list):
            raise InvalidParamException(
                'invalid parameter: markets should be list')

        if len(markets) == 0:
            raise InvalidParamException('invalid parameter: no markets')

        markets_data = markets[0]
        for market in markets[1:]:
            markets_data += ',%s' % market
        params = {'markets': markets_data}
        return self._http.get(URL, params=params)

    def get_orderbook(self, markets):
        '''
        호가 정보 조회
        https://docs.upbit.com/v1.0/reference#%ED%98%B8%EA%B0%80-%EC%A0%95%EB%B3%B4-%EC%A1%B0%ED%9A%8C
        :param str[] markets: 마켓 코드 목록 (ex. KRW-BTC,KRW-ADA)
        :return: json array
        '''
        URL = 'https://api.upbit.com/v1/orderbook?'
        if not isinstance(markets, list):
            raise InvalidParamException(
                'invalid parameter: markets should be list')

        if len(markets) == 0:
            raise InvalidParamException('invalid parameter: no markets')

        markets_data = markets[0]
        for market in markets[1:]:
            markets_data += ',%s' % market
        params = {'markets': markets_data}
        return self._http.get(URL, params=params)
Ejemplo n.º 6
0
class Gopax():
    """
    Gopax
    https://www.gopax.co.kr/API
    """
    def __init__(self):
        self._http = HttpUtil()

    def get_asset(self):
        '''
        1. 자산 조회하기
        https://www.gopax.co.kr/API
        :return: json array
        '''
        URL = 'https://api.gopax.co.kr/assets'
        return self._http.get(URL)

    def get_trading_pairs(self):
        '''
        2. 특정 거래쌍 조회하기
        https://www.gopax.co.kr/API
        :return: json array
        '''
        URL = 'https://api.gopax.co.kr/trading-pairs'
        return self._http.get(URL)

    def get_ticker(self, pair):
        '''
        3. 특정 거래쌍의 거래량 조회하기
        https://www.gopax.co.kr/API
        :param str pair: currency pair
        :return: json object
        '''
        URL = 'https://api.gopax.co.kr/trading-pairs/%s/ticker' % pair
        return self._http.get(URL)

    def get_book(self, pair, level):
        '''
        4. 특정 거래쌍의 호가창 조회하기
        https://www.gopax.co.kr/API
        :param str pair: currency pair
        :parm int level: 호가창의 상세정보 수준 (1 = 매수호가 및 매도호가, 2 = 매수 및 매도 주문 각 50개, 기타 = 호가창 전체)
        :return: json object
        '''
        URL = 'https://api.gopax.co.kr/trading-pairs/%s/book' % pair
        params = {'level': level}
        return self._http.get(URL, params)

    def get_trades(self,
                   pair,
                   limit=None,
                   pastmax=None,
                   latestmin=None,
                   after=None,
                   before=None):
        '''
        5. 최근 체결 내역 조회하기
        https://www.gopax.co.kr/API
        :param str pair: currency pair
        :parm int limit: 반환되는 항목의 갯수 (최대 100)
        :parm int pastmax: 이 ID보다 오래된 데이터를 제외함
        :parm int latestmin: 이 ID보다 새로운 최신 데이터를 가져옴
        :parm int after: 이 타임스탬프 이후의 데이터를 제외함 (ms 단위)
        :parm int before: 이 타임스탬프 이전의 데이터를 제외함 (ms 단위)
        :return: json object
        '''
        URL = 'https://api.gopax.co.kr/trading-pairs/%s/trades' % pair
        params = {}
        if limit is not None:
            params['limit'] = limit
        if pastmax is not None:
            params['pastmax'] = pastmax
        if latestmin is not None:
            params['latestmin'] = latestmin
        if after is not None:
            params['after'] = after
        if before is not None:
            params['before'] = before
        return self._http.get(URL, params)

    def get_stats(self, pair):
        '''
        6. 특정 거래쌍의 최근 24시간 통계 조회하기
        https://www.gopax.co.kr/API
        :param str pair: currency pair
        :return: json object
        '''
        URL = 'https://api.gopax.co.kr/trading-pairs/%s/stats' % pair
        return self._http.get(URL)

    def get_candles(self, pair, interval, start=None, end=None):
        '''
        7. 특정 거래쌍의 과거 기록 조회하기
        # 동작 안됨
        https://www.gopax.co.kr/API
        :param str pair: currency pair
        :param int interval: 희망하는 시간 간격 (분 단위, 1/5/30/1440)
        :param int start: 시작 시점 (ms단위)
        :param int end: 종료 시점 (ms단위)
        :return: json object
        '''
        URL = 'https://api.gopax.co.kr/trading-pairs/%s/candles' % pair
        params = {}
        if start is not None:
            params['start'] = start
        if end is not None:
            params['end'] = end
        if interval is not None:
            params['interval'] = interval
        return self._http.get(URL, params)

    def get_all_stats(self):
        '''
        8. 모든 거래쌍의 최근 24시간 통계 조회하기
        https://www.gopax.co.kr/API
        :return: json object
        '''
        URL = 'https://api.gopax.co.kr/trading-pairs/stats'
        return self._http.get(URL)
Ejemplo n.º 7
0
class Huobi():
    """
    Huobi Pro
    https://github.com/huobiapi/API_Docs_en/wiki
    """

    def __init__(self):
        self._http = HttpUtil()

    def get_history_kline(self, symbol, period, size=None):
        '''
        Get Candlestick Data
        https://github.com/huobiapi/API_Docs_en/wiki/REST_Reference#get-markethistorykline--get-candlestick-data
        :param str symbol: trading asset, btcusdt, bccbtc, rcneth ...
        :param str period: 1min, 5min, 15min, 30min, 60min, 1day, 1mon, 1week, 1year
        :param integer size: default(150), [1,2000]
        :return: json object
        '''
        URL = 'https://api.huobi.pro/market/history/kline'
        params = {
            'symbol': symbol,
            'period': period
        }
        if size is not None:
            params['size'] = size
        return self._http.get(URL, params)

    def get_market_detail_merged(self, symbol):
        '''
        Get Ticker
        https://github.com/huobiapi/API_Docs_en/wiki/REST_Reference#get-marketdetailmerged-get-ticker
        :param str symbol: trading asset, btcusdt, bccbtc, rcneth ...
        :return: json object
        '''
        URL = 'https://api.huobi.pro/market/detail/merged'
        params = {'symbol': symbol}
        return self._http.get(URL, params)

    def get_market_tickers(self):
        '''
        Get Tickers
        https://github.com/huobiapi/API_Docs_en/wiki/REST_Reference#get-markettickers
        :return: json object
        '''
        URL = 'https://api.huobi.pro/market/tickers'
        return self._http.get(URL)

    def get_market_depth(self, symbol, type):
        '''
        Market Depth
        https://github.com/huobiapi/API_Docs_en/wiki/REST_Reference#get-marketdepth---market-depth
        :param str symbol: trading asset, btcusdt, bccbtc, rcneth ...
        :param str type: Depth data type, step0, step1, step2, step3, step4, step5
        :return: json object
        '''
        URL = 'https://api.huobi.pro/market/depth'
        params = {
            'symbol': symbol,
            'type': type
        }
        return self._http.get(URL, params)

    def get_market_trade(self, symbol):
        '''
        Trade Detail
        https://github.com/huobiapi/API_Docs_en/wiki/REST_Reference#get-markettrade--trade-detail
        :param str symbol: trading asset, btcusdt, bccbtc, rcneth ...
        :return: json object
        '''
        URL = 'https://api.huobi.pro/market/trade'
        params = {'symbol': symbol}
        return self._http.get(URL, params)

    def get_market_history_trade(self, symbol, size=None):
        '''
        Orderbook
        https://github.com/huobiapi/API_Docs_en/wiki/REST_Reference#get-markethistorytrade-orderbook
        :param str symbol: trading asset, btcusdt, bccbtc, rcneth ...:param:
        :param int size: default(1), [1, 2000]
        :return: json object
        '''
        URL = 'https://api.huobi.pro/market/history/trade'
        params = {'symbol': symbol}
        if size is not None:
            params['size'] = size
        return self._http.get(URL, params)

    def get_market_detail(self, symbol):
        '''
        Market detail in 24 hours
        https://github.com/huobiapi/API_Docs_en/wiki/REST_Reference#get-marketdetail---market-detail-in-24-hours
        :param str symbol: trading asset, btcusdt, bccbtc, rcneth ...:param:
        :return: json object
        '''
        URL = 'https://api.huobi.pro/market/detail'
        params = {'symbol': symbol}
        return self._http.get(URL, params)

    def get_symbols(self):
        '''
        Get all the trading assets in huobi.pro
        https://github.com/huobiapi/API_Docs_en/wiki/REST_Reference#get-v1commonsymbols-----get-all-the-trading-assets-in-huobipro
        :return: json object
        '''
        URL = 'https://api.huobi.pro/v1/common/symbols'
        return self._http.get(URL)

    def get_currencys(self):
        '''
        Get currencys supported in huobi.pro
        https://github.com/huobiapi/API_Docs_en/wiki/REST_Reference#get-v1commoncurrencys-----get-currencys-supported-in-huobipro
        :return: json object
        '''
        URL = 'https://api.huobi.pro/v1/common/currencys'
        return self._http.get(URL)

    def get_timestamp(self):
        '''
        Get system timestamp
        https://github.com/huobiapi/API_Docs_en/wiki/REST_Reference#get-v1commontimestamp----get-system-timestamp
        :return: json object
        '''
        URL = 'https://api.huobi.pro/v1/common/timestamp'
        return self._http.get(URL)
Ejemplo n.º 8
0
class Bitflyer():
    """
    Bitflyer
    https://lightning.bitflyer.com/docs?lang=en
    """
    def __init__(self):
        self._http = HttpUtil()

    def get_markets(self):
        '''
        Market List
        https://lightning.bitflyer.com/docs?lang=en#market-list
        :return: json array
        '''
        URL = 'https://api.bitflyer.com/v1/markets'
        return self._http.get(URL)

    def get_orderbook(self, product_code):
        '''
        Order Book
        https://lightning.bitflyer.com/docs?lang=en#order-book
        :param str product_code: Please specify a product_code or alias, as obtained from the Market List. If omitted, the value is set to "BTC_JPY". Only "BTC_USD" is available for U.S. accounts, and only "BTC_EUR" is available for European accounts.
        :return: json object
        '''
        URL = 'https://api.bitflyer.com/v1/board'
        params = {'product_code': product_code}
        return self._http.get(URL, params)

    def get_ticker(self, product_code):
        '''
        Ticker
        https://lightning.bitflyer.com/docs?lang=en#ticker
        :param str product_code: Please specify a product_code or alias, as obtained from the Market List. If omitted, the value is set to "BTC_JPY". Only "BTC_USD" is available for U.S. accounts, and only "BTC_EUR" is available for European accounts.
        :return: json object
        '''
        URL = 'https://api.bitflyer.com/v1/ticker'
        params = {'product_code': product_code}
        return self._http.get(URL, params)

    def get_executions(self,
                       product_code,
                       count=None,
                       before=None,
                       after=None):
        '''
        Execution History
        https://lightning.bitflyer.com/docs?lang=en#execution-history
        :param str product_code: Please specify a product_code or alias, as obtained from the Market List. If omitted, the value is set to "BTC_JPY". Only "BTC_USD" is available for U.S. accounts, and only "BTC_EUR" is available for European accounts.
        :param int count: Specifies the number of results. If this is omitted, the value will be 100.
        :param int before: Obtains data having an id lower than the value specified for this parameter.
        :param int after: Obtains data having an id higher than the value specified for this parameter.
        :return: json array
        '''
        URL = 'https://api.bitflyer.com/v1/executions'
        params = {'product_code': product_code}
        if count is not None:
            params['count'] = count
        if before is not None:
            params['before'] = before
        if after is not None:
            params['after'] = after
        return self._http.get(URL, params)

    def get_exchange_status(self,
                            product_code,
                            count=None,
                            before=None,
                            after=None):
        '''
        Exchange status
        https://lightning.bitflyer.com/docs?lang=en#exchange-status
        :param str product_code: Please specify a product_code or alias, as obtained from the Market List. If omitted, the value is set to "BTC_JPY". Only "BTC_USD" is available for U.S. accounts, and only "BTC_EUR" is available for European accounts.
        :return: json object
        '''
        URL = 'https://api.bitflyer.com/v1/gethealth'
        params = {'product_code': product_code}
        return self._http.get(URL, params)
Ejemplo n.º 9
0
class Bitfinex():
    """
    Bitfinex
    https://bitfinex.readme.io/v1/reference
    """
    def __init__(self):
        self._http = HttpUtil()

    def get_ticker(self, symbol):
        '''
        Ticker
        The ticker is a high level overview of the state of the market. It shows you the current best bid and ask, as well as the last trade price. It also includes information such as daily volume and how much the price has moved over the last day.
        https://bitfinex.readme.io/v1/reference#rest-public-ticker
        :param str symbol: The symbol you want information about. You can find the list of valid symbols by calling the /symbols endpoint.
        :return: json object
        '''
        URL = 'https://api.bitfinex.com/v1/ticker/'
        return self._http.get(URL + symbol)

    def get_stats(self, symbol):
        '''
        Stats
        Various statistics about the requested pair.
        https://bitfinex.readme.io/v1/reference#rest-public-stats
        :param str symbol: The symbol you want information about. You can find the list of valid symbols by calling the /symbols endpoint.
        :return: json array
        '''
        URL = 'https://api.bitfinex.com/v1/stats/'
        return self._http.get(URL + symbol)

    # https://bitfinex.readme.io/v1/reference#rest-public-fundingbook
    def get_fundingbook(self,
                        currency='USD',
                        limit_bids=None,
                        limit_asks=None):
        '''
        Fundingbook
        Get the full margin funding book
        https://bitfinex.readme.io/v1/reference#rest-public-fundingbook
        :param str currency:
        :param int limit_bids: Default(50), Limit the number of funding bids returned. May be 0 in which case the array of bids is empty
        :param int limit_asks: Default(50), Limit the number of funding offers returned. May be 0 in which case the array of asks is empty
        :return: json object
        '''
        URL = 'https://api.bitfinex.com/v1/lendbook/'
        params = {}
        if limit_asks is not None:
            params['limit_asks'] = limit_asks
        if limit_bids is not None:
            params['limit_bids'] = limit_bids
        return self._http.get(URL + currency, params)

    # https://bitfinex.readme.io/v1/reference#rest-public-orderbook
    def get_orderbook(self,
                      symbol,
                      limit_bids=None,
                      limit_asks=None,
                      group=None):
        '''
        Orderbook
        Get the full order book.
        https://bitfinex.readme.io/v1/reference#rest-public-orderbook
        :param str symbol:
        :param int limit_bids: Default(50), Limit the number of bids returned. May be 0 in which case the array of bids is empty
        :param int limit_asks: Default(50), Limit the number of asks returned. May be 0 in which case the array of asks is empty
        :param int group: Default(1), If 1, orders are grouped by price in the orderbook. If 0, orders are not grouped and sorted individually
        :return: json object
        '''
        URL = 'https://api.bitfinex.com/v1/book/'
        params = {}
        if limit_bids is not None:
            params['limit_bids'] = limit_bids
        if limit_asks is not None:
            params['limit_asks'] = limit_asks
        if group is not None:
            params['group'] = group
        return self._http.get(URL + symbol, params)

    def get_trades(self, symbol, timestamp=None, limit_trades=None):
        '''
        Trades
        Get a list of the most recent trades for the given symbol.
        https://bitfinex.readme.io/v1/reference#rest-public-trades
        :param str symbol:
        :param time timestamp: Only show trades at or after this timestamp
        :param int limit_trades: Default(50), Limit the number of trades returned. Must be >= 1
        :return: json array
        '''
        URL = 'https://api.bitfinex.com/v1/trades/'
        params = {}
        if timestamp is not None:
            params['timestamp'] = timestamp
        if limit_trades is not None:
            params['limit_trades'] = limit_trades
        return self._http.get(URL + symbol, params)

    def get_lends(self, currency='USD', timestamp=None, limit_lends=None):
        '''
        Lends
        Get a list of the most recent funding data for the given currency: total amount provided and Flash Return Rate (in % by 365 days) over time.
        https://bitfinex.readme.io/v1/reference#rest-public-lends
        :param str currency:
        :param time timestamp: Only show data at or after this timestamp
        :param int limit_lends: Default(50), Limit the amount of funding data returned. Must be >= 1
        :return: json array
        '''
        URL = 'https://api.bitfinex.com/v1/lends/'
        params = {}
        if timestamp is not None:
            params['timestamp'] = timestamp
        if limit_lends is not None:
            params['limit_lends'] = limit_lends
        return self._http.get(URL + currency, params)

    def get_symbols(self):
        '''
        Symbols
        A list of symbol names.
        https://bitfinex.readme.io/v1/reference#rest-public-symbols
        :return: json array
        '''
        URL = 'https://api.bitfinex.com/v1/symbols'
        return self._http.get(URL)

    def get_symbol_details(self):
        '''
        Symbol Details
        Get a list of valid symbol IDs and the pair details.
        https://bitfinex.readme.io/v1/reference#rest-public-symbol-details
        :return: json array
        '''
        URL = 'https://api.bitfinex.com/v1/symbols_details'
        return self._http.get(URL)
Ejemplo n.º 10
0
class Bibox:
    """
    Bibox
    https://github.com/Biboxcom/api_reference/wiki/home_en
    """
    def __init__(self):
        self._http = HttpUtil()

    def get_pair_list(self):
        '''
        get pair list
        https://github.com/Biboxcom/api_reference/wiki/home_en#323-v1mdata
        :return: json object
        '''
        URL = 'https://api.bibox.com/v1/mdata'
        params = {'cmd': 'pairList'}
        return self._http.get(URL, params)

    def get_kline(self, pair, period, size=None):
        '''
        get K line
        https://github.com/Biboxcom/api_reference/wiki/home_en#323-v1mdata
        :param str pair: pairs, exmple: BIX_BTC
        :param str period: k line period,value ['1min', '3min', '5min', '15min', '30min', '1hour', '2hour', '4hour', '6hour', '12hour', 'day', 'week']
        :param int size: how many,1-1000,if not passed will return 1000
        :return: json object
        '''
        URL = 'https://api.bibox.com/v1/mdata'
        params = {'cmd': 'kline', 'pair': pair, 'period': period}
        if size is not None:
            params['size'] = size
        return self._http.get(URL, params)

    def get_depth(self, pair, size=None):
        '''
        get depth
        https://github.com/Biboxcom/api_reference/wiki/home_en#323-v1mdata
        :param str pair: pairs,example: BIX_BTC
        :param int size: how many,1-200,if not passed will return 200
        :return: json object
        '''
        URL = 'https://api.bibox.com/v1/mdata'
        params = {'cmd': 'depth', 'pair': pair}
        if size is not None:
            params['size'] = size
        return self._http.get(URL, params)

    def get_trade_history(self, pair, size=None):
        '''
        get trade history
        https://github.com/Biboxcom/api_reference/wiki/home_en#323-v1mdata
        :param str pair: pairs,example: BIX_BTC
        :param int size: how many,1-200,if not passed will return 200
        :return: json object
        '''
        URL = 'https://api.bibox.com/v1/mdata'
        params = {'cmd': 'deals', 'pair': pair}
        if size is not None:
            params['size'] = size
        return self._http.get(URL, params)

    def get_ticker(self, pair):
        '''
        get ticker
        https://github.com/Biboxcom/api_reference/wiki/home_en#323-v1mdata
        :param str pair: pairs,example: BIX_BTC
        :return: json object
        '''
        URL = 'https://api.bibox.com/v1/mdata'
        params = {'cmd': 'ticker', 'pair': pair}
        return self._http.get(URL, params)

    def get_market_all(self):
        '''
        get market data (all pairs)
        https://github.com/Biboxcom/api_reference/wiki/home_en#323-v1mdata
        :return: json object
        '''
        URL = 'https://api.bibox.com/v1/mdata'
        params = {'cmd': 'marketAll'}
        return self._http.get(URL, params)

    def get_market(self, pair):
        '''
        get market
        https://github.com/Biboxcom/api_reference/wiki/home_en#323-v1mdata
        :param str pair: pairs,example: BIX_BTC
        :return: json object
        '''
        URL = 'https://api.bibox.com/v1/mdata'
        params = {'cmd': 'market', 'pair': pair}
        return self._http.get(URL, params)
Ejemplo n.º 11
0
class Coinbene:
    """
    Coinbene
    https://github.com/Coinbene/API-Documents/wiki/0.0.0-Coinbene-API-documents
    """
    def __init__(self):
        self._http = HttpUtil()

    def get_symbols(self):
        '''
        Get Symbols
        https://github.com/Coinbene/API-Documents/wiki/1.1.3-Get-Symbols-%5BMarket%5D
        :return: json object
        '''
        URL = 'http://api.coinbene.com/v1/market/symbol'
        return self._http.get(URL)

    def get_ticker_all(self):
        '''
        Get ticker (all)
        https://github.com/Coinbene/API-Documents/wiki/1.1.0-Get-Ticker-%5BMarket%5D
        :return: json object
        '''
        URL = 'http://api.coinbene.com/v1/market/ticker'
        params = {'symbol': 'all'}
        return self._http.get(URL, params)

    def get_ticker(self, symbol):
        '''
        Get ticker
        https://github.com/Coinbene/API-Documents/wiki/1.1.0-Get-Ticker-%5BMarket%5D
        :param str symbol: the code of symbol
        :return: json object
        '''
        URL = 'http://api.coinbene.com/v1/market/ticker'
        params = {'symbol': symbol}
        return self._http.get(URL, params)

    def get_orderbook(self, symbol, depth=None):
        '''
        Get Orderbook
        https://github.com/Coinbene/API-Documents/wiki/1.1.1-Get-Orderbook-%5BMarket%5D
        :param str symbol: the code of symbol
        :param int depth: the number of orders, default = 200, 1 to 500
        :return: json object
        '''
        URL = 'http://api.coinbene.com/v1/market/orderbook'
        params = {'symbol': symbol}
        if depth is not None:
            params['depth'] = depth
        return self._http.get(URL, params)

    def get_trades(self, symbol, size=None):
        '''
        Get Trades
        https://github.com/Coinbene/API-Documents/wiki/1.1.2-Get-Trades-%5BMarket%5D
        :param str symbol: the code of symbol
        :param int size: The number of trade records, sorted by time reverse order. Default = 300, 1 to 2000
        :return: json object
        '''
        URL = 'http://api.coinbene.com/v1/market/trades'
        params = {'symbol': symbol}
        if size is not None:
            params['size'] = size
        return self._http.get(URL, params)
Ejemplo n.º 12
0
class OKEx():
    """
    OKEx Spot
    https://github.com/okcoin-okex/API-docs-OKEx.com
    """

    def __init__(self):
        self._http = HttpUtil()

    def get_pairs(self):
        URL = 'https://raw.githubusercontent.com/okcoin-okex/API-docs-OKEx.com/master/%E5%B8%81%E5%AF%B9%E7%B2%BE%E5%BA%A6(pairs_increment).csv'
        return self._http.get_raw(URL)

    def get_ticker(self, symbol, contract_type=None):
        '''
        Get Price Ticker
        https://github.com/okcoin-okex/API-docs-OKEx.com/blob/master/API-For-Spot-EN/REST%20API%20for%20SPOT.md#spot-price-api
        :param str symbol: Pairs like : ltc_btc etc_btc
        :param str contract_type: this_week next_week quarter
        :return: json object
        '''
        URL = 'https://www.okex.com/api/v1/ticker.do'
        params = {
            'symbol': symbol
        }
        if contract_type is not None:
            params['contract_type'] = contract_type
        return self._http.get(URL, params=params)

    def get_depth(self, symbol, size=None):
        '''
        Get Market Depth
        https://github.com/okcoin-okex/API-docs-OKEx.com/blob/master/API-For-Spot-EN/REST%20API%20for%20SPOT.md#spot-price-api
        :param str symbol: Pairs like : ltc_btc etc_btc
        :param int size: value: must be between 1 - 200
        :return: json object
        '''
        URL = 'https://www.okex.com/api/v1/depth.do'
        params = {
            'symbol': symbol
        }
        if size is not None:
            params['size'] = size
        return self._http.get(URL, params=params)

    def get_trades(self, symbol, since=None):
        '''
        Get Trade Recently 600
        https://github.com/okcoin-okex/API-docs-OKEx.com/blob/master/API-For-Spot-EN/REST%20API%20for%20SPOT.md#spot-price-api
        :param str symbol: Pairs like : ltc_btc etc_btc
        :param int since: value: get recently 600 pieces of data starting from the given tid (optional)
        :return: json array
        '''
        URL = 'https://www.okex.com/api/v1/trades.do'
        params = {'symbol': symbol}
        if since is not None:
            params['since'] = since
        return self._http.get(URL, params=params)

    def get_kline(self, symbol, type, size=None, since=None):
        '''
        Get Candlestick Data
        https://github.com/okcoin-okex/API-docs-OKEx.com/blob/master/API-For-Spot-EN/REST%20API%20for%20SPOT.md#spot-price-api
        :param str symbol: Pairs like : ltc_btc etc_btc
        :param str type: 1min/3min/5min/15min/30min/1day/3day/1week/1hour/2hour/4hour/6hour/12hour
        :param int size: specify data size to be acquired
        :param int since: timestamp(eg:1417536000000). data after the timestamp will be returned
        '''
        URL = 'https://www.okex.com/api/v1/kline.do'
        params = {
            'symbol': symbol,
            'type': type
        }
        if size is not None:
            params['size'] = size
        if since is not None:
            params['since'] = since
        return self._http.get(URL, params=params)
Ejemplo n.º 13
0
class ZB():
    """
    ZB
    https://www.zb.com/i/developer/restApi
    """
    def __init__(self):
        self._http = HttpUtil()

    def get_markets(self):
        '''
        Get the enabled market information ( price, number of decimal places)
        https://www.zb.com/i/developer/restApi#config
        :return: json object
        '''
        URL = 'http://api.zb.cn/data/v1/markets'
        return self._http.get(URL)

    def get_all_ticker(self):
        '''
        All Ticker
        https://www.zb.com/i/developer/restApi#market
        :return: json object
        '''
        URL = 'http://api.zb.cn/data/v1/allTicker'
        return self._http.get(URL)

    def get_ticker(self, market):
        '''
        Price
        https://www.zb.com/i/developer/restApi#market
        :param str market: ex) btc_usdt
        :return: json object
        '''
        URL = 'http://api.zb.cn/data/v1/ticker'
        params = {'market': market}
        return self._http.get(URL, params)

    def get_depth(self, market, size=None):
        '''
        Market depth
        https://www.zb.com/i/developer/restApi#market
        :param str market: ex) btc_usdt
        :param int size: Positions are from 1-50, if there is a combination of depth, only return 5 positions depth
        :return: json object
        '''
        URL = 'http://api.zb.cn/data/v1/depth'
        params = {'market': market}
        if size is not None:
            params['size'] = size
        return self._http.get(URL, params)

    def get_trades(self, market, since=None):
        '''
        Get history trade data
        https://www.zb.com/i/developer/restApi#market
        :param str market: ex) btc_usdt
        :param int since: 50 items after designate transaction ID
        :return: json object
        '''
        URL = 'http://api.zb.cn/data/v1/trades'
        params = {'market': market}
        if since is not None:
            params['since'] = since
        return self._http.get(URL, params)

    def get_kline(self, market, type=None, since=None, size=None):
        '''
        K line
        https://www.zb.com/i/developer/restApi#market
        :param str market: ex) btc_usdt
        :param str type:
            1min
            3min
            5min
            15min
            30min
            1day
            3day
            1week
            1hour
            2hour
            4hour
            6hour
            12hour
        :param int since: From this timestamp
        :param int size: Limit of returning data(default 1000,it only return 1000 data if that more than 1000 date )
        :return: json object
        '''
        URL = 'http://api.zb.cn/data/v1/kline'
        params = {'market': market}
        if type is not None:
            params['type'] = type
        if since is not None:
            params['since'] = since
        if size is not None:
            params['size'] = size
        return self._http.get(URL, params)
Ejemplo n.º 14
0
 def __init__(self):
     self._http = HttpUtil()
Ejemplo n.º 15
0
class CoinbasePro:
    """
    Coinbase Pro
    https://docs.pro.coinbase.com/
    """

    def __init__(self):
        self._http = HttpUtil()

    def get_products(self):
        '''
        Get Products
        Get a list of available currency pairs for trading.
        https://docs.pro.coinbase.com/#get-products
        :return: json array
        '''
        URL = 'https://api.pro.coinbase.com/products'
        return self._http.get(URL)

    def get_product_order_book(self, id, level=None):
        '''
        Get Product Order Book
        Get a list of open orders for a product. The amount of detail shown can be customized with the level parameter.
        https://docs.pro.coinbase.com/#get-product-order-book
        :param str id: product id
        :param int level: default(1), Select response detail. Valid levels are documented below
            1	Only the best bid and ask
            2	Top 50 bids and asks (aggregated)
            3	Full order book (non aggregated)
        :return: json object
        '''
        URL = 'https://api.pro.coinbase.com/products/%s/book' % id
        params = {}
        if level is not None:
            params['level'] = level
        return self._http.get(URL, params)

    def get_product_ticker(self, id):
        '''
        Get Product Ticker
        Snapshot information about the last trade (tick), best bid/ask and 24h volume.
        https://docs.pro.coinbase.com/#get-product-ticker
        :param str id: product id
        :return: json object
        '''
        URL = 'https://api.pro.coinbase.com/products/%s/ticker' % id
        return self._http.get(URL)

    def get_trades(self, id):
        '''
        Get Product Trades
        List the latest trades for a product.
        https://docs.pro.coinbase.com/#get-trades
        :param str id: product id
        :return: json array
        '''
        URL = 'https://api.pro.coinbase.com/products/%s/trades' % id
        return self._http.get(URL)

    def get_historical_rates(self, id, start=None, end=None, granularity=None):
        '''
        Get Historic Rates
        Historic rates for a product. Rates are returned in grouped buckets based on requested granularity.
        https://docs.pro.coinbase.com/#get-historic-rates
        :param str id: product id
        :param str start: Start time in ISO 8601
        :param str end: End time in ISO 8601
        :param int granularity: Desired timeslice in seconds
            The granularity field must be one of the following values:
            {60, 300, 900, 3600, 21600, 86400}.
            Otherwise, your request will be rejected.
            These values correspond to timeslices representing one minute,
            five minutes, fifteen minutes, one hour, six hours, and one day, respectively.
        '''
        URL = 'https://api.pro.coinbase.com/products/%s/candles' % id
        params = {}
        if start is not None:
            params['start'] = start
        if end is not None:
            params['end'] = end
        if granularity is not None:
            params['granularity'] = granularity
        return self._http.get(URL, params)

    def get_24hr_stats(self, id):
        '''
        Get 24hr Stats
        Get 24 hr stats for the product. volume is in base currency units. open, high, low are in quote currency units.
        https://docs.pro.coinbase.com/#get-24hr-stats
        :param str id: product id
        :return: json object
        '''
        URL = 'https://api.pro.coinbase.com/products/%s/stats' % id
        return self._http.get(URL)

    def get_currencies(self):
        '''
        Get currencies
        List known currencies.
        https://docs.pro.coinbase.com/#get-currencies
        :return: json array
        '''
        URL = 'https://api.pro.coinbase.com/currencies'
        return self._http.get(URL)

    def get_time(self):
        '''
        Get the API server time.
        https://docs.pro.coinbase.com/#time
        :return: json object
        '''
        URL = 'https://api.pro.coinbase.com/time'
        return self._http.get(URL)
Ejemplo n.º 16
0
class Binance:
    """
    Binance
    https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
    """
    def __init__(self):
        self._http = HttpUtil()

    def get_ping(self):
        '''
        Test connectivity
        Test connectivity to the Rest API.
        https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#test-connectivity
        :return: json object
        '''
        URL = 'https://api.binance.com/api/v1/ping'
        return self._http.get(URL)

    def get_time(self):
        '''
        Check server time
        Test connectivity to the Rest API and get the current server time.
        https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#check-server-time
        :return: json object
        '''
        URL = 'https://api.binance.com/api/v1/time'
        return self._http.get(URL)

    def get_exchange_info(self):
        '''
        Exchange information
        Current exchange trading rules and symbol information
        https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#exchange-information
        :return: json object
        '''
        URL = 'https://api.binance.com/api/v1/exchangeInfo'
        return self._http.get(URL)

    def get_orderbook(self, symbol, limit=None):
        '''
        Order book
        https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#order-book
        Caution: setting limit=0 can return a lot of data.
        :param str symbol:
        :param int limit: Default 100; max 1000. Valid limits:[5, 10, 20, 50, 100, 500, 1000]
        :return: json object
        '''
        URL = 'https://api.binance.com/api/v1/depth'
        if limit is not None and limit not in [5, 10, 20, 50, 100, 500, 1000]:
            raise InvalidParamException('invalid unit: %d' % limit)

        params = {'symbol': symbol}
        if limit is not None:
            params['limit'] = limit
        return self._http.get(URL, params=params)

    def get_trades(self, symbol, limit=None):
        '''
        Recent trades list
        Get recent trades (up to last 500).
        https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#recent-trades-list
        :param str symbol:
        :param int limit: Default 500; max 1000
        :return: json array
        '''
        URL = 'https://api.binance.com/api/v1/trades'
        params = {'symbol': symbol}
        if limit is not None:
            params['limit'] = limit
        return self._http.get(URL, params=params)

    def get_agg_trades(self,
                       symbol,
                       from_id=None,
                       start_time=None,
                       end_time=None,
                       limit=None):
        '''
        Compressed/Aggregate trades list
        Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.
        https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#compressedaggregate-trades-list
        :param str symbol:
        :param long from_id: ID to get aggregate trades from INCLUSIVE.
        :param long start_time: Timestamp in ms to get aggregate trades from INCLUSIVE.
        :param long end_time: Timestamp in ms to get aggregate trades until INCLUSIVE.
        :param int limit: Default 500; max 1000.
        :return: json array
        '''
        URL = 'https://api.binance.com/api/v1/aggTrades'
        params = {'symbol': symbol}
        if from_id is not None:
            params['fromId'] = from_id
        if start_time is not None:
            params['startTime'] = start_time
        if end_time is not None:
            params['endTime'] = end_time
        if limit is not None:
            params['limit'] = limit
        return self._http.get(URL, params=params)

    def get_klines(self,
                   symbol,
                   interval,
                   start_time=None,
                   end_time=None,
                   limit=None):
        '''
        Kline/Candlestick data
        Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
        https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#klinecandlestick-data
        :param str symbol:
        :param str interval: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#enum-definitions
        :param long start_time: Timestamp in ms to get aggregate trades from INCLUSIVE.
        :param long end_time: Timestamp in ms to get aggregate trades until INCLUSIVE.
        :param int limit: Default 500; max 1000.
        :return: json array
        '''
        URL = 'https://api.binance.com/api/v1/klines'

        if interval not in [
                '1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '8h',
                '12h', '1d', '3d', '1w', '1M'
        ]:
            raise InvalidParamException('invalid interval: %s' % interval)

        params = {'symbol': symbol, 'interval': interval}
        if start_time is not None:
            params['startTime'] = start_time
        if end_time is not None:
            params['endTime'] = end_time
        if limit is not None:
            params['limit'] = limit
        return self._http.get(URL, params=params)

    def get_24h_ticker(self, symbol=None):
        '''
        24hr ticker price change statistics
        24 hour price change statistics. Careful when accessing this with no symbol.
        https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#24hr-ticker-price-change-statistics
        :param str symbol:
        :return: json array (symbol is None), json object (symbol is not None)
        '''
        URL = 'https://api.binance.com/api/v1/ticker/24hr'
        params = {}
        if symbol is not None:
            params['symbol'] = symbol
        return self._http.get(URL, params=params)

    def get_ticker_price(self, symbol=None):
        '''
        Symbol price ticker
        Latest price for a symbol or symbols.
        https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#symbol-price-ticker
        :param str symbol:
        :return: json array (symbol is None), json object (symbol is not None)
        '''
        URL = 'https://api.binance.com/api/v3/ticker/price'
        params = {}
        if symbol is not None:
            params['symbol'] = symbol
        return self._http.get(URL, params=params)

    def get_ticker_book(self, symbol=None):
        '''
        Symbol order book ticker
        Best price/qty on the order book for a symbol or symbols.
        https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#symbol-order-book-ticker
        :param str symbol:
        :return: json array (symbol is None), json object (symbol is not None)
        '''
        URL = 'https://api.binance.com/api/v3/ticker/bookTicker'
        params = {}
        if symbol is not None:
            params['symbol'] = symbol
        return self._http.get(URL, params=params)
Ejemplo n.º 17
0
class CoinEx:
    """
    CoinEx
    https://github.com/coinexcom/coinex_exchange_api/wiki
    """

    def __init__(self):
        self._http = HttpUtil()

    def get_market_list(self):
        '''
        Acquire Market List
        https://github.com/coinexcom/coinex_exchange_api/wiki/020market
        :return: json object
        '''
        URL = 'https://api.coinex.com/v1/market/list'
        return self._http.get(URL)

    def get_ticker(self, market):
        '''
        Acquire Market Statistics
        https://github.com/coinexcom/coinex_exchange_api/wiki/021ticker#acquire-market-statistics
        :param str market:
        :return: json object
        '''
        URL = 'https://api.coinex.com/v1/market/ticker'
        params = {'market': market}
        return self._http.get(URL, params)

    def get_depth(self, market, merge, limit=None):
        '''
        Acquire Market Depth
        https://github.com/coinexcom/coinex_exchange_api/wiki/022depth#acquire-market-depth
        :param str market:
        :param str merge: '0', '0.1', '0.01', '0.001', '0.0001', '0.00001', '0.000001', '0.0000001', '0.00000001
        :param int limit: Return amount,range: 5/10/20
        :return: json object
        '''
        URL = 'https://api.coinex.com/v1/market/depth'
        params = {
            'market': market,
            'merge': merge
        }
        if limit is not None:
            params['limit'] = limit
        return self._http.get(URL, params)

    def get_deals(self, market, last_id=None):
        '''
        Acquire Latest Transaction Data
        https://github.com/coinexcom/coinex_exchange_api/wiki/023deals#acquire-latest-transaction-data
        :param str market:
        :param int last_id: Transaction history id, send 0 to draw from the latest record.
        :return: json object
        '''
        URL = 'https://api.coinex.com/v1/market/deals'
        params = {
            'market': market
        }
        if last_id is not None:
            params['last_id'] = last_id
        return self._http.get(URL, params)

    def get_kline(self, market, type, limit=None):
        '''
        Acquire K-Line Data
        https://github.com/coinexcom/coinex_exchange_api/wiki/024kline#acquire-k-line-data
        :param str market:
        :param str type:
            1min:1min;
            3min:3min;
            5min:5min;
            15min:15min;
            30min:30min;
            1hour:1hour;
            2hour:2hour;
            4hour:4hour;
            6hour:6hour;
            12hour:12hour;
            1day:1day;
            3day:3day;
            1week:1week;
        :param int limit: Less than or equal to 1000
        '''
        URL = 'https://api.coinex.com/v1/market/kline'
        params = {
            'market': market,
            'type': type
        }
        if limit is not None:
            params['limit'] = limit
        return self._http.get(URL, params)