BUG: Fix a bug causing us to discard very low limit prices.

Fixes an issue where very low limit prices were being rounded to 0.0 and
effectively resulting in market orders.  Adds an explicit check to test for
this behavior.
This commit is contained in:
Scott Sanderson
2014-04-21 17:01:35 -04:00
parent 574415f434
commit eadf9d27e8
2 changed files with 10 additions and 4 deletions
+4 -4
View File
@@ -296,10 +296,10 @@ class Order(object):
self.amount = int(self.amount / ratio)
if self.limit:
if self.limit is not None:
self.limit = round(self.limit * ratio, 2)
if self.stop:
if self.stop is not None:
self.stop = round(self.stop * ratio, 2)
@property
@@ -324,10 +324,10 @@ class Order(object):
For a stop order, True IFF stop_reached.
For a limit order, True IFF limit_reached.
"""
if self.stop and not self.stop_reached:
if self.stop is not None and not self.stop_reached:
return False
if self.limit and not self.limit_reached:
if self.limit is not None and not self.limit_reached:
return False
return True
+6
View File
@@ -424,6 +424,12 @@ class AmbitiousStopLimitAlgorithm(TradingAlgorithm):
# prevent trigger).
self.order(self.sid, -100, limit_price=1, stop_price=1)
###################
# Rounding Checks #
###################
self.order(self.sid, 100, limit_price=.00000001)
self.order(self.sid, -100, stop_price=.00000001)
##########################################
# Algorithm using simple batch transforms