def QA_SU_save_okex_symbol(client=DATABASE, market="OKEx"): """ 保存OKEx交易对信息 """ print('Under construction... I will test and debug soon...') return False QA_util_log_info('Downloading {:s} symbol list...'.format(market)) # 保存 OKEx API 原始 Symbol 数据备查阅,自动交易用得着 raw_symbol_lists = QA_util_save_raw_symbols( QA_fetch_okex_symbols, market ) if (len(raw_symbol_lists) > 0): # 保存到 QUANTAXIS.crypto_asset_list 数字资产列表,为了跨市场统一查询做数据汇总 symbol_lists = pd.DataFrame(raw_symbol_lists) # market,symbol为 mongodb 索引字段,保存之前必须要检查存在 symbol_lists['market'] = market symbol_lists['category'] = 1 symbol_lists.rename( { 'baseAssetPrecision': 'price_precision', 'baseAsset': 'base_currency', 'quoteAsset': 'quote_currency', 'status': 'state', }, axis=1, inplace=True ) symbol_lists['name'] = symbol_lists.apply( lambda x: '{:s}/{:s}'. format(x['base_currency'].upper(), x['quote_currency'].upper()), axis=1 ) symbol_lists['desc'] = symbol_lists['name'] symbol_lists['created_at'] = int( time.mktime(datetime.datetime.now().utctimetuple()) ) symbol_lists['updated_at'] = int( time.mktime(datetime.datetime.now().utctimetuple()) ) # 移除非共性字段,这些字段只有 broker 才关心,做对应交易所 broker 接口的时候在交易所 raw_symbol_lists # 数据中读取。 symbol_lists.drop( [ '_id', 'price_precision', 'baseCommissionPrecision', 'quotePrecision', 'filters', 'icebergAllowed', 'isMarginTradingAllowed', 'isSpotTradingAllowed', 'ocoAllowed', 'orderTypes', 'quoteCommissionPrecision', 'quoteOrderQtyMarketAllowed', ], axis=1, inplace=True ) # 删除不交易的交易对 symbol_lists = symbol_lists[symbol_lists['state'].isin(['TRADING'])] coll_crypto_asset_list = client.crypto_asset_list coll_crypto_asset_list.create_index( [('market', pymongo.ASCENDING), ('symbol', pymongo.ASCENDING)], unique=True ) try: query_id = {'market': market} if (coll_crypto_asset_list.count_documents(query_id) > 0): # 删掉重复数据 query_id = { 'market': market, 'symbol': { '$in': symbol_lists['symbol'].tolist() } } coll_crypto_asset_list.delete_many(query_id) coll_crypto_asset_list.insert_many( QA_util_to_json_from_pandas(symbol_lists) ) return symbol_lists except: QA_util_log_expection( 'QA_SU_save_OKEx_symbol: Insert_many(symbol) to "crypto_asset_list" got Exception {}' .format(len(data)) ) pass return []
def QA_SU_save_huobi_symbol(client=DATABASE, market="huobi"): """ 保存火币交易对信息 """ QA_util_log_info('Downloading {:s} symbol list...'.format(market)) # 保存Huobi API 原始 Symbol 数据备查阅,自动交易用得着 raw_symbol_lists = QA_util_save_raw_symbols(QA_fetch_huobi_symbols, market) if (len(raw_symbol_lists) > 0): # 保存到 QUANTAXIS.crypto_asset_list 数字资产列表,为了跨市场统一查询做数据汇总 symbol_lists = pd.DataFrame(raw_symbol_lists) # market,symbol为 mongodb 索引字段,保存之前必须要检查存在 symbol_lists['market'] = market symbol_lists['category'] = 1 symbol_lists['name'] = symbol_lists.apply(lambda x: '{:s}/{:s}'.format( x['base-currency'].upper(), x['base-currency'].upper()), axis=1) symbol_lists['desc'] = symbol_lists.apply( lambda x: '现货: {:s} 兑换 {:s}'.format(x['base-currency'], x[ 'quote-currency']), axis=1) # 移除非共性字段,这些字段只有 broker 才关心,做对应交易所 broker 接口的时候在交易所 raw_symbol_lists # 数据中读取。火币网超有个性的,注意字段里面的减号,不是下划线!!! symbol_lists.drop([ '_id', 'amount-precision', 'leverage-ratio', 'max-order-amt', 'min-order-amt', 'min-order-value', 'symbol-partition', 'value-precision' ], axis=1, inplace=True) symbol_lists['created_at'] = int( time.mktime(datetime.datetime.now().utctimetuple())) symbol_lists['updated_at'] = int( time.mktime(datetime.datetime.now().utctimetuple())) coll_crypto_asset_list = client.crypto_asset_list coll_crypto_asset_list.create_index([('market', pymongo.ASCENDING), ('symbol', pymongo.ASCENDING)], unique=True) try: query_id = {'market': market} if (coll_crypto_asset_list.count_documents(query_id) > 0): # 删掉重复数据 query_id = { 'market': market, 'symbol': { '$in': symbol_lists['symbol'].tolist() } } coll_crypto_asset_list.delete_many(query_id) coll_crypto_asset_list.insert_many( QA_util_to_json_from_pandas(symbol_lists)) return symbol_lists except: QA_util_log_expection( 'QA_SU_save_huobi_symbol(): Insert_many(symbol) to "crypto_asset_list" got Exception with {} klines' .format(len(data))) pass return []
def QA_SU_save_okex_symbol( market="okex", client=DATABASE, ): """ 保存OKEx交易对信息 """ QA_util_log_info('Downloading {:s} symbol list...'.format(market)) # 保存 OKEx API 原始 Symbol 数据备查阅,自动交易用得着 raw_symbol_lists = QA_util_save_raw_symbols(QA_fetch_okex_symbols, market) if (len(raw_symbol_lists) > 0): # 保存到 QUANTAXIS.crypto_asset_list 数字资产列表,为了跨市场统一查询做数据汇总 symbol_lists = pd.DataFrame(raw_symbol_lists) # market,symbol为 mongodb 索引字段,保存之前必须要检查存在 symbol_lists['market'] = market symbol_lists['category'] = 1 symbol_lists.rename( { 'instrument_id': 'symbol', 'tick_size': 'price_precision', }, axis=1, inplace=True) symbol_lists['state'] = 'online' symbol_lists['name'] = symbol_lists.apply(lambda x: '{:s}/{:s}'.format( x['base_currency'].upper(), x['quote_currency'].upper()), axis=1) symbol_lists['desc'] = symbol_lists['name'] # 移除非共性字段,这些字段只有 broker 才关心,做对应交易所 broker 接口的时候在交易所 raw_symbol_lists # 数据中读取。 symbol_lists.drop([ 'min_size', 'size_increment', ], axis=1, inplace=True) symbol_lists['created_at'] = int( time.mktime(datetime.datetime.now().utctimetuple())) symbol_lists['updated_at'] = int( time.mktime(datetime.datetime.now().utctimetuple())) coll_crypto_asset_list = client.crypto_asset_list coll_crypto_asset_list.create_index([('market', pymongo.ASCENDING), ('symbol', pymongo.ASCENDING)], unique=True) try: query_id = {'market': market} if (coll_crypto_asset_list.count_documents(query_id) > 0): # 删掉重复数据 query_id = { 'market': market, 'symbol': { '$in': symbol_lists['symbol'].tolist() } } coll_crypto_asset_list.delete_many(query_id) coll_crypto_asset_list.insert_many( QA_util_to_json_from_pandas(symbol_lists)) return symbol_lists except: QA_util_log_expection( 'QA_SU_save_okex_symbol(): Insert_many(symbol) to "crypto_asset_list" got Exception with {} klines' .format(len(data))) pass return []
def QA_SU_save_bitmex_symbol( market=bitmex_EXCHANGE, client=DATABASE, ): """ 保存 bitmex 交易对信息 """ market = market.upper() QA_util_log_info('Downloading {:s} symbol list...'.format(market)) # 保存 bitmex API 原始 Symbol 数据备查阅,自动交易用得着 raw_symbol_lists = QA_util_save_raw_symbols(QA_fetch_bitmex_symbols, market) if (len(raw_symbol_lists) > 0): # 保存到 QUANTAXIS.crypto_asset_list 数字资产列表,为了跨市场统一查询做数据汇总 symbol_lists = pd.DataFrame(raw_symbol_lists) # market,symbol为 mongodb 索引字段,保存之前必须要检查存在 symbol_lists['market'] = market symbol_lists['category'] = symbol_lists['typ'] symbol_lists.rename( { 'rootSymbol': 'base_currency', 'quoteCurrency': 'quote_currency', }, axis=1, inplace=True) symbol_lists['price_precision'] = symbol_lists.apply( lambda x: 2 + -1 * int(math.log10(float(x.maintMargin))), axis=1) symbol_lists['name'] = symbol_lists['symbol'] symbol_lists['desc'] = '' # 移除非共性字段,这些字段只有 broker 才关心,做对应交易所 broker 接口的时候在交易所 raw_symbol_lists # 数据中读取。 symbol_lists = symbol_lists[[ 'symbol', 'name', 'market', 'state', 'category', 'base_currency', 'quote_currency', 'price_precision', 'desc' ]] if ('_id' in symbol_lists.columns.values): # 有时有,必须单独删除 symbol_lists.drop([ '_id', ], axis=1, inplace=True) symbol_lists['created_at'] = int( time.mktime(datetime.datetime.now().utctimetuple())) symbol_lists['updated_at'] = int( time.mktime(datetime.datetime.now().utctimetuple())) coll_cryptocurrency_list = client.cryptocurrency_list coll_cryptocurrency_list.create_index([('market', pymongo.ASCENDING), ('symbol', pymongo.ASCENDING)], unique=True) try: query_id = {'market': market} if (coll_cryptocurrency_list.count_documents(query_id) > 0): # 删掉重复数据 query_id = { 'market': market, 'symbol': { '$in': symbol_lists['symbol'].tolist() } } coll_cryptocurrency_list.delete_many(query_id) coll_cryptocurrency_list.insert_many( QA_util_to_json_from_pandas(symbol_lists)) return symbol_lists except: QA_util_log_expection( 'QA_SU_save_bitmex_symbol(): Insert_many(symbol) to "cryptocurrency_list" got Exception with {} klines' .format(len(symbol_lists))) pass return []