def bat(timeout): _time1 = datetime.datetime.now() from QUANTAXIS.QAFetch.QAQuery_Advance import QA_fetch_stock_block_adv code = QA_fetch_stock_block_adv().code print(len(code)) x = QA_Tdx_Executor(timeout=timeout) print(x._queue.qsize()) print(x.get_available()) database = DATABASE.get_collection('realtime_{}'.format( datetime.date.today())) print(database) database.create_index([('code', QA_util_sql_mongo_sort_ASCENDING), ('datetime', QA_util_sql_mongo_sort_ASCENDING)]) for i in range(100000): _time = datetime.datetime.now() if QA_util_if_tradetime(_time): # 如果在交易时间 data = x.get_realtime_concurrent(code) data[0]['datetime'] = data[1] x.save_mongo(data[0]) print('Time {}'.format( (datetime.datetime.now() - _time).total_seconds())) time.sleep(1) print('Connection Pool NOW LEFT {} Available IP'.format( x._queue.qsize())) print('Program Last Time {}'.format( (datetime.datetime.now() - _time1).total_seconds())) else: print('Not Trading time {}'.format(_time)) time.sleep(1)
def run(self): sleep = int(self.sleep_time) _time1 = datetime.datetime.now() database = DATABASE.get_collection('realtime_{}'.format( datetime.date.today())) database.create_index([('code', QA_util_sql_mongo_sort_ASCENDING)]) database.create_index([('datetime', QA_util_sql_mongo_sort_ASCENDING)]) from QUANTAXIS.QAFetch.QAQuery_Advance import QA_fetch_stock_block_adv code = QA_fetch_stock_block_adv().code while True: _time = datetime.datetime.now() if QA_util_if_tradetime(_time): # 如果在交易时间 data = x.get_realtime_concurrent(code) data[0]['datetime'] = data[1] x.save_mongo(data[0]) print('Time {}'.format( (datetime.datetime.now() - _time).total_seconds())) time.sleep(sleep) print('Connection Pool NOW LEFT {} Available IP'.format( x._queue.qsize())) print('Program Last Time {}'.format( (datetime.datetime.now() - _time1).total_seconds())) else: print('Not Trading time {}'.format(_time)) time.sleep(sleep)
def bat(): _time1 = datetime.datetime.now() from QUANTAXIS.QAFetch.QAQuery_Advance import QA_fetch_stock_block_adv code = QA_fetch_stock_block_adv().code print(len(code)) x = QA_Tdx_Executor() print(x._queue.qsize()) print(x.get_available()) database = DATABASE.get_collection( 'realtime_{}'.format(datetime.date.today())) print(database) database.create_index([('code', QA_util_sql_mongo_sort_ASCENDING), ('datetime', QA_util_sql_mongo_sort_ASCENDING)]) for i in range(100000): _time = datetime.datetime.now() if QA_util_if_tradetime(_time): # 如果在交易时间 data = x.get_realtime_concurrent(code) data[0]['datetime'] = data[1] x.save_mongo(data[0]) print('Time {}'.format( (datetime.datetime.now() - _time).total_seconds())) time.sleep(1) print('Connection Pool NOW LEFT {} Available IP'.format( x._queue.qsize())) print('Program Last Time {}'.format( (datetime.datetime.now() - _time1).total_seconds())) else: print('Not Trading time {}'.format(_time)) time.sleep(1)
def get(self): try: code = self.get_argument('code', default='000001')[0:6] database = DATABASE.get_collection( 'realtime_{}'.format(datetime.date.today())) current = [QA_util_dict_remove_key(item, '_id') for item in database.find({'code': code}, limit=1, sort=[ ('datetime', pymongo.DESCENDING)])] self.write(current[0]) except: self.write('wrong')
def bat(timeout=0.2, sleep=1, thread=2, size=80): sleep = int(sleep) _time1 = datetime.datetime.now() from QUANTAXIS.QAFetch.QAQuery_Advance import QA_fetch_stock_block_adv code = QA_fetch_stock_block_adv().code print(len(code)) x = QA_Tdx_Executor(timeout=float(timeout), thread_num=int(thread), max_size=int(size)) print(x._queue.qsize()) print(x.get_available()) database = DATABASE.get_collection('realtime_{}'.format( datetime.date.today())) print(database) # mongodb在排序时,复合索引并不能像关系型数据库一样提升效率,反而会降低排序性能 # 在测试的过程,发现datetime倒序索引在倒序查询时性能更高,但写入性能较低 # 此表属于写多读少,所以索引继续采用正序 database.create_index([('code', QA_util_sql_mongo_sort_ASCENDING)]) database.create_index([('datetime', QA_util_sql_mongo_sort_ASCENDING)]) while True: _time = datetime.datetime.now() if QA_util_if_tradetime(_time): # 如果在交易时间 data = x.get_realtime_concurrent(code) data[0]['datetime'] = data[1] x.save_mongo(data[0]) print('Time {}'.format( (datetime.datetime.now() - _time).total_seconds())) time.sleep(sleep) print('Connection Pool NOW LEFT {} Available IP'.format( x._queue.qsize())) print('Program Last Time {}'.format( (datetime.datetime.now() - _time1).total_seconds())) else: print('Not Trading time {}'.format(_time)) time.sleep(sleep)
def bat(timeout=0.2, sleep=1): sleep = int(sleep) _time1 = datetime.datetime.now() from QUANTAXIS.QAFetch.QAQuery_Advance import QA_fetch_stock_block_adv code = QA_fetch_stock_block_adv().code print(len(code)) x = QA_Tdx_Executor(timeout=float(timeout)) print(x._queue.qsize()) print(x.get_available()) database = DATABASE.get_collection( 'realtime_{}'.format(datetime.date.today())) print(database) # mongodb在排序时,复合索引并不能像关系型数据库一样提升效率,反而会降低排序性能 # # 在测试的过程,发现datetime倒序索引在倒序查询时性能更高,但写入性能较低 # # 此表属于写多读少,所以索引继续采用正序 database.create_index([('code', QA_util_sql_mongo_sort_ASCENDING)]) database.create_index([('datetime', QA_util_sql_mongo_sort_ASCENDING)]) while True: _time = datetime.datetime.now() if QA_util_if_tradetime(_time): # 如果在交易时间 data = x.get_realtime_concurrent(code) data[0]['datetime'] = data[1] x.save_mongo(data[0]) print('Time {}'.format( (datetime.datetime.now() - _time).total_seconds())) time.sleep(sleep) print('Connection Pool NOW LEFT {} Available IP'.format( x._queue.qsize())) print('Program Last Time {}'.format( (datetime.datetime.now() - _time1).total_seconds())) else: print('Not Trading time {}'.format(_time)) time.sleep(sleep)
def save_mongo(self, data, client=DATABASE): database = DATABASE.get_collection('realtime_{}'.format( datetime.date.today())) database.insert_many(QA_util_to_json_from_pandas(data))
def save_mongo(self, data, client=DATABASE): database = DATABASE.get_collection( 'realtime_{}'.format(datetime.date.today())) database.insert_many(QA_util_to_json_from_pandas(data))
from QUANTAXIS.QAFetch.QATdx import QA_fetch_get_stock_list from QUANTAXIS.QAFetch.QATdx_adv import QA_Tdx_Executor from QUANTAXIS.QAUtil.QADate_trade import QA_util_if_tradetime from QUANTAXIS.QAUtil.QASetting import DATABASE from QUANTAXIS.QAUtil.QASql import (QA_util_sql_mongo_sort_ASCENDING, QA_util_sql_mongo_sort_DESCENDING) _time1 = datetime.datetime.now() code = QA_fetch_get_stock_list().code.tolist() print(len(code)) x = QA_Tdx_Executor() print(x._queue.qsize()) print(x.get_available()) database = DATABASE.get_collection('realtime_{}'.format(datetime.date.today())) print(database) database.create_index([('code', QA_util_sql_mongo_sort_ASCENDING), ('datetime', QA_util_sql_mongo_sort_ASCENDING)]) for i in range(100000): _time = datetime.datetime.now() if QA_util_if_tradetime(_time): # 如果在交易时间 data = x.get_realtime_concurrent(code) data[0]['datetime'] = data[1] x.save_mongo(data[0]) print('Time {}'.format( (datetime.datetime.now() - _time).total_seconds()))