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