forked from mattsta/ib_insync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix message sending with unqualified contracts
Error introduced during refactor of comparing against tuples to now comparing against sets. Unqualified contracts aren't hashable so they can't compare against sets, but they could compare against the previous tuples without errors. Fixed by refactoring the entire message sending logic to be faster and use direct comparison of matching types instead of walking a 5-7 stage if-else tree. Also extended error message for contract hash errors (still needs some improvements, contracts should probably hash by conId+exchange+currency instead of only conId). Fixes mattsta#4 Closes mattsta#5
- Loading branch information
Showing
6 changed files
with
140 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ html | |
doctrees | ||
ib_async.egg-info | ||
poetry.lock | ||
*.csv | ||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import ib_async | ||
from ib_async import * | ||
|
||
import pandas as pd | ||
|
||
|
||
def test_contract_format_data_pd(): | ||
"""Simple smoketest to verify everything still works minimally.""" | ||
ib = ib_async.IB() | ||
ib.connect("127.0.0.1", 4001, clientId=90, readonly=True) | ||
|
||
symbols = ["AMZN", "TSLA"] | ||
|
||
# Method to get OHLCV | ||
def get_OHLCV( | ||
symbol, | ||
endDateTime="", | ||
durationStr="1 D", | ||
barSizeSetting="1 hour", | ||
whatToShow="TRADES", | ||
useRTH=False, | ||
formatDate=1, | ||
): | ||
bars = ib.reqHistoricalData( | ||
symbol, | ||
endDateTime, | ||
durationStr, | ||
barSizeSetting, | ||
whatToShow, | ||
useRTH, | ||
formatDate, | ||
) | ||
df = util.df(bars) | ||
df["date"] = df["date"].dt.tz_convert("America/New_York") | ||
df = df.drop(columns=["average", "barCount"]) | ||
# df.set_index("date", inplace=True) | ||
|
||
print("\n", df) | ||
|
||
# df = df.iloc[::-1] | ||
# df.to_csv("{}.csv".format(symbol.symbol)) | ||
# df = pd.read_csv("{}.csv".format(symbol.symbol)) | ||
df.columns = ["date", "open", "high", "low", "close", "volume"] | ||
|
||
df["date"] = pd.to_datetime(df["date"]) | ||
df.set_index("date", inplace=True) | ||
|
||
print(f"Data for {symbol.symbol} downloaded OK with OLD") | ||
return df | ||
|
||
for symbol_str in symbols: | ||
symbol = Stock(symbol_str, "SMART", "USD") | ||
df = get_OHLCV(symbol) |