示例#1
0
 def body(self):
     data = hash_object(self, excludes=('result', 'params', 'key_maps'))
     for k, v in self.key_maps.items():
         if data.has_key(k):
             data[v] = data[k]
             del data[k]
     return data
示例#2
0
 def save(self):
     coll = get_database()[self.__collection__]
     data = hash_object(self, excludes=['_id'])
     if self._id:
         self.update(**data)
     else:
         self._id = coll.insert_one(data).inserted_id
     return self
示例#3
0
 def dict(self):
     data = self.location.dict()
     data.update(self.location_ext.dict())
     data.update(hash_object(self, excludes=('location', 'location_ext')))
     data.update(self.simple_info.dict())
     data.update({
         'voltage': self.voltage,
         'gsm': self.gsm,
         'alarm': self.alarm,
         'lang': self.lang,
         'miles': self.miles
     })
     return data
示例#4
0
def make_hist_day_bar(symbol,start,end='',dbname='Ctp_Bar_d'):
    """

    :param start: 2019-1-1
    :param end:  默认为至今
    :return:
    """
    coll = config.db_conn[dbname][symbol]
    start = parse(start)
    if not end:
        end =  datetime.datetime.now().date()
        end = datetime.datetime(year=end.year,month=end.month,day=end.day)

    coll.create_index([('datetime', 1)])
    coll.delete_many({'datetime':{'$gte':start,'$lte':end}})

    coll_m1 = config.db_conn['Ctp_Bar_1'][symbol]
    coll_m1.create_index([('datetime', 1)])

    seek_day = start
    # 依次迭代所有交易日
    while seek_day <= end:
        print 'Indexing ',seek_day
        rs = coll_m1.find({'trade_date':seek_day}).sort('datetime',1)
        bar = BarData('d')
        last_volume = 0
        count = 0
        for idx,r in enumerate(rs):
            count +=1
            bar.high = max(bar.high, r['high'])
            if idx ==0:
                bar.low = r['low']
            else:
                bar.low = min(bar.low, r['low'])

            bar.close = r['close']
            bar.openInterest = r['openInterest']
            last_volume = r['volume']
            if idx == 0:
                bar.open = r['open']
            else:
                bar.volume += r['volume'] - last_volume

        bar.datetime = seek_day

        if count:
            coll.insert_one( hash_object(bar) )

        seek_day += datetime.timedelta(days=1)

    print 'make day bar end..'
示例#5
0
 def dict(self):
     data = hash_object(self.price)
     data.update(hash_object(self, excludes=('trade_object', 'price')))
     return data
示例#6
0
 def values(self):
     return hash_object(self,
                        excludes=('id_', 'name_', 'values_', 'extras_',
                                  'NAME', 'OFFSET_BID', 'OFFSET_DOWN',
                                  'OFFSET_UP'))
示例#7
0
 def dict(self):
     data = hash_object(self, excludes=('message', ))
     data.update(hash_object(self.device))
     return data
示例#8
0
文件: message.py 项目: adoggie/PyDawn
 def dict(self):
     data = hash_object(self,excludes=('extra','Type'))
     return data
示例#9
0
 def dict(self):
     data = hash_object(self)
     if data.has_key('_id'):
         del data['_id']
     return data
示例#10
0
 def dict(self):
     data =  hash_object(self,excludes=('last_volume','start','end'))
     return data
示例#11
0
文件: message.py 项目: adoggie/SecIoT
 def values(self):
     return hash_object(self,excludes=('id_','name_','values_','extras_','NAME'))
示例#12
0
 def dict(self):
     # data = self.simple_info.dict()
     data = {}
     data.update(hash_object(self, excludes=('simple_info', )))
     return data
示例#13
0
 def values(self):
     src = hash_object(self.src)
     dest = hash_object(self.dest)
     return dict(sid=self.sid, src=src, dest=dest)
示例#14
0
 def dict(self):
     data = hash_object(self, excludes=('trade_object', ))
     return data
示例#15
0
 def dumps(self):
     result = hash_object(self)
     return result
示例#16
0
 def dumps(self):
     return hash_object(self)
示例#17
0
 def dict(self):
     data = {}
     data.update(hash_object(self,excludes=('content',)))
     return data
示例#18
0
from graphviz import Digraph
from mantis.fundamental.utils.useful import hash_object
from mantis.sg.fisher.stbase.tradeobject import TradeObject

dot = Digraph(comment='mantis.sg.fisher')
s = Digraph('structs', node_attr={'shape': 'record'})


def hash_object(obj, excludes=()):
    attrs = [s for s in dir(obj) if not s.startswith('__')]
    kvs = {}
    mems = []
    funs = []
    name = obj.__class__.__name__
    for k in attrs:
        if k in excludes:
            continue
        attr = getattr(obj, k)
        if callable(attr):
            funs.append(k)
        else:
            mems.append(k)
    mems.sort(cmp=lambda x, y: x > y)
    return name, mems, funs


obj = TradeObject(None, None)
name, mems, funs = hash_object(obj)
funs = map(lambda f: '*' + f + '()', funs)
s.node(name, '{%s|%s|%s}' % (name, '|'.join(mems), '|'.join(funs)))
s.view()
示例#19
0
 def dict(self):
     data = hash_object(self, excludes=('location', ))
     data.update(self.location.dict())
     return data
示例#20
0
 def dict(self):
     return hash_object(self)
示例#21
0
 def dict(self):
     data = self.location_ext.dict()
     data.update(hash_object(self, excludes=('location', 'location_ext')))
     return data