Пример #1
0
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)
Пример #2
0
    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)
Пример #3
0
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)
Пример #4
0
    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')
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
    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))
Пример #8
0
    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))
Пример #9
0
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()))