-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_eti.py
139 lines (100 loc) · 3.53 KB
/
test_eti.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# SPDX-FileCopyrightText: © 2021 Georg Sauthoff <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
from eti.v9_0 import *
import dataclasses
import pytest
def test_logon():
x = LogonRequest()
assert x.MessageHeaderIn.TemplateID == 10000
assert x.MessageHeaderIn.BodyLen == 280
x.HeartBtInt = 2300000 # ms
assert x.DefaultCstmApplVerID == b'9.0'
x.ApplUsageOrders = ApplUsageOrders.AUTOMATED
x.ApplUsageQuotes = ApplUsageQuotes.AUTOMATED
x.OrderRoutingIndicator = OrderRoutingIndicator.NO
x.ApplicationSystemName = b'myRoboTrader'
x.ApplicationSystemVersion = b'1.666'
x.ApplicationSystemVendor = b'ACME Inc.'
x.PartyIDSessionID = 471142
x.Password = b'einsfueralles'
x.RequestHeader.MsgSeqNum = 1
x.RequestHeader.SenderSubID = 8150815 # not used for logon
bs = x.pack()
y = LogonRequest.create_from(bs)
cs = y.pack()
y.rstrip()
assert x == y
x.RequestHeader.MsgSeqNum = 2
assert x != y
x.RequestHeader.MsgSeqNum = 1
x.MessageHeaderIn.BodyLen = 100
assert x != y
assert bs == cs
def test_login():
x = UserLoginRequest()
assert x.MessageHeaderIn.TemplateID == 10018
assert x.MessageHeaderIn.BodyLen == 64
assert x.RequestHeader.SenderSubID == 0xffffffff # -> no-value, not used for login
x.RequestHeader.MsgSeqNum = 2
x.Username = 23
x.Password = b'P4s7w0rd'
bs = x.pack()
y = UserLoginRequest.create_from(bs)
cs = y.pack()
y.rstrip()
assert x == y
x.Username = 24
assert x != y
assert bs == cs
def test_order():
x = NewOrderSingleShortRequest()
x.ExecutingTrader = 1337
x.EnrichmentRuleID = 1
x.ApplSeqIndicator = ApplSeqIndicator.NO_RECOVERY_REQUIRED
x.PriceValidityCheckType = PriceValidityCheckType.NONE
x.ValueCheckTypeValue = ValueCheckTypeValue.DO_NOT_CHECK
x.OrderAttributeLiquidityProvision = OrderAttributeLiquidityProvision.N
x.TimeInForce = TimeInForce.IOC
x.ExecInst = ExecInst.Q # non-persistant order
x.TradingCapacity = TradingCapacity.MARKET_MAKER
x.PartyIdInvestmentDecisionMakerQualifier = PartyIdInvestmentDecisionMakerQualifier.ALGO
x.ExecutingTraderQualifier = ExecutingTraderQualifier.ALGO
x.RequestHeader.MsgSeqNum = 3
x.Side = Side.BUY
x.OrderQty = 42 * 10**4
x.SimpleSecurityID = 23
x.Price = 404 * 10**8
x.ClOrdID = 666
bs = x.pack()
y = NewOrderSingleShortRequest.create_from(bs)
cs = y.pack()
y.rstrip()
assert x == y
assert bs == cs
def test_unk_att_fails():
x = NewOrderSingleShortRequest()
with pytest.raises(AttributeError):
x.ExecutingTrada = 1337
def test_unpack_factory():
x = NewOrderSingleShortRequest()
x.ExecutingTrader = 1337
x.EnrichmentRuleID = 1
x.ApplSeqIndicator = ApplSeqIndicator.NO_RECOVERY_REQUIRED
x.PriceValidityCheckType = PriceValidityCheckType.NONE
x.ValueCheckTypeValue = ValueCheckTypeValue.DO_NOT_CHECK
x.OrderAttributeLiquidityProvision = OrderAttributeLiquidityProvision.N
x.TimeInForce = TimeInForce.IOC
x.ExecInst = ExecInst.Q # non-persistant order
x.TradingCapacity = TradingCapacity.MARKET_MAKER
x.PartyIdInvestmentDecisionMakerQualifier = PartyIdInvestmentDecisionMakerQualifier.ALGO
x.ExecutingTraderQualifier = ExecutingTraderQualifier.ALGO
x.RequestHeader.MsgSeqNum = 3
x.Side = Side.BUY
x.OrderQty = 42 * 10**4
x.SimpleSecurityID = 23
x.Price = 404 * 10**8
x.ClOrdID = 666
bs = x.pack()
y = unpack_from(bs)
y.rstrip()
assert x == y