which ticker opened/closed in notify_order
-
How can I tell which ticker symbol was opened or closed when notify_order is called?
-
notify_order
receives anorder
. And this contains several attributes includingdata
-
but data attribute does not include the ticker, or am I missing something?
what is the data attribute for the ticker symbol? -
That depends on the data source and what you have done (which we don't know). Data feeds have for example an parameter
dataname
which is the parameter you use to create them. And they can also be assigned a name incerebro.adddata
which is later available as_name
But at the end of the day it's up to you and your data feed.
-
I added the data source with
data = bt.feeds.QuandlCSV(dataname="+ticker[0]+".csv",...)
but when calling print(order.data._name) I get the name of the ticker for datas[0] every time, regardless of the order sent to the print command, BTW all other parameters are displayed OK, only the _name is the same.
it should be basic and intuitive to get the ticker symbol. -
Although your explanation for sure makes sense for you, it doesn't make any sense here.
@Alon-Horesh said in which ticker opened/closed in notify_order:
I added the data source with
data = bt.feeds.QuandlCSV(dataname="+ticker[0]+".csv",...)You didn't add anything. You created it.
@Paska-Houso said in which ticker opened/closed in notify_order:
And they can also be assigned a name in cerebro.adddata which is later available as _name
From my own comment above, it should be clear that
_name
is only available when provided withcerebro.adddata
. See the linked doc forcerebro
it should be basic and intuitive to get the ticker symbol.
Subclass, add your own field ticker and get it. There is no code and not much can be said. You can read the linked docs and then work it out. Or you can further complain.
-
the data was added using cerebro.adddata
for ticker in tickers:
# Create a Data Feed
data = bt.feeds.QuandlCSV(
dataname='ticker[0]+'.csv',
fromdate=datetime.datetime(2013, 1, 1),
todate=datetime.datetime(2016, 12, 29),
adjclose=False, reverse=True)
# Add the Data Feed to Cerebro
cerebro.adddata(data) -
here is the entire code sample:
# Create a cerebro entity
cerebro = bt.Cerebro()# load symbol list from file with open('list.txt', 'r') as f: reader = csv.reader(f) tickers = list(reader) for ticker in tickers: # Create a Data Feed data = bt.feeds.QuandlCSV( dataname=ticker[0]+'.csv', fromdate=datetime.datetime(2013, 1, 1), todate=datetime.datetime(2016, 12, 29), adjclose=False, reverse=True) # Add the Data Feed to Cerebro cerebro.adddata(data)
-
@Alon-Horesh said in which ticker opened/closed in notify_order:
cerebro.adddata(data)
No
name
is being assigned when usingaddata
-
cerebro.adddata(data,name=ticker[0])
-
the problem is solved on another line:
self.buy(data = ticker_data,...)