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


Python FastRBTree.min_item方法代码示例

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


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

示例1: OrderQueue

# 需要导入模块: from bintrees import FastRBTree [as 别名]
# 或者: from bintrees.FastRBTree import min_item [as 别名]
class OrderQueue(object):
    """
    """
    def __init__(self):
        self.Orders = FastRBTree()

        self.totalAmount = 0.0

    def append(self,order):
        k = order.timestamp
        self.Orders.insert(k,order)
        self.totalAmount += self.Orders[k].amount

    def count(self):
        return self.Orders.count

    def min_item(self):
        return self.Orders.min_item()

    def eat(self,amount):
        """
        use this only if amount <= self.amount
        return OrderToPop,RestAmount
        """
        current_amount = amount
        to_pop_orders = []
        while self.totalAmount>0 and current_amount>0:
            if not self.Orders or self.Orders.count==0:
                #print "amount:%.4f" % self.totalAmount
                self.totalAmount = 0.0
                return []

            min_item = self.Orders.min_item()
            min_i = min_item[1]
            # 1.enough
            # 2.not enough
            if min_i.amount <= current_amount:
                current_amount -= min_i.amount
                self.totalAmount -= min_i.amount
                to_pop_orders.append(self.Orders.pop_min()[1])
                continue
            # this is a hard case , need to take care of
            # first we split the order , take amount from current order
            # and make
            elif min_i.amount > current_amount:
                new_order = min_i.copy()
                new_order.amount = current_amount
                to_pop_orders.append(new_order)
                min_i.amount -= current_amount
                self.totalAmount -= current_amount
                current_amount = 0
                break
        # return:
        # 1.orders
        # 2.amount to trade
        # 3.amount left
        return to_pop_orders

    def remove(self,order):
        k = order.timestamp
        self.totalAmount -= self.Orders[k].amount
        self.Orders.remove(k)

    def get_price_depth(self):
        return self.totalAmount

    def is_empty(self):
        return self.Orders.count == 0
开发者ID:ydxt25,项目名称:trade_matching_engine,代码行数:70,代码来源:OrderQueue.py


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