BUG: Ensure consistent ordering of amounts, prices & multipliers

Previously, we have assumed that the `amounts` and `last_sale_prices`
lists have the same order as the `value_multipliers`. This is not
correct, since to populate the `amounts` and `last_sale_prices` lists
we iterate over a `dict` (self.positions). The order of this `dict`
can change in arbitrary ways when it is updated, which occurs when
we call `update_positions`. Our `value_multipliers` however are stored
in an `OrderedDict`, meaning the order of existing key/value pairs
is not changed when they are updated.

To address this issue, we make sure that `self.positions` subclasses
`OrderedDict`.
This commit is contained in:
Stewart Douglas
2016-02-29 10:40:57 -05:00
parent 4f0babc558
commit e47cb96479
+2 -1
View File
@@ -33,6 +33,7 @@ Position Tracking
from __future__ import division
from math import copysign
from collections import OrderedDict
from copy import copy
@@ -228,7 +229,7 @@ last_sale_price: {last_sale_price}"
self.__dict__.update(state)
class positiondict(dict):
class positiondict(OrderedDict):
def __missing__(self, key):
pos = Position(key)