Example #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
Example #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
Example #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
Example #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..'
Example #5
0
 def dict(self):
     data = hash_object(self.price)
     data.update(hash_object(self, excludes=('trade_object', 'price')))
     return data
Example #6
0
 def values(self):
     return hash_object(self,
                        excludes=('id_', 'name_', 'values_', 'extras_',
                                  'NAME', 'OFFSET_BID', 'OFFSET_DOWN',
                                  'OFFSET_UP'))
Example #7
0
 def dict(self):
     data = hash_object(self, excludes=('message', ))
     data.update(hash_object(self.device))
     return data
Example #8
0
 def dict(self):
     data = hash_object(self,excludes=('extra','Type'))
     return data
Example #9
0
 def dict(self):
     data = hash_object(self)
     if data.has_key('_id'):
         del data['_id']
     return data
Example #10
0
 def dict(self):
     data =  hash_object(self,excludes=('last_volume','start','end'))
     return data
Example #11
0
 def values(self):
     return hash_object(self,excludes=('id_','name_','values_','extras_','NAME'))
Example #12
0
 def dict(self):
     # data = self.simple_info.dict()
     data = {}
     data.update(hash_object(self, excludes=('simple_info', )))
     return data
Example #13
0
 def values(self):
     src = hash_object(self.src)
     dest = hash_object(self.dest)
     return dict(sid=self.sid, src=src, dest=dest)
Example #14
0
 def dict(self):
     data = hash_object(self, excludes=('trade_object', ))
     return data
Example #15
0
 def dumps(self):
     result = hash_object(self)
     return result
Example #16
0
 def dumps(self):
     return hash_object(self)
Example #17
0
 def dict(self):
     data = {}
     data.update(hash_object(self,excludes=('content',)))
     return data
Example #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()
Example #19
0
 def dict(self):
     data = hash_object(self, excludes=('location', ))
     data.update(self.location.dict())
     return data
Example #20
0
 def dict(self):
     return hash_object(self)
Example #21
0
 def dict(self):
     data = self.location_ext.dict()
     data.update(hash_object(self, excludes=('location', 'location_ext')))
     return data