def get_symbols(): """ :return: """ url = MARKET_URL + '/v1/common/symbols' params = {} return http_get_request(url, params)
def get_detail(symbol): """ :param symbol: 可选值:{ ethcny } :return: """ params = {'symbol': symbol} url = MARKET_URL + '/market/detail' return http_get_request(url, params)
def get_price(symbol): """ :param symbol: symbol STRING 全大写 :return: """ params = {'symbol': symbol} url = BA_MARKET_URL + '/api/v3/ticker/price' return http_get_request(url, params)
def get_coin_price_api(self, symbol): #_symbol = symbol.upper(symbol.strip(symbol)) _symbol = symbol.strip().upper() coin_market = OK_COIN_MARKET_USDT.get(_symbol) _data = {'symbol': _symbol} if coin_market: _symbol = coin_market _data = {'symbol': coin_market} objs = http_get_request(self.homeUrl, _data) """ { "date":"1410431279", "ticker":{ "buy":"33.15", "high":"34.15", "last":"33.15", "low":"32.05", "sell":"33.16", "vol":"10532696.39199642" } } """ _map = " exchange:okex\n symbol:%s" % _symbol if objs: if ('status' in objs) and (objs['status'] != 'ok'): return 'cannot query the price of %s from okex' % coin_market if 'ticker' in objs: jsonobj = objs['ticker'] if 'last' in jsonobj: _tmp = "\n price:%s" % jsonobj['last'] _map = _map + _tmp if 'buy' in jsonobj: _tmp = "\n buy:%s" % jsonobj['buy'] _map = _map + _tmp if 'sell' in jsonobj: _tmp = "\n sell:%s" % jsonobj['sell'] _map = _map + _tmp if 'high' in jsonobj: _tmp = "\n high_24h:%s" % jsonobj['high'] _map = _map + _tmp if 'low' in jsonobj: _tmp = "\n low_24h:%s" % jsonobj['low'] _map = _map + _tmp if 'vol' in jsonobj: _tmp = "\n vol_24h:%s" % jsonobj['vol'] _map = _map + _tmp if 'date' in objs: _time = objs['date'] _map = _map + "\n time:%s" % (time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime(long(_time)))) return _map return "cannot query the price of %s from okex" % _symbol else: return "cannot query the price of %s from okex" % _symbol
def get_depth(symbol, type): """ :param symbol: :param type: 可选值:{ percent10, step0, step1, step2, step3, step4, step5 } :return: """ params = {'symbol': symbol, 'type': type} url = MARKET_URL + '/market/depth' return http_get_request(url, params)
def get_kline(symbol, period, size): """ :param symbol :param period: 可选值:{1min, 5min, 15min, 30min, 60min, 1day, 1mon, 1week, 1year } :param size: [1,2000] :return: """ params = {'symbol': symbol, 'period': period, 'size': size} url = MARKET_URL + '/market/history/kline' return http_get_request(url, params)
def api_key_get(params, request_path): method = 'GET' timestamp = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S') params.update({'AccessKeyId': ACCESS_KEY, 'SignatureMethod': 'HmacSHA256', 'SignatureVersion': '2', 'Timestamp': timestamp}) host_name = host_url = TRADE_URL host_name = urlparse.urlparse(host_url).hostname host_name = host_name.lower() params['Signature'] = createSign(params, method, host_name, request_path, SECRET_KEY) url = host_url + request_path return http_get_request(url, params)