Esempio n. 1
0
 def get_kline(self, symbol, timeframe):
     """获取市场K线信息
     时间间隔(分钟制:1m,5m,15m,30m,60m。小时制:1h,天制:1d,月制:1M)
     """
     interval = 0
     symbol = symbol
     if "m" in timeframe:
         interval = get_cur_timestamp() - 60 * int(
             timeframe.split("m")[0]) * 300
     elif "h" in timeframe:
         interval = get_cur_timestamp() - 60 * int(
             timeframe.split("h")[0]) * 60 * 300
         print(interval)
     elif "d" in timeframe:
         interval = get_cur_timestamp() - 60 * int(
             timeframe.split("d")[0]) * 24 * 60 * 300
     params = {
         'market': symbol,
         'interval': timeframe,
         'startTime': interval,
         'limit': 1000
     }
     url = ROOT_URL + '/open/api/v1/data/kline'
     response = requests.request('GET', url, params=params, headers=headers)
     return response.json()
Esempio n. 2
0
 def get_kline(self, symbol, interval):
     """
     查询K线数据
     :param symbol:"BTCUSD"
     :param interval:"1m" "3m" "1h" "12" "1d"
     :return:
     """
     m, t = "", 0
     if interval == "1m":
         m = "1"
         t = 1
     elif interval == "3m":
         m = "3"
         t = 3
     elif interval == "5m":
         m = "5"
         t = 5
     elif interval == "15m":
         m = "15"
         t = 15
     elif interval == "30m":
         m = "30"
         t = 30
     elif interval == "1h":
         m = "60"
         t = 60
     elif interval == "2h":
         m = "120"
         t = 120
     elif interval == "4h":
         m = "240"
         t = 240
     elif interval == "6h":
         m = "360"
         t = 360
     elif interval == "12h":
         m = "720"
         t = 720
     elif interval == "1d":
         m = "D"
         t = 1440
     params = {
         "symbol": symbol,
         "interval": m,
         "from": get_cur_timestamp() - 60 * 200 * t
     }
     url = self.__url + "/v2/public/kline/list"
     data = self.http_get_request(url, params)
     kline = []
     for item in data['result']:
         kline.append([
             float(item['open_time']),
             float(item['open']),
             float(item['high']),
             float(item['low']),
             float(item['close']),
             float(item['volume'])
         ])
     kline.reverse()
     return kline