示例#1
0
    def getDataFromPostgres(self):

        #Now = getNow('%Y-%m-%d')
        Now = self.Now.split()[0]

        post = postgersql()
        colname1 = [
            'id', 'trade_id', 'currency_pair', 'sell_currency', 'buy_currency',
            'sell_amount', 'buy_amount', 'trade_date', 'determined_date',
            'delivery_date', 'exe_doexrate', 'exe_upexrate', 'type',
            'consign_entity', 'trade_type'
        ]
        wherestring1 = """ delivery_date>='{}' and trade_date<='{}'""".format(
            Now, Now)

        optiondata = post.select(self.table, colname1, wherestring1)
        optiondata = filter(
            lambda x: x['currency_pair'] in getrate() and Now >= getrate()[x[
                'currency_pair']], optiondata)
        colname2 = ['der_id']
        wherestring2 = """date='{}'""".format(Now)
        savedata = map(lambda x: x['der_id'],
                       post.select(self.writetable, colname2, wherestring2))
        data = []
        for lst in optiondata:
            if lst['trade_type'] + '_' + str(lst['id']) not in savedata:
                data.append(lst)
        if data is not None and data != []:
            self.data = data
            self.getDataFromMongo()  ##从mongo提取数据并更新损益
示例#2
0
 def getTime(self):
     """
     获取最小起始日期和min{最大交割日日期,当前日期}
     """
     post = postgersql()
     colname = ['trade_date','delivery_date','currency_pair','dates']
     sql = """select op.trade_date,op.delivery_date,op.currency_pair,
             case
             when t.dates<op.delivery_date then date(t.dates)+1
             when t.dates=op.delivery_date then current_date
             end as dates
             from %s op
             left join 
             (select max(pt.date) as dates,pt.der_id from %s pt
             group by pt.der_id) t
             on op.trade_type||'_'||op.id = t.der_id
             """%(self.table,self.querytable)
     time = post.view(sql,colname)
     if time==[] or time==None:
         self.begintime = None
         self.endtime = None
     else:
         time = filter(lambda x:x['currency_pair'] in getrate() and dateTostr(x['delivery_date'])>=getrate()[x['currency_pair']],time)
         #print len(time)
         for lst in time:
             if lst['dates'] is None:
                 lst['dates'] = dateTostr(lst['trade_date']) if dateTostr(lst['trade_date'])>getrate()[lst['currency_pair']] else getrate()[lst['currency_pair']]
             else:
                 lst['dates'] = dateTostr(lst['dates'])
         begintime = time[0]['dates'] if len(time)==1 else min(map(lambda x:x['dates'],time))
         self.begintime = begintime if getNow('%Y-%m-%d')>=begintime else None
         endtime = dateTostr(time[0]['delivery_date'] if len(time)==1 else max(map(lambda x:x['delivery_date'],time)))
         self.endtime = endtime if getNow('%Y-%m-%d')>endtime else timedelta(getNow('%Y-%m-%d'),-1)
示例#3
0
 def getDataFromPostgres(self):
     """
     获取结构性产品的订单数据
     """
     post = postgersql()
     colname = [
         'id', 'trade_id', 'currency_pair', 'sell_currency', 'buy_currency',
         'sell_amount', 'buy_amount', 'trade_date', 'determined_date',
         'delivery_date', 'trp', 'rate', 'type', 'consign_entity',
         'trade_type'
     ]
     #wherestring = None
     #orderby = "order by trade_id, delivery_date"
     #Now = getNow('%Y-%m-%d')
     Now = dateTostr(self.Now)
     sql = """select %s from %s t join 
               (select trade_id from %s group by trade_id  having max(delivery_date)>=date'%s' ) b
               on t.trade_id=b.trade_id
               order by t.trade_id, t.delivery_date
               """ % (','.join(map(lambda x: 't.' + x, colname)),
                      self.table, self.table, Now)  ##过滤已交割完成的结构产品
     #self.data = post.view(sql,colname)
     optiondata = post.view(sql, colname)
     optiondata = filter(
         lambda x: x['currency_pair'] in getrate() and Now >= getrate()[x[
             'currency_pair']], optiondata)
     colname2 = ['der_id']
     wherestring2 = """date='{}'""".format(Now)
     savedata = map(lambda x: x['der_id'],
                    post.select(self.writetable, colname2, wherestring2))
     data = []
     for lst in optiondata:
         if lst['trade_type'] + '_' + str(lst['id']) not in savedata:
             data.append(lst)
     if data is not None and data != []:
         self.data = data
         self.getDataFromMongo()  ##从mongo提取数据并更新损益
         self.cumputeLost()