Exemple #1
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)
Exemple #2
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)
Exemple #3
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)
Exemple #4
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)
Exemple #5
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)
Exemple #6
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)
Exemple #7
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)
Exemple #8
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)
Exemple #9
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)
Exemple #10
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)
Exemple #11
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)