mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-03 16:56:11 +08:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user