Esempio n. 1
0
def SU_save_stock_block(client=ms.client):
    client.flyshare.drop_collection('stock_block')
    __coll = client.flyshare.stock_block
    __coll.create_index('code')
    __err = []
    try:
        util_log_info('##JOB09 Now Saving STOCK_BlOCK ====')
        __coll.insert_many(
            util_to_json_from_pandas(fetch_get_stock_block('tdx')))
        __coll.insert_many(
            util_to_json_from_pandas(fetch_get_stock_block('ths')))
    except:
        pass
Esempio n. 2
0
    def __saving_work(code, __coll):

        util_log_info('##JOB07 Now Saving ETF_MIN ==== %s' % (str(code)))
        try:

            for type in ['1min', '5min', '15min', '30min', '60min']:
                ref_ = __coll.find({'code': str(code)[0:6], 'type': type})
                end_time = str(now_time())[0:19]
                if ref_.count() > 0:
                    start_time = ref_[ref_.count() - 1]['datetime']
                else:
                    start_time = '2015-01-01'
                util_log_info(
                    '##JOB07.%s Now Saving %s from %s to %s ==%s ' %
                    (['1min', '5min', '15min', '30min', '60min'
                      ].index(type), str(code), start_time, end_time, type))
                if start_time != end_time:
                    __data = fetch_get_index_min(str(code), start_time,
                                                 end_time, type)
                    if len(__data) > 1:
                        __coll.insert_many(
                            util_to_json_from_pandas(__data[1::]))

        except:
            __err.append(code)
Esempio n. 3
0
def fetch_get_stock_info(name):
    data = QATs.get_stock_basics()
    data_json = util_to_json_from_pandas(data)

    for i in range(0, len(data_json) - 1, 1):
        data_json[i]['code'] = data.index[i]
    return data_json
Esempio n. 4
0
    def __saving_work(code, __coll):
        util_log_info('##JOB02 Now Saving XDXR INFO ==== %s' % (str(code)))
        try:
            __coll.insert_many(
                util_to_json_from_pandas(fetch_get_stock_xdxr(str(code))))

        except:
            __err.append(str(code))
Esempio n. 5
0
    def save_stock_day(code, start, end, coll):
        util_log_info('##JOB01 Now Updating STOCK_DAY==== %s' % (str(code)))
        data = util_to_json_from_pandas(
            fetch_get_stock_day(str(code), start, end, '00'))

        if len(data) > 0:
            coll.insert_many(data)
        else:
            pass
Esempio n. 6
0
 def __get_index_day_data(self, __bid):
     __data = util_to_json_from_pandas(
         fetch_index_day(
             str(__bid.code)[0:6],
             str(__bid.datetime)[0:10],
             str(__bid.datetime)[0:10], 'pd'))
     if len(__data) == 0:
         pass
     else:
         __data = __data[0]
     return __data
Esempio n. 7
0
 def __saving_work(code):
     util_log_info('##JOB10 Now Saving STOCK_TRANSACTION ==== %s' %
                   (str(code)))
     try:
         __coll.insert_many(
             util_to_json_from_pandas(
                 fetch_get_stock_transaction(str(code),
                                             str(__stock_list[code]),
                                             str(now_time())[0:10])))
     except:
         __err.append(str(code))
Esempio n. 8
0
def SU_save_stock_list(client=ms.client):
    client.flyshare.drop_collection('stock_list')
    __coll = client.flyshare.stock_list
    __coll.create_index('code')
    __err = []

    try:
        util_log_info('##JOB08 Now Saving STOCK_LIST ====')
        __coll.insert_many(util_to_json_from_pandas(fetch_get_stock_list()))
    except:
        pass
Esempio n. 9
0
 def saving_work(i):
     util_log_info('Now Saving ==== %s' % (i))
     try:
         data_hfq = fetch_get_stock_day(i,
                                        startDate='1990-01-01',
                                        if_fq='02',
                                        type_='pd')
         data_json = util_to_json_from_pandas(data_hfq)
         __coll.insert_many(data_json)
     except:
         util_log_info('error in saving ==== %s' % str(i))
Esempio n. 10
0
 def __get_data(__bid):
     '隔离掉引擎查询数据库的行为'
     __data = util_to_json_from_pandas(
         fetch_stock_day(
             str(__bid.code)[0:6],
             str(__bid.date)[0:10],
             str(__bid.date)[0:10], 'pd'))
     if len(__data) == 0:
         pass
     else:
         __data = __data[0]
     return __data
Esempio n. 11
0
def fetch_get_trade_date(endDate, exchange):
    data = QATs.trade_cal()
    da = data[data.isOpen > 0]
    data_json = util_to_json_from_pandas(data)
    message = []
    for i in range(0, len(data_json) - 1, 1):
        date = data_json[i]['calendarDate']
        num = i + 1
        exchangeName = 'SSE'
        data_stamp = util_date_stamp(date)
        mes = {
            'date': date,
            'num': num,
            'exchangeName': exchangeName,
            'date_stamp': data_stamp
        }
        message.append(mes)
    return message
Esempio n. 12
0
    def __saving_work(code, coll_stock_day):
        try:
            util_log_info('##JOB01 Now Saving STOCK_DAY==== %s' % (str(code)))

            ref = coll_stock_day.find({'code': str(code)[0:6]})
            end_date = str(now_time())[0:10]
            if ref.count() > 0:
                # 加入这个判断的原因是因为如果股票是刚上市的 数据库会没有数据 所以会有负索引问题出现

                start_date = ref[ref.count() - 1]['date']
            else:
                start_date = '1990-01-01'
            util_log_info(
                ' UPDATE_STOCK_DAY \n Trying updating %s from %s to %s' %
                (code, start_date, end_date))
            if start_date != end_date:
                coll_stock_day.insert_many(
                    util_to_json_from_pandas(
                        fetch_get_stock_day(str(code), start_date, end_date,
                                            '00')[1::]))
        except:
            __err.append(str(code))
Esempio n. 13
0
    def __saving_work(code, __coll):

        try:

            ref_ = __coll.find({'code': str(code)[0:6]})
            end_time = str(now_time())[0:10]
            if ref_.count() > 0:
                start_time = ref_[ref_.count() - 1]['date']
            else:
                start_time = '1990-01-01'

            util_log_info(
                '##JOB06 Now Saving ETF_DAY==== \n Trying updating %s from %s to %s'
                % (code, start_time, end_time))

            if start_time != end_time:
                __coll.insert_many(
                    util_to_json_from_pandas(
                        fetch_get_index_day(str(code), start_time,
                                            end_time)[1::]))
        except:
            __err.append(str(code))
Esempio n. 14
0
def fetch_get_stock_day(name,
                        startDate='',
                        endDate='',
                        if_fq='01',
                        type_='json'):
    if (len(name) != 6):
        name = str(name)[0:6]

    if str(if_fq) in ['qfq', '01']:
        if_fq = 'qfq'
    elif str(if_fq) in ['hfq', '02']:
        if_fq = 'hfq'
    elif str(if_fq) in ['bfq', '00']:
        if_fq = 'bfq'
    else:
        util_log_info('wrong with fq_factor! using qfq')
        if_fq = 'qfq'

    data = QATs.get_k_data(str(name),
                           startDate,
                           endDate,
                           ktype='D',
                           autype=if_fq,
                           retry_count=200,
                           pause=0.005).sort_index()

    data['date_stamp'] = data['date'].apply(lambda x: util_date_stamp(x))
    data['fqtype'] = if_fq
    if type_ in ['json']:
        data_json = util_to_json_from_pandas(data)
        return data_json
    elif type_ in ['pd', 'pandas', 'p']:
        data['date'] = pd.to_datetime(data['date'])
        data = data.set_index('date', drop=False)
        data['date'] = data['date'].apply(lambda x: str(x)[0:10])
        return data
Esempio n. 15
0
 def to_json(self):
     return util_to_json_from_pandas(self.data)
Esempio n. 16
0
def fetch_backtest_info(user=None, account_cookie=None, strategy=None, stock_list=None, collections=ms.client.flyshare.backtest_info):

    return util_to_json_from_pandas(pd.DataFrame([item for item in collections.find(util_to_json_from_pandas(pd.DataFrame([user, account_cookie, strategy, stock_list], index=['user', 'account_cookie', 'strategy', 'stock_list']).dropna().T)[0])]).drop(['_id'], axis=1))
Esempio n. 17
0
def fetch_backtest_history(cookie=None, collections=ms.client.flyshare.backtest_history):
    return util_to_json_from_pandas(pd.DataFrame([item for item in collections.find(util_to_json_from_pandas(pd.DataFrame([cookie], index=['cookie']).dropna().T)[0])]).drop(['_id'], axis=1))
Esempio n. 18
0
 def from_dataframe(self, dataframe):
     bid_list = []
     for item in util_to_json_from_pandas(dataframe):
         bid_list.append(self.from_dict(item))
     return bid_list
Esempio n. 19
0
 def from_dataframe(self, dataframe):
     self.list = [
         MarketBid().from_dict(item)
         for item in util_to_json_from_pandas(dataframe)
     ]
     return self.list
Esempio n. 20
0
def fetch_get_stock_realtime():
    data = QATs.get_today_all()
    data_json = util_to_json_from_pandas(data)
    return data_json