Beispiel #1
0
def min60(time):
    min60_times = [1030, 1130, 1400, 1500]
    if time in min60_times:
        temp = time // 100 * 60 + time % 100 - 60
        temp = temp // 60 * 100 + temp % 60
        print(temp)
        sql = {'time': {'$gt': temp, '$lte': time}, 'date': Calendar.today()}
        curror = BaseModel('real_kline_min5').query(sql=sql)
        if curror.count():
            data = pd.DataFrame(list(curror))

            data = data.sort_values(by=['time'], ascending=True)
            data = data.groupby(by=['stock_code'], as_index=False).agg({
                'volume':
                'sum',
                'amount':
                'sum',
                'open':
                'first',
                'close':
                'last',
                'high':
                'max',
                'low':
                'min'
            })

            data['time'] = time
            data['date'] = Calendar.today()
            BaseModel('real_kline_min60').insert_batch(
                data.to_dict(orient='records'))
            print('min60 ok')
        curror.close()
Beispiel #2
0
def exe(parm):
    time = parm['time']
    datetime = parm['datetime']
    i = parm['sc']
    temp = datetime.hour * 60 + datetime.minute - 5
    temp = temp // 60 * 100 + temp % 60
    # print(temp)
    curror = BaseModel('real_buy_sell_all_stock_code').query(
        sql={
            'stock_code': {
                '$in': i
            },
            'datetime': {
                '$gte':
                dt.datetime(datetime.year, datetime.month, datetime.day,
                            temp // 100, temp % 100),
                '$lt':
                dt.datetime(datetime.year, datetime.month, datetime.day,
                            datetime.hour, datetime.minute, 0)
            }
        })

    if curror.count() > 0:
        data = pd.DataFrame(list(curror))
        data['volume2'] = data.volume
        data['amount2'] = data.amount
        data['high'] = data.price
        data['low'] = data.price
        data['close'] = data.price
        data['open'] = data.price
        data = data.groupby(by=['stock_code'], as_index=False).agg({
            'volume': 'first',
            'volume2': 'last',
            'amount': 'first',
            'amount2': 'last',
            'open': 'first',
            'close': 'last',
            'high': 'max',
            'low': 'min'
        })
        data['volume'] = data.volume2 - data.volume
        data['amount'] = data.amount2 - data.amount
        data = data.drop(['volume2', 'amount2'], axis=1)
        data['time'] = time
        data['date'] = dt.datetime(datetime.year, datetime.month, datetime.day)

        BaseModel('real_kline_min5').insert_batch(
            data.to_dict(orient='records'))
Beispiel #3
0
 def is_trade_day(cls, date):
     curror = BaseModel('calendar').query(dict(date=Calendar.today()))
     return True if curror.count() else False