Skip to content

Commit a31e94d

Browse files
chipkentFirelement
andauthored
Support the crypto in the ibapi 10.16.01 (#66)
* Updated code to work with crypto data and added code for code review. * Updated git ignore * Updates to remove uneeded files * Removed example code * updated Dockerfile * Fixed .gitignore * Added crypto to the read only example * Updated install with extra pip installs Co-authored-by: joshuahilgartner <32405513+Firelement@users.noreply.github.com>
1 parent a3235c3 commit a31e94d

File tree

11 files changed

+105
-20
lines changed

11 files changed

+105
-20
lines changed

.github/workflows/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ FROM ubuntu:22.04
44
ARG IB_VERSION
55

66
RUN apt update && \
7-
apt install -y openjdk-11-jdk python3-pip curl zip
7+
apt install -y openjdk-11-jdk python3-pip curl zip && \
8+
pip3 install --upgrade pip setuptools wheel
89

910
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
1011

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ dist
44
src/deephaven_ib.egg-info
55
docker/data
66
docker/*/data
7-
docker/*/build
7+
docker/*/build
8+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ new feature and has not been well tested. To do this:
234234
```
235235
4) Install [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib):
236236
```bash
237+
pip3 install --upgrade pip setuptools wheel
237238
pip3 install deephaven-ib
238239
```
239240
5) Install Java 11 and set the appropriate `JAVA_HOME` environment variable.

docker/dev/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN apt update && \
1212
apt install -y openjdk-11-jdk && \
1313
ln -s /usr/lib/jvm/java-11-openjdk-*/ /usr/lib/jvm/java-11-openjdk && \
1414
apt install --yes git python3-venv python3-pip && \
15-
pip3 install --upgrade setuptools wheel build twine
15+
pip3 install --upgrade pip setuptools wheel build twine
1616

1717
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk
1818

docker/release/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ FROM ubuntu:22.04
77
RUN apt update && \
88
apt install -y openjdk-11-jdk python3-pip && \
99
ln -s /usr/lib/jvm/java-11-openjdk-*/ /usr/lib/jvm/java-11-openjdk && \
10+
pip3 install --upgrade pip setuptools wheel
1011

1112
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk/
1213

examples/example_all_functionality.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,42 @@ def get_contracts() -> Dict[str, Contract]:
331331
client.request_bars_historical(rc, duration=dhib.Duration.days(22), bar_size=dhib.BarSize.DAY_1,
332332
bar_type=dhib.BarDataType.YIELD_LAST, keep_up_to_date=False)
333333

334+
print("==============================================================================================================")
335+
print("==== Request bars (Crypto).")
336+
print("==============================================================================================================")
337+
338+
contract = Contract()
339+
contract.symbol = "BTC"
340+
contract.secType = "CRYPTO"
341+
contract.exchange = "PAXOS"
342+
contract.currency = "USD"
343+
344+
rc = client.get_registered_contract(c2)
345+
client.request_bars_historical(rc2, duration=dhib.Duration.days(253),
346+
bar_size=dhib.BarSize.DAY_1,
347+
bar_type=dhib.BarDataType.AGGTRADES,
348+
keep_up_to_date = False
349+
)
350+
client.request_bars_realtime(rc2, bar_type=dhib.BarDataType.TRADES)
351+
352+
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
353+
bar_type=dhib.BarDataType.MIDPOINT)
354+
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
355+
bar_type=dhib.BarDataType.BID)
356+
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
357+
bar_type=dhib.BarDataType.ASK)
358+
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
359+
bar_type=dhib.BarDataType.BID_ASK, keep_up_to_date=False)
360+
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
361+
bar_type=dhib.BarDataType.AGGTRADES)
362+
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
363+
bar_type=dhib.BarDataType.ADJUSTED_LAST, keep_up_to_date=False)
364+
365+
client.request_bars_realtime(rc, bar_type=dhib.BarDataType.MIDPOINT)
366+
client.request_bars_realtime(rc, bar_type=dhib.BarDataType.BID)
367+
client.request_bars_realtime(rc, bar_type=dhib.BarDataType.ASK)
368+
client.request_bars_realtime(rc, bar_type=dhib.BarDataType.TRADES)
369+
334370
print("==============================================================================================================")
335371
print("==== Request tick data.")
336372
print("==============================================================================================================")

examples/example_read_only_functionality.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,42 @@ def get_contracts() -> Dict[str, Contract]:
327327
client.request_bars_historical(rc, duration=dhib.Duration.days(22), bar_size=dhib.BarSize.DAY_1,
328328
bar_type=dhib.BarDataType.YIELD_LAST, keep_up_to_date=False)
329329

330+
print("==============================================================================================================")
331+
print("==== Request bars (Crypto).")
332+
print("==============================================================================================================")
333+
334+
contract = Contract()
335+
contract.symbol = "BTC"
336+
contract.secType = "CRYPTO"
337+
contract.exchange = "PAXOS"
338+
contract.currency = "USD"
339+
340+
rc = client.get_registered_contract(c2)
341+
client.request_bars_historical(rc2, duration=dhib.Duration.days(253),
342+
bar_size=dhib.BarSize.DAY_1,
343+
bar_type=dhib.BarDataType.AGGTRADES,
344+
keep_up_to_date = False
345+
)
346+
client.request_bars_realtime(rc2, bar_type=dhib.BarDataType.TRADES)
347+
348+
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
349+
bar_type=dhib.BarDataType.MIDPOINT)
350+
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
351+
bar_type=dhib.BarDataType.BID)
352+
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
353+
bar_type=dhib.BarDataType.ASK)
354+
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
355+
bar_type=dhib.BarDataType.BID_ASK, keep_up_to_date=False)
356+
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
357+
bar_type=dhib.BarDataType.AGGTRADES)
358+
client.request_bars_historical(rc, duration=dhib.Duration.days(10), bar_size=dhib.BarSize.MIN_5,
359+
bar_type=dhib.BarDataType.ADJUSTED_LAST, keep_up_to_date=False)
360+
361+
client.request_bars_realtime(rc, bar_type=dhib.BarDataType.MIDPOINT)
362+
client.request_bars_realtime(rc, bar_type=dhib.BarDataType.BID)
363+
client.request_bars_realtime(rc, bar_type=dhib.BarDataType.ASK)
364+
client.request_bars_realtime(rc, bar_type=dhib.BarDataType.TRADES)
365+
330366
print("==============================================================================================================")
331367
print("==== Request tick data.")
332368
print("==============================================================================================================")

src/deephaven_ib/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ class BarDataType(Enum):
150150
"""Bid/Ask yield."""
151151
YIELD_LAST = 14
152152
"""Last yield."""
153-
153+
AGGTRADES = 15
154+
"""Aggregate trade prices."""
154155

155156
class BarSize(Enum):
156157
"""Bar data sizes."""
@@ -966,7 +967,7 @@ def request_bars_realtime(self, contract: RegisteredContract, bar_type: BarDataT
966967
self._assert_connected()
967968
requests = []
968969

969-
if bar_type not in [BarDataType.TRADES, BarDataType.MIDPOINT, BarDataType.BID, BarDataType.ASK]:
970+
if bar_type not in [BarDataType.TRADES, BarDataType.AGGTRADES, BarDataType.MIDPOINT, BarDataType.BID, BarDataType.ASK]:
970971
raise Exception(f"Unsupported bar type: {bar_type}")
971972

972973
for cd in contract.contract_details:

src/deephaven_ib/_internal/tablewriter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from deephaven.table import Table
1111
from deephaven import dtypes
1212
from deephaven.dtypes import DType
13+
import decimal
14+
from decimal import Decimal
1315

1416
from .trace import trace_str
1517

@@ -67,6 +69,10 @@ def write_row(self, values: List) -> None:
6769
if self._receive_time:
6870
values.insert(0, now())
6971

72+
for i in range(len(values)):
73+
if isinstance(values[i], decimal.Decimal):
74+
values[i] = float(values[i])
75+
7076
self._check_logged_value_types(values)
7177

7278
for i in self._string_indices:

src/deephaven_ib/_tws/ib_type_logger.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def map_sec_id_list(value):
141141
("LiquidHours", dtypes.StringSet, lambda cd: to_string_set(cd.liquidHours.split(";"))),
142142
("EvRule", dtypes.string, lambda cd: cd.evRule),
143143
("EvMultiplier", dtypes.int64, lambda cd: cd.evMultiplier),
144-
("MdSizeMultiplier", dtypes.int64, lambda cd: cd.mdSizeMultiplier),
145144
("AggGroup", dtypes.int64, lambda cd: map_null_int(cd.aggGroup)),
146145
("UnderSymbol", dtypes.string, lambda cd: cd.underSymbol),
147146
("UnderSecType", dtypes.string, lambda cd: cd.underSecType),
@@ -218,9 +217,9 @@ def parse_timestamp(bd):
218217
("High", dtypes.float64, lambda bd: bd.high),
219218
("Low", dtypes.float64, lambda bd: bd.low),
220219
("Close", dtypes.float64, lambda bd: bd.close),
221-
("Volume", dtypes.int64, lambda bd: map_null(bd.volume)),
220+
("Volume", dtypes.float64, lambda bd: map_null(bd.volume)),
222221
("BarCount", dtypes.int64, lambda bd: map_null(bd.barCount)),
223-
("Average", dtypes.float64, lambda bd: map_null(bd.average)),
222+
("WAP", dtypes.float64, lambda bd: map_null(bd.wap)),
224223
]
225224

226225

@@ -245,7 +244,7 @@ def map_null(val):
245244
("High", dtypes.float64, lambda bd: bd.high),
246245
("Low", dtypes.float64, lambda bd: bd.low),
247246
("Close", dtypes.float64, lambda bd: bd.close),
248-
("Volume", dtypes.int64, lambda bd: map_null(bd.volume)),
247+
("Volume", dtypes.float64, lambda bd: map_null(bd.volume)),
249248
("WAP", dtypes.float64, lambda bd: map_null(bd.wap)),
250249
("Count", dtypes.int64, lambda bd: map_null(bd.count)),
251250
]
@@ -330,7 +329,7 @@ def map_special_conditions(special_conditions: str) -> Any:
330329
return [
331330
("Timestamp", dtypes.DateTime, lambda t: unix_sec_to_dh_datetime(t.time)),
332331
("Price", dtypes.float64, lambda t: t.price),
333-
("Size", dtypes.int64, lambda t: t.size),
332+
("Size", dtypes.float64, lambda t: t.size),
334333
*_include_details(_details_tick_attrib_last(), lambda t: t.tickAttribLast),
335334
("Exchange", dtypes.string, lambda t: t.exchange),
336335
("SpecialConditions", dtypes.StringSet, lambda t: map_special_conditions(t.specialConditions))

0 commit comments

Comments
 (0)