Exemple #1
0
 def do_all(self):
     """
     执行所有历史数据
     """
     self.getTime()
     if self.begintime and self.endtime is not None:
         Now = self.begintime
         while (Now >= self.begintime and Now <= self.endtime):
             self.Now = strTostr(Now)
             CollaOptions_oneday(self.Lock, self.Now)
             Now = timedelta(Now, 1)
Exemple #2
0
    def getdayMax(self,Time=None):
        """
        获取某一天汇率最大值
        """
        key={'code':True}
        
        Time_end = strTostr(timedelta(Time,17.0/24))##当天时间下午5点
        Time = strTostr(Time)
        initial ={'Close':0,'Time':Time}
       
        reduces = """function(doc,prev){
 
                     if (prev.Time<doc.Time){
                          prev.Close = doc.Close/1.0/doc.PriceWeight;
                          prev.Time = doc.Time
                     }}"""##遍历寻找当前最大汇率值
        condition={'type':'0','code':self.code,'Time':{'$lt':Time_end,'$gte':Time}}             
        data =  self.__mongo.group('kline',key,condition,initial,reduces)
        self.__mongo.close()
        return data
Exemple #3
0
def setrate():
    from database.database import mongodb  ## mongo connect
    from help.help import getNow, strTostr  ##get current datetime
    key = {'code': True}
    Time = strTostr(getNow('%Y-%m-%d'))
    initial = {'Time': Time}
    reduces = """function(doc,prev){
                if (prev.Time>doc.Time){
                prev.Time = doc.Time
                }}"""
    condition = {'type': '5'}
    db = mongodb()
    rate = db.group('kline', key, condition, initial, reduces)
    rate = map(lambda x: {x['code']: x['Time'].split()[0]}, rate)
    globalrate.rate = reduce(lambda x, y: dict(x, **y), rate)
    db.close()
Exemple #4
0
    def getMax(self):
        """
        获取利率最大的日期对应的日期
        """
        key={'index':True}
        Time = strTostr(getNow('%Y'),'%Y')
        initial ={'rate':0,'datadate':Time}
        reduces = """function(doc,prev){
 
                     if (prev.datadate<doc.datadate){
                          prev.rate = doc.rate;
                          prev.datadate = doc.datadate
                     }}"""##遍历寻找当前最大汇率值
        ratetype ='12月'
        condition={'ratetype':ratetype,'index':self.code}      
        
        data = self.__mongo.group('KPI',key,condition,initial,reduces)
        self.__mongo.close()
        return data
Exemple #5
0
def gethistory(Currency):
    """获取汇率对的历史收盘价"""
    data = []
    try:
        mongo = mongodb()
        data = mongo.select('kline', {'type': '5', 'code': Currency})
        mongo.close()
    except:
        pass
    if data != []:
        data = pd.DataFrame(data)
        data = data[['Time', 'Close', 'PriceWeight']]
        data['Close'] = data['Close'] / data['PriceWeight']
        #data['High'] = data['High']/data['PriceWeight']
        #data['Open'] = data['Open']/data['PriceWeight']
        #data['LastClose'] = data['LastClose']/data['PriceWeight']
        #data['Low'] = data['Low']/data['PriceWeight']

        data['Time'] = data['Time'].map(
            lambda x: strTostr(x, '%Y-%m-%d %H:%M:%S', '%Y-%m-%d'))
        data = data[['Time', 'Close']]

    return data