mathpaquette / IQFeed.CSharpApiClient

IQFeed.CSharpApiClient is fastest and the most well-designed C# DTN IQFeed socket API connector available
MIT License
120 stars 43 forks source link

startDate endDate #147

Closed dutchy54321 closed 1 year ago

dutchy54321 commented 1 year ago

so I have some testcode

import sys
import clr
assembly_path = r'C:/Program Files/AmiBroker/IQFeedCSharpApiClient'
sys.path.append(assembly_path)
clr.AddReference("IQFeed.CSharpApiClient")
import time
import numpy as np
import pandas as pd
from IQFeed.CSharpApiClient.Lookup import LookupClientFactory
from IQFeed.CSharpApiClient.Lookup.Historical.Messages import TickMessage
from datetime import datetime

# Create Lookup client
lookupClient = LookupClientFactory.CreateNew()
# Connect
lookupClient.Connect()

now these two work:

1)

ticksFilename = lookupClient.Historical.File.GetHistoryTickDatapoints("@ES#",500,1)

2)

ticksFilename = lookupClient.Historical.File.GetHistoryTickDays("@ES#",3,None,None,None,1)

But I can not make the friqqin beginDate and endDate work. I tried many setups, here is 1:

# consider date in string format
start_date = "20221013 105902"
end_date = "20221014 105902"
# convert datetime string into date,month,day and
# hours:minutes:and seconds format using strptime
sd = datetime.strptime(start_date, "%Y%m%d %H%M%S")
ed = datetime.strptime(end_date, "%Y%m%d %H%M%S")
sd1 = sd.strftime("%Y%m%d %H%M%S")
ed1 = ed.strftime("%Y%m%d %H%M%S")
ticksFilename = lookupClient.Historical.File.GetHistoryTickTimeframe("@ES#",sd1,ed1,None,None,None,1)

or this:

# consider date in string format
start_date = "20221013"
end_date = "20221014"
# convert datetime string into date,month,day and
# hours:minutes:and seconds format using strptime
sd = datetime.strptime(start_date, "%Y%m%d")
ed = datetime.strptime(end_date, "%Y%m%d")
sd1 = sd.strftime("%Y%m%d")
ed1 = ed.strftime("%Y%m%d")
ticksFilename = lookupClient.Historical.File.GetHistoryTickTimeframe("@ES#",sd1,ed1,None,None,None,1)

what the hell is the trick here? Starting to PISS me off. because one can not get any reply on this. What the hell is the trick here?

dutchy54321 commented 1 year ago

i know the startDate and endDate are just strings

startDate = "20221013" endDate = "20221014"

should work but they do not. So something is wrong here.

this should work:

startDate = "20221013"
endDate = "20221014"
ticksFilename = lookupClient.Historical.File.GetHistoryTickTimeframe("@ES#",startDate,endDate,None,None,None,1)

but it does not work. So why not?

dutchy54321 commented 1 year ago

also passing them as type DateTime does not work. So I tested all types, str, int, datetime, nothing works

>>> d1 = datetime.datetime(2022, 10, 13, 9, 30, 0)
>>> d2 = datetime.datetime(2022, 10, 13, 9, 30, 0)
>>> d1
datetime.datetime(2022, 10, 13, 9, 30)
>>> d2
datetime.datetime(2022, 10, 13, 9, 30)
>>> ticksFilename = lookupClient.Historical.File.GetHistoryTickTimeframe("@ES#",d1,d2,None,None,None,1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: No method matches given arguments for GetHistoryTickTimeframe: (<class 'str'>, <class 'datetime.datetime'>, <class 'datetime.datetime'>, <class 'NoneType'>, <class 'NoneType'>, <class 'NoneType'>, <class 'int'>)
>>> type(d1)
<class 'datetime.datetime'>
dutchy54321 commented 1 year ago

well figured out the type needs to be: type: <class 'System.DateTime'>

dutchy54321 commented 1 year ago

for completion, the answer to my question is you need to load:

clr.AddReference('System.Collections')
from System import DateTime

then you can fill in the beginDate and endDate using:

    d1 = DateTime(2022,10,17,9,10,10)
    d2 = DateTime(2022,10,18,8,0,0)
    ticksFilename = lookupClient.Historical.File.GetHistoryTickTimeframe(sym,d1,d2,None,None,None,1)

the parameters used in DatetTime are Year, Month, Day, Hour, Minute, Second

works great

mathpaquette commented 1 year ago

@dutchy54321 please update the examples !

dutchy54321 commented 1 year ago

hi Math, you mean I post some Python code examples where I use your CSharp plugin?