def get_kline(self, time_frame): if time_frame == '1m' or time_frame == '1M': period = '1min' elif time_frame == '5m' or time_frame == '5M': period = '5min' elif time_frame == '15m' or time_frame == '15M': period = '15min' elif time_frame == '30m' or time_frame == '30M': period = '30min' elif time_frame == '1h' or time_frame == '1H': period = '60min' elif time_frame == '4h' or time_frame == '4H': period = '4hour' elif time_frame == '1d' or time_frame == '1D': period = '1day' else: raise KlineError( "交易所: Huobi k线周期错误,k线周期只能是【1m, 5m, 15m, 30m, 1h, 4h, 1d】!") records = self.__huobi_swap.get_contract_kline(self.__instrument_id, period=period)['data'] list = [] for item in records: item = [ ts_to_utc_str(item['id']), item['open'], item['high'], item['low'], item['close'], item['vol'], round(item['amount'], 2) ] list.append(item) list.reverse() return list
def get_kline(self, time_frame): if time_frame == '1m' or time_frame == '1M': period = '1min' elif time_frame == '5m' or time_frame == '5M': period = '5min' elif time_frame == '15m' or time_frame == '15M': period = '15min' elif time_frame == '30m' or time_frame == '30M': period = '30min' elif time_frame == '1h' or time_frame == '1H': period = '60min' elif time_frame == '4h' or time_frame == '4H': period = '4hour' elif time_frame == '1d' or time_frame == '1D': period = '1day' else: return ( "【交易提醒】交易所: Huobi k线周期错误,k线周期只能是【1m, 5m, 15m, 30m, 1h, 4h, 1d】之一" ) records = self.__huobi_spot.get_kline(self.__instrument_id, period=period)['data'] length = len(records) j = 1 list = [] while j < length: for item in records: item = [ ts_to_utc_str(item['id']), item['open'], item['high'], item['low'], item['close'], item['vol'], round(item['amount'], 2) ] list.append(item) j += 1 return list
def get_last_kline(symbol): """获取24hr 价格变动情况""" params = {"symbol": symbol} data = request("GET", "/api/v3/ticker/24hr", params) timestamp = ts_to_utc_str(float(data["closeTime"]) / 1000) open = data["openPrice"] high = data["highPrice"] low = data["lowPrice"] close = data["lastPrice"] volume = data["volume"] last_kline = [timestamp, open, high, low, close, volume] return last_kline
def get_kline(self, time_frame): """ 币安USDT合约获取k线数据 :param time_frame: k线周期。1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M :return:返回一个列表,包含开盘时间戳、开盘价、最高价、最低价、收盘价、成交量。 """ receipt = self.__binance_swap.klines(self.__instrument_id, time_frame) # 获取历史k线数据 for item in receipt: item[0] = ts_to_utc_str(int(item[0])/1000) item.pop(6) item.pop(7) item.pop(8) item.pop(6) item.pop(7) item.pop(6) receipt.reverse() return receipt