One last question on this, as mentionned, I did use a csv file with the exact same column structure as in your example (columns=[bid, ask, datetime in last position]). The original file however come with the following structure [symbol, datetime, bid, ask] as show here:
EUR/USD,20180201 00:00:00.125,1.24171,1.24173
EUR/USD,20180201 00:00:00.262,1.24172,1.24173
EUR/USD,20180201 00:00:00.695,1.24172,1.24175
EUR/USD,20180201 00:00:00.838,1.24173,1.24178
EUR/USD,20180201 00:00:00.848,1.24174,1.24177
Thus modifing the BidAskCSV class:
class BidAskCSV(btfeeds.GenericCSVData):
linesoverride = True # discard usual OHLC structure
# datetime must be present and last
lines = ('PAIR','datetime','bid', 'ask')
# datetime (always 1st) and then the desired order for
params = (
('PAIR', 0), # inherited from parent class
('datetime', 1), # inherited from parent class
('bid', 2), # default field pos 1
('ask', 3) # default field pos 2
)
The above won't work due to lines = ('PAIR','datetime','bid', 'ask') however replacing the section below instead is not returning an error message and so seems to be working fine:
lines = ('datetime','bid', 'ask')
I understand that the field 'PAIR' being a string is what is causing the error (code section below from -loadline), thus my questions:
What is the underlying rationale ? Is it because "lines" should only refers to preset categories defined in BT (datetime, OHLV, volume, etc...)?
What is the impact of simply not mentioning "PAIR" in the "lines" list (if any)?
for linefield in (x for x in self.getlinealiases() if x != 'datetime'):
# Get the index created from the passed params
csvidx = getattr(self.params, linefield)
if csvidx is None or csvidx < 0:
# the field will not be present, assignt the "nullvalue"
csvfield = self.p.nullvalue
else:
# get it from the token
csvfield = linetokens[csvidx]
if csvfield == '':
# if empty ... assign the "nullvalue"
csvfield = self.p.nullvalue
# get the corresponding line reference and set the value
line = getattr(self.lines, linefield)
line[0] = float(float(csvfield))# Why is the expectation to ALWAYS have a float - can it be changed for more flexibility? (cg 'PAIR' filed in TruFX import - Error message
return True