def __init__(self, api_key, secret_key): # 赋值 字符串 self.name = 'qianqiancelue' + '20200105' # 实例化一个外部类 需要传入一个字典 dict {} self.api = ccxt.fcoin({'apiKey': api_key, 'secret': secret_key}) # 声明列表 list [] self.orders_id = [] # 往列表添加元素 self.orders_id.append(str(666)) self.orders_id.append(int('888')) # for 循环遍历 同时 赋值 for item in self.orders_id: print(item) # '666' 888 # 删除元素 del (self.orders_id[1]) # delete 888 del (self.orders_id[0]) # delete '666' # 赋值 整型 self._time_interval = 10
import time import ccxt import matplotlib.pyplot as plt import logging n_states = pow(3, 7) # 环境状态个数 actions = ['buy', 'sell', 'wait'] epsilon = 0.9 # 贪心率 alpha = 0.1 # 学习速率 越大学习越快 但有可能很容易记住噪音特征 gamma = 0.9 # 折扣因子 越大越信任己有经验,越小越看重每次奖励 max_epsilon = 3 # 最大学习回合数 api_key = 'c778848925934310a15db6755659c4af' secret_key = 'd7c9a9a9ced84200afe4f51a8e1bdc01' exchange = ccxt.fcoin({"apiKey": api_key, "secret": secret_key}) amount = 0.01 fee = 0 symbol = 'BTC/USDT' period = 60 # 创建Qtable def build_q_table(n_states, actions): table = pd.DataFrame( np.zeros((n_states, len(actions))), columns=actions, ) print(table) return table
newline='') write = csv.writer(file, dialect='excel') for i in range(len(data)): write.writerow(data.iloc[i]) file.close() time.sleep(1) if __name__ == '__main__': obj_list = [ ccxt.okex(), ccxt.huobipro(), ccxt.binance(), ccxt.bitmax(), ccxt.fcoin(), ccxt.upbit() ] file = open('config.txt', 'r') config = json.loads(file.read()) file.close() mkdir(config['name_list']) time_info = get_time_info(config['name_list'], config['symbol_list']) info_queue = Queue() for obj, name in zip(obj_list, config['name_list']): crawl = CrawlInfo(obj, info_queue, name, config['symbol_list']) crawl.start() for i in range(3): Parse_thread = Parse(info_queue) Parse_thread.start() Update_thread = Update()
import ccxt import pandas as pd pd.set_option('expand_frame_repr', False) symbol = "NEWOS/ETH" apiKey = '1ca4c9f5f5bf45b4a984fee9cc392dae' secret = '2f3abdb44cc341088383d91e08e689ef' fcoin = ccxt.fcoin({'apiKey': apiKey, 'secret': secret}) if __name__ == '__main__': data = fcoin.fetch_balance() balances = data['info']['data'] for balance in balances: if balance['currency'] == 'newos' or balance['currency'] == 'eth': print(balance)
console.setLevel(logging.DEBUG) formatter = logging.Formatter('[%(asctime)s] %(message)s') handler = logging.FileHandler("btc_%s.txt" % time.strftime("%Y-%m-%d %H-%M-%S")) handler.setLevel(logging.DEBUG) handler.setFormatter(formatter) logger.addHandler(console) logger.addHandler(handler) f = open('accounts.txt') lines = f.readlines() acct_id = int(lines[-1]) api_key = lines[acct_id*2 - 2].strip('\n') seceret_key = lines[acct_id*2 - 1].strip('\n') fcoin = Fcoin() fcoin.auth(api_key, seceret_key) # fcoin.margin_buy('ethusdt', 0.01, 10) ex0 = ccxt.fcoin() ex1 = ccxt.okex3() ex2 = ccxt.binance() ex3 = ccxt.huobipro() type = 'limit' trend = 0 trend_0, trend_1, trend_2, trend_3, trend_cmb = [], [], [], [], [] pre_price_0 = 0 pre_price_1, score_1 = 0, 0 pre_price_2, score_2 = 0, 0 pre_price_3, score_3 = 0, 0 pre_price_4, score_4 = 0, 0 pre_price_5, score_5 = 0, 0 pre_price_cmb, score_cmb = 0, 0 buy_id = [] sell_id = []
logger.info("btc机会来了 %s %s" % (ft_usdt_askOne, 1.01 * ft_btc_bidOne * btc_usdt_bidOne)) trade(exchange, 'BTC/USDT', btc_usdt_bidOne, ft_btc_bidOne, ft_usdt_askOne) else: logger.info("%s %s" % (ft_usdt_askOne, 1.01 * ft_btc_bidOne * btc_usdt_bidOne)) def trade(exchange, symbol, bidOne, bidTwo, askOne): # firstly buy btc or eth using usdt, freeAmount = exchange.fetch_balance()['USDT']['free'] tradeAmount = min(min(bidOne, bidTwo, askOne), freeAmount) order = exchange.create_market_buy_order('BTC/USDT', tradeAmount) count = 0 orderStatus = '' while count < 5: orderStatus = fcoin.fetch_order(order['id'], 'BTC/USDT')['status'] if orderStatus != 'closed': time.sleep(50) count += 1 else: break if count == 5: print('order can not be closed, exceed max retry count') fcoin = ccxt.fcoin({'apiKey': '40', 'secret': 'b9'}) print(fcoin.fetch_balance()['USDT']['free']) sameExchangseAlg(fcoin)