如何获得订单提交的价格



这是我的代码

class TestStrategy(bt.Strategy):
params = dict(
stop_loss=0.02,  # price is 2% less than the entry point
trail=False,
)
def log(self, txt, dt=None):
''' Logging function fot this strategy'''
dt = dt or self.datas[0].datetime.date(0)
print('%s, %s' % (dt.isoformat(), txt))
def __init__(self):
# Keep a reference to the "close" line in the data[0] dataseries
self.dataclose = self.datas[0].close
self.bearish = pd.read_csv('bearish_comments.csv')
self.bullish = pd.read_csv('bullish_comments.csv')
self.bearish['dt'] = pd.to_datetime(self.bearish['dt'])
self.bullish['dt'] = pd.to_datetime(self.bullish['dt'])
self.bullish['tt'] = np.where(self.bullish['TSLA'] > (2 * self.bearish['TSLA']), True, False)
self.order = None
self.buyprice = None
self.buycomm = None
def notify_order(self, order):
self.order = None
def next(self):
dt = self.datas[0].datetime.date(0)
# Simply log the closing price of the series from the reference
buy = self.bullish[self.bullish['dt'].isin(
[datetime.datetime(dt.year, dt.month, dt.day, 0, 0, 0, 0),
datetime.datetime(dt.year, dt.month, dt.day, 23, 59, 59, 99)])].iloc[0].tt
self.log('Close, %.2f' % self.dataclose[0])
print(buy)
if self.order:
return
if not self.position:
if buy:
# BUY, BUY, BUY!!! (with all possible default parameters)
self.log('BUY CREATE, %.2f' % self.dataclose[0])
self.order = self.buy()
print(self.order)
else:
if buy == False:
if self.dataclose[0] >= ((self.order * 0.01) + self.order):
# TAKE PROFIT!!! (with all possible default parameters)
self.log('TAKE PROFIT, %.2f' % self.dataclose[0])
self.order = self.sell()

对于line

if self.dataclose[0] >= ((self.order * 0.01) + self.order):

当我使用self。TypeError:不支持*:'NoneType'和'float'的操作数类型所以我想做的是获得订单的价格,然后在买入价格上涨1%时获利

这个错误是不言自明的:变量self.orderNone,所以它还没有被赋值。

在我看来,这一定发生在你在买进之前卖出的时候。

相关内容

  • 没有找到相关文章

最新更新