-
Notifications
You must be signed in to change notification settings - Fork 3
/
ApplicationMsgUtil.py
64 lines (59 loc) · 2.37 KB
/
ApplicationMsgUtil.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
55
56
57
58
59
60
61
62
63
64
import FIXPMsgUtil
from typing import Dict
import Constant
from datetime import datetime
class ApplicationMsgUtil:
@staticmethod
def create_application_msg(msg_type: str):
msg = dict()
msg['MsgType'] = msg_type
return msg
@staticmethod
def decorate_application_msg(msg: dict):
msg['ApplVerID'] = Constant.APPL_VER_ID
msg['SendingTime'] = datetime.now().isoformat()
return msg
@staticmethod
def create_new_single_order(account: str,
client_order_id: str,
security_id: str,
side: str,
order_qty: str,
ord_typ: str,
currency: str,
time_in_force: str,
price: str = None,
expire_time: str = None):
# {"MsgType": "NewOrderSingle",
# "ApplVerID": "FIX50SP2",
# "CstmApplVerID": "IGUS/Trade/V1",
# "SendingTime": "20190802-21:14:38.717",
# "ClOrdID": "12345",
# "Account": "PDKKL",
# "SecurityID": "CS.D.GBPUSD.CZD.IP",
# "SecurityIDSource": "MarketplaceAssignedIdentifier",
# "Side": "Buy",
# "TransactTime": "20190802-21:14:38.717",
# "OrderQty": "6",
# "OrdTyp": "2",
# "Price": "34.444",
# "Currency": "USD",
# "TimeInForce": "GoodTillDate",
# "ExpireTime": "20190802-17:00:00.000" }
msg: dict = ApplicationMsgUtil.create_application_msg("NewOrderSingle")
msg = ApplicationMsgUtil.decorate_application_msg(msg)
msg['ClOrdID'] = client_order_id
msg['Account'] = account
msg['SecurityID'] = security_id
msg['SecurityIDSource'] = "MarketplaceAssignedIdentifier"
msg['Side'] = side
msg['OrderQty'] = order_qty
msg['OrdType'] = ord_typ
if expire_time is not None:
msg['Price'] = price
msg['Currency'] = currency
msg['TimeInForce'] = time_in_force
if expire_time is not None:
msg['ExpireTime'] = expire_time
msg['TransactTime'] = msg['SendingTime']
return msg