forked from robcarver17/pysystemtrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathib_fx_handling.py
54 lines (43 loc) · 1.6 KB
/
ib_fx_handling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from syscore.constants import arg_not_supplied
from syslogging.logger import *
from sysbrokers.IB.client.ib_fx_client import ibFxClient
from sysbrokers.IB.ib_connection import connectionIB
from sysbrokers.IB.ib_translate_broker_order_objects import tradeWithContract
from sysbrokers.broker_fx_handling import brokerFxHandlingData
from sysdata.data_blob import dataBlob
class ibFxHandlingData(brokerFxHandlingData):
def __init__(
self,
ibconnection: connectionIB,
data: dataBlob,
log=get_logger("ibFXHandlingData"),
):
super().__init__(log=log, data=data)
self._ibconnection = ibconnection
self._data = data
def __repr__(self):
return "IB FX handling data %s" % str(self.ib_client)
@property
def ibconnection(self) -> connectionIB:
return self._ibconnection
@property
def ib_client(self) -> ibFxClient:
client = getattr(self, "_ib_client", None)
if client is None:
client = self._ib_client = ibFxClient(
ibconnection=self.ibconnection, log=self.log
)
return client
def broker_fx_balances(self, account_id: str = arg_not_supplied) -> dict:
return self.ib_client.broker_fx_balances(account_id)
def broker_fx_market_order(
self,
trade: float,
ccy1: str,
account_id: str = arg_not_supplied,
ccy2: str = "USD",
) -> tradeWithContract:
submitted_fx_trade = self.ib_client.broker_fx_market_order(
trade, ccy1, account_id=account_id, ccy2=ccy2
)
return submitted_fx_trade