当前位置: 首页>>代码示例>>Python>>正文


Python Order.query方法代码示例

本文整理汇总了Python中models.Order.query方法的典型用法代码示例。如果您正苦于以下问题:Python Order.query方法的具体用法?Python Order.query怎么用?Python Order.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Order的用法示例。


在下文中一共展示了Order.query方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sec_tops

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import query [as 别名]
def sec_tops(secs):
    lt = {}
    bb = {}
    ba = {}
    for sec in secs:
        # Last traded price
        t = Trade.query(Trade.security == sec).order(-Trade.timestamp)
        t = list(t)
        if len(t) > 0:
            lt[sec.key.id()] = t[0].price
        else:
            lt[sec.key.id()] = 0
        
        # Best bid
        t = Order.query(Order.security == sec, Order.buysell == 'Buy', Order.active == True).order(-Order.price)
        t = list(t)
        if len(t) > 0:
            bb[sec.key.id()] = t[0].price
        else:
            bb[sec.key.id()] = 0
        
        # Best ask
        t = Order.query(Order.security == sec, Order.buysell == 'Sell', Order.active == True).order(Order.price)
        t = list(t)
        if len(t) > 0:
            ba[sec.key.id()] = t[0].price
        else:
            ba[sec.key.id()] = 0
    
    tops = {'lt':lt, 'bb':bb, 'ba':ba}
    return tops
开发者ID:tonyin,项目名称:chifx,代码行数:33,代码来源:scripts.py

示例2: construct_book

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import query [as 别名]
def construct_book(sec): 
    """Create buy and sell top depths"""
    # Get sorted
    b1 = Order.query(Order.security == sec, Order.buysell == 'Buy', Order.active == True, ancestor=sec.key).order(-Order.price)
    s1 = Order.query(Order.security == sec, Order.buysell == 'Sell', Order.active == True, ancestor=sec.key).order(Order.price)
    
    # BUYS
    # Combine price volume
    b2 = {}
    for order in b1:
        b2[order.price] = b2.get(order.price, 0) + order.volume
    b2 = OrderedDict(sorted(b2.items(), reverse = True))
    
    # Get top of buy book
    n = list(islice(b2.items(), 0, 1))
    b3 = {}
    if len(n) != 0:
        k = n[0][0]
        b3[k] = n[0][1]
    else:
        k = 0
        b3[k] = 0
    
    # Keep top BOOK_TOP_LEVELS number of prices
    for i in range(BOOK_TOP_LEVELS):
        if k - i - 1 <= 0:
            break
        b3[k-i-1] = b2.get(k-i-1, 0)
    b3 = OrderedDict(sorted(b3.items(), reverse = True))
    
    # SELLS
    # Combine price volume
    s2 = {}
    for order in s1:
        s2[order.price] = s2.get(order.price, 0) + order.volume
    s2 = OrderedDict(sorted(s2.items()))
    
    # Get top of sell book
    n = list(islice(s2.items(), 0, 1))
    s3 = {}
    if len(n) != 0:
        k = n[0][0]
        s3[k] = n[0][1]
    else:
        k = list(islice(b3.items(), 0, 1))[0][0]+1
        s3[k] = 0
    
    # Keep top BOOK_TOP_LEVELS number of prices
    for i in range(BOOK_TOP_LEVELS):
        s3[k+i+1] = s2.get(k+i+1, 0)
    s3 = OrderedDict(sorted(s3.items(), reverse = True))
    
    # Combine books
    book = {'buys':b3, 'sells':s3}
    
    return book
开发者ID:tonyin,项目名称:chifx,代码行数:58,代码来源:scripts.py

示例3: summary

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import query [as 别名]
def summary():
    global symbols
    user = request.args.get('user')
    if user:
        if not current_user.is_admin():
            return 'WTF?'

    if user:
        user = User.query_one({'_id': user})
    else:
        user = current_user

    accounts = list(Account.query({'user_id': user._id}))

    ps = [p for p in
          Position.query({'user_id': user._id},
                         sort=[('date', 1)])]
    os = [o for o in
          Order.query({'user_id': user._id},
                      sort=[('date', 1)])]

    dates = list(reversed([p.date for p in ps]))
    total_profit = 0
    for o in os:
        for oo in o.order_list:
            if oo.symbol in symbols:
                total_profit += oo.profit

    today = request.args.get('today')
    if today:
        today = datetime.strptime(today, '%Y-%m-%d %H:%M:%S')
    else:
        d = datetime.utcnow() + timedelta(hours=8)
        if d.hour == 9 and 20 <= d.minute <= 40:
            return '跌零时间段, 不可查看'
        if d.hour < 9:
            d -= timedelta(days=1)
        today = d.replace(hour=0, minute=0, second=0, microsecond=0)

    try:
        position_list = Position.query_one({'user_id': user._id,
                                            'date': today}).position_list
        status_list = Status.query_one({'user_id': user._id,
                                        'date': today}).status_list
        order_list = Order.query_one({'user_id': user._id,
                                      'date': today}).order_list
    except:
        pass

    locals()['symbols'] = symbols

    return render_template('summary.html', **locals())
开发者ID:sopnic,项目名称:ybk,代码行数:54,代码来源:app.py

示例4: getOrder

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import query [as 别名]
	def getOrder(self,request):
		data = {}
		c = []
		for field in request.all_fields():
			data[field.name] = getattr(request,field.name)

		orders = Order.query(Order.custId == ndb.Key(Customer,data['custId']))
		for order in orders:
			setattr(order,'itemName',(Item.query(Item.key == order.itemId, projection = [Item.itemName])).get().itemName)
			logging.debug(order)
			logging.debug(order.key)
			c.append(self._copyOrderToForm(order))
			logging.debug(c)
		return ReturnCustOrderForm(orderList=c)
开发者ID:nipun0212,项目名称:Shiv-Dugdh-Bhandar,代码行数:16,代码来源:dairymanagement.py

示例5: match_orders

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import query [as 别名]
def match_orders(sec, buysell):
    """Match orders in cross"""
    # Get buy and sell lists
    b = Order.query(Order.security == sec, Order.buysell == 'Buy', Order.active == True, ancestor=sec.key).order(-Order.price, Order.timestamp)
    s = Order.query(Order.security == sec, Order.buysell == 'Sell', Order.active == True, ancestor=sec.key).order(Order.price, Order.timestamp)
    b = list(b)
    s = list(s)
    
    # Match orders until market uncrosses
    bn = 0
    sn = 0
    while(1):
        if bn + 1 > len(b):
            break
        if sn + 1 > len(s):
            break
        if b[bn].price >= s[sn].price:
            t = Trade()
            t.timestamp = datetime.utcnow()
            t.buy_user = b[bn].user
            t.sell_user = s[sn].user
            t.security = b[bn].security
            if buysell == "Buy":
                t.price = s[sn].price
            else:
                t.price = b[bn].price
            b[bn] = b[bn].key.get()
            s[sn] = s[sn].key.get()
            b_ptf = Portfolio.query(Portfolio.user == b[bn].user).get()
            s_ptf = Portfolio.query(Portfolio.user == s[sn].user).get()
            if b[bn].volume > s[sn].volume:
                t.volume = s[sn].volume
                b[bn].volume += -s[sn].volume
                s[sn].active = False
                b_ptf.points += s[sn].volume
                s_ptf.points += s[sn].volume
                b[bn].put()
                s[sn].put()
                sn += 1
            elif b[bn].volume < s[sn].volume:
                t.volume = b[bn].volume
                s[sn].volume += -b[bn].volume
                b[bn].active = False
                b_ptf.points += b[bn].volume
                s_ptf.points += b[bn].volume
                b[bn].put()
                s[sn].put()
                bn += 1
            elif b[bn].volume == s[sn].volume:
                t.volume = b[bn].volume
                b[bn].active = False
                s[sn].active = False
                b_ptf.points += b[bn].volume
                s_ptf.points += b[bn].volume
                b[bn].put()
                s[sn].put()
                bn += 1
                sn += 1
            b_ptf.put()
            s_ptf.put()
            t.put()
            flash(u'Trade %s successfully completed.' % t.key.id(), 'success')
            continue
        break
开发者ID:tonyin,项目名称:chifx,代码行数:66,代码来源:scripts.py


注:本文中的models.Order.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。