Example #1
0
    IntField, StringField,
    Index,
)


class Test(Document):

    class Meta:
        tsidx = Index(['text', 'status'], unique=True)

    text = StringField(required=True)
    status = IntField()
    count = IntField(default=0)


conn = Connection('mongodb://localhost/yamotest')
conn.register_all()


def test_crud():
    Test.drop()

    t = Test({'text': 'aaa', 'status': 2})
    t.save()

    assert t.count == 0
    assert t._id

    t2 = Test({'text': 'aaa', 'status': 2, 'count': 5})
    t2.upsert()
    assert t2.count == 5
Example #2
0
File: config.py Project: sopnic/ybk
def setup_mongodb(conf):
    from yamo import Connection
    conn = Connection(conf['mongodb_url'])
    conn.register_all()
Example #3
0
File: models.py Project: sopnic/ybk
class Summary(Document):

    """ 各种组合的汇总信息

    总资金/总持仓/总浮盈
    """
    class Meta:
        idf = IDFormatter('{exchange}_{user}_{collection}')
        idx1 = Index('exchange')
        idx2 = Index('user')
        idx3 = Index('collection')

    exchange = StringField(default='', required=True)
    user = StringField(default='', required=True)
    collection = StringField(default='', required=True)

    position = ListField(EmbeddedField(MyPosition))
    orders = ListField(EmbeddedField(MyOrder))
    order_status = ListField(EmbeddedField(MyStatus))
    money = FloatField()
    capital = FloatField()
    profit = FloatField()
    earned = FloatField()  # 交易收入
    lost = FloatField()  # 交易亏损

conn = Connection('mongodb://localhost/qd')
for d in [Exchange, User, Collection, Account, DailyTrading, Summary]:
    conn.register(d)
for exchange in exchanges:
    Exchange({'name': exchange}).upsert()