MAINT: Defines members of the Order object.

Instead of a loosely defined object for Order, explicitly
defines the parameters and corresponding members.

Clearing the way for adding more members to the Order object.
This commit is contained in:
Eddie Hebert
2013-03-18 17:59:14 -04:00
parent 8f91711390
commit 77bc821025
2 changed files with 19 additions and 9 deletions
+5 -4
View File
@@ -52,10 +52,11 @@ class SlippageTestCase(TestCase):
slippage_model = VolumeShareSlippage()
open_orders = {133: [
Order(
{'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': 100,
'filled': 0, 'sid': 133})
Order(**{
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': 100,
'filled': 0,
'sid': 133})
]}
txn = slippage_model.simulate(
+14 -5
View File
@@ -28,10 +28,19 @@ log = Logger('Trade Simulation')
class Order(object):
def __init__(self, initial_values=None):
if initial_values:
self.__dict__ = initial_values
def __init__(self, dt, sid, amount, filled=0):
"""
@dt - datetime.datetime that the order was placed
@sid - stock sid of the order
@amount - the number of shares to buy/sell
a positive sign indicates a buy
a negative sign indicates a sell
@filled - how many shares of the order have been filled so far
"""
self.dt = dt
self.sid = sid
self.amount = amount
self.filled = filled
class TradeSimulationClient(object):
@@ -177,7 +186,7 @@ class AlgorithmSimulator(object):
Closure to pass into the user's algo to allow placing orders
into the transaction simulator's dict of open orders.
"""
order = Order({
order = Order(**{
'dt': self.simulation_dt,
'sid': sid,
'amount': int(amount),