print (okcoinSpot.ticker('btc_usd')) print (u' 现货深度 ') print (okcoinSpot.depth('btc_usd')) print (u' 现货历史交易信息 ') print (okcoinSpot.trades('btc_usd',0)) print (u'期货交易记录信息') print (okcoinFuture.future_trades('ltc_usd','this_week',0)) ''' print(u'期货分钟日线数据') print(okcoinFuture.future_kline('btc_usd', '1min', 'this_week', 0, 0)) print(u' it has done the job') print(okcoinSpot.kline('btc_usd', '1min', 0, 0)) #print (u' 用户现货账户信息 ') #print (okcoinSpot.userinfo()) #print (u' 现货下单 ') #print (okcoinSpot.trade('ltc_usd','buy','0.1','0.2')) #print (u' 现货批量下单 ') #print (okcoinSpot.batchTrade('ltc_usd','buy','[{price:0.1,amount:0.2},{price:0.1,amount:0.2}]')) #print (u' 现货取消订单 ') #print (okcoinSpot.cancelOrder('ltc_usd','18243073')) #print (u' 现货订单信息查询 ') #print (okcoinSpot.orderinfo('ltc_usd','18243644'))
okcoinRESTURL = 'www.okcoin.com' #请求注意:国内账号需要 修改为 www.okcoin.cn #现货API okcoinSpot = OKCoinSpot(okcoinRESTURL, apikey, secretkey) #期货API okcoinFuture = OKCoinFuture(okcoinRESTURL, apikey, secretkey) print(u' 现货行情 ') print(okcoinSpot.ticker('btc_usd')) print(u' 现货深度 ') print(okcoinSpot.depth('btc_usd')) print('kline') print(okcoinSpot.kline('gsc_eth', '1min')) #print (u' 现货历史交易信息 ') #print (okcoinSpot.trades()) #print (u' 用户现货账户信息 ') #print (okcoinSpot.userinfo()) #print (u' 现货下单 ') #print (okcoinSpot.trade('ltc_usd','buy','0.1','0.2')) #print (u' 现货批量下单 ') #print (okcoinSpot.batchTrade('ltc_usd','buy','[{price:0.1,amount:0.2},{price:0.1,amount:0.2}]')) #print (u' 现货取消订单 ') #print (okcoinSpot.cancelOrder('ltc_usd','18243073'))
from OkcoinFutureAPI import OKCoinFuture #初始化apikey,secretkey,url okcoinRESTURL = 'www.okcoin.com' #请求注意:国内账号需要 修改为 www.okcoin.cn #现货API okcoinSpot = OKCoinSpot(okcoinRESTURL, apikey, secretkey) #期货API okcoinFuture = OKCoinFuture(okcoinRESTURL, apikey, secretkey) print(u' 现货行情 ') print(okcoinSpot.ticker('btc_usd')) print(u' 现货k线历史行情 ') print(okcoinSpot.kline('btc_usd', '30min', '2000')) #print (u' 现货深度 ') #print (okcoinSpot.depth('btc_usd')) #print (u' 现货历史交易信息 ') #print (okcoinSpot.trades()) #print (u' 用户现货账户信息 ') #print (okcoinSpot.userinfo()) #print (u' 现货下单 ') #print (okcoinSpot.trade('ltc_usd','buy','0.1','0.2')) #print (u' 现货批量下单 ') #print (okcoinSpot.batchTrade('ltc_usd','buy','[{price:0.1,amount:0.2},{price:0.1,amount:0.2}]'))
first_trade_error = open(first_trade_file_error, 'r') except Exception: first_trade_file = open(first_trade_file_log, 'w') first_trade_error = open(first_trade_file_error, 'a+') else: first_trade_file.close() first_trade_error.close() first_trade_file = open(first_trade_file_log, 'w') first_trade_error = open(first_trade_file_error, 'a+') #print (u' 现货K line ') while True: error_count = 0 try: kline_now = (okcoinSpot.kline(size=4)) break except Exception as e: #print (error_count) error_count += 1 pass since_now=kline_now[2][0] #print (since_now) count=0 while count >= 0: min1_dist = 60 - int(time.time()) % 60 - 5 if min1_dist > 0: time.sleep(min1_dist) error_count = 0 while True: try:
#初始化apikey,secretkey,url #apikey = 'd8da16f9-a531-4853-b9ee-ab07927c4fef' #secretkey = '4752BE55655A6233A7254628FB7E9F50' #okcoinRESTURL = 'www.okcoin.com' #请求注意:国内账号需要 修改为 www.okcoin.cn apikey = 'fd07e7f8-519a-4ba3-8289-af9881181a96' secretkey = 'E0EACE4FB14A8CBDFE271E87D6FA2B6C' okcoinRESTURL = 'www.okcoin.cn' #现货API okcoinSpot = OKCoinSpot(okcoinRESTURL, apikey, secretkey) #期货API okcoinFuture = OKCoinFuture(okcoinRESTURL, apikey, secretkey) #print (u'K线信息') print(okcoinSpot.kline('btc_cny')) #print (u' 现货行情 ') #print (okcoinSpot.ticker('btc_usd')) #print (u' 现货深度 ') #print (okcoinSpot.depth('btc_usd')) #print (u' 现货历史交易信息 ') #print (okcoinSpot.trades()) #print (u' 用户现货账户信息 ') #print (okcoinSpot.userinfo()) #print (u' 现货下单 ') #print (okcoinSpot.trade('ltc_usd','buy','0.1','0.2'))
okcoinRESTURL = 'www.okex.com' #请求注意:国内账号需要 修改为 www.okcoin.cn #现货API okcoinSpot = OKCoinSpot(okcoinRESTURL,apikey,secretkey) #期货API okcoinFuture = OKCoinFuture(okcoinRESTURL,apikey,secretkey) #print (u' 现货行情 ') #print (okcoinSpot.ticker('btc_usdt')) #print (u' 现货深度 ') #print (okcoinSpot.depth('btc_usdt')) print (u' K线数据 ') print (okcoinSpot.kline(symbol='btc_usdt',type_='1day')) #print (u' 现货历史交易信息 ') #print (okcoinSpot.trades()) #print (u' 用户现货账户信息 ') #print (okcoinSpot.userinfo()) #print (u' 现货下单 ') #print (okcoinSpot.trade('ltc_usd','buy','0.1','0.2')) #print (u' 现货批量下单 ') #print (okcoinSpot.batchTrade('ltc_usd','buy','[{price:0.1,amount:0.2},{price:0.1,amount:0.2}]')) #print (u' 现货取消订单 ')
class Kline(object): __my_future_client = None __my_spot_client = None __mydb = None def __init__(self, dbconfig, credential): self.__my_future_client = OKCoinFuture(credential['okcoinRESTURL'], credential['apikey'], credential['secretkey']) self.__my_spot_client = OKCoinSpot(credential['okcoinRESTURL'], credential['apikey'], credential['secretkey']) self.__mydb = MySQL(dbconfig['host'], dbconfig['user'], dbconfig['passwd'], dbconfig['db']) def collect_future_kline(self, symbol, type, contract_type): max_timestamp = self.__mydb.get_max_timestamp(symbol, type, 0, contract_type) hjson = self.__my_future_client.future_kline(symbol, type, contract_type, 0, max_timestamp) collected = 0 for i in range(0, len(hjson)): timestamp = hjson[i][0] open = hjson[i][1] high = hjson[i][2] low = hjson[i][3] close = hjson[i][4] amount = hjson[i][5] amount_in_coin = hjson[i][6] dateArray = datetime.datetime.fromtimestamp(timestamp / 1000) otherStyleTime = dateArray.strftime("%Y-%m-%d %H:%M:%S") if timestamp > max_timestamp: self.__mydb.insert_kline(otherStyleTime, type, open, high, low, close, amount, symbol, 0, amount_in_coin, contract_type) collected = collected + 1 print(symbol + ' ' + type + ' ' + contract_type + ' future kline history' + ' is done! collected ' + str(collected) + ' records!') ##end of def def collect_spot_kline(self, symbol, type): spot = 1 since = 0 max_timestamp = self.__mydb.get_max_timestamp(symbol, type, spot) hjson = self.__my_spot_client.kline(symbol, type, since, max_timestamp) collected = 0 for i in range(0, len(hjson)): timestamp = hjson[i][0] open = hjson[i][1] high = hjson[i][2] low = hjson[i][3] close = hjson[i][4] amount = hjson[i][5] dateArray = datetime.datetime.fromtimestamp(timestamp / 1000) otherStyleTime = dateArray.strftime("%Y-%m-%d %H:%M:%S") if timestamp > max_timestamp: self.__mydb.insert_kline(otherStyleTime, type, open, high, low, close, amount, symbol, spot) collected = collected + 1 print(symbol + ' ' + type + ' spot kline history' + ' is done! collected ' + str(collected) + ' records!')
#初始化apikey,secretkey,url #apikey = 'd8da16f9-a531-4853-b9ee-ab07927c4fef' #secretkey = '4752BE55655A6233A7254628FB7E9F50' #okcoinRESTURL = 'www.okcoin.com' #请求注意:国内账号需要 修改为 www.okcoin.cn apikey = 'fd07e7f8-519a-4ba3-8289-af9881181a96' secretkey = 'E0EACE4FB14A8CBDFE271E87D6FA2B6C' okcoinRESTURL = 'www.okcoin.cn' #现货API okcoinSpot = OKCoinSpot(okcoinRESTURL,apikey,secretkey) #期货API okcoinFuture = OKCoinFuture(okcoinRESTURL,apikey,secretkey) #print (u'K线信息') print (okcoinSpot.kline('btc_cny')) #print (u' 现货行情 ') #print (okcoinSpot.ticker('btc_usd')) #print (u' 现货深度 ') #print (okcoinSpot.depth('btc_usd')) #print (u' 现货历史交易信息 ') #print (okcoinSpot.trades()) #print (u' 用户现货账户信息 ') #print (okcoinSpot.userinfo()) #print (u' 现货下单 ') #print (okcoinSpot.trade('ltc_usd','buy','0.1','0.2'))
okcoinRESTURL = 'www.okex.com' #请求注意:国内账号需要 修改为 www.okcoin.cn #现货API okcoinSpot = OKCoinSpot(okcoinRESTURL, apikey, secretkey) #期货API okcoinFuture = OKCoinFuture(okcoinRESTURL, apikey, secretkey) #print (u' 现货行情 ') #print (okcoinSpot.ticker('btc_usdt')) #print (u' 现货深度 ') #print (okcoinSpot.depth('btc_usdt')) print('显示最后5条日线数据:') klines = okcoinSpot.kline(symbol='eth_usdt', type_='1day') for kl in klines[-5:]: print('utc:{}, bjt:{} {}'.format(datetime.utcfromtimestamp(kl[0] / 1e3), datetime.fromtimestamp(kl[0] / 1e3), kl)) print('显示最后5条12小时线数据:') klines = okcoinSpot.kline(symbol='eth_usdt', type_='12hour') for kl in klines[-5:]: print('utc:{}, bjt:{} {}'.format(datetime.utcfromtimestamp(kl[0] / 1e3), datetime.fromtimestamp(kl[0] / 1e3), kl)) print('显示最后5条6小时线数据:') klines = okcoinSpot.kline(symbol='eth_usdt', type_='6hour') for kl in klines[-5:]: print('utc:{}, org:{} {}'.format(datetime.utcfromtimestamp(kl[0] / 1e3), datetime.fromtimestamp(kl[0] / 1e3), kl))