-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_eti.py
76 lines (59 loc) · 2.27 KB
/
bench_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
# SPDX-FileCopyrightText: © 2021 Georg Sauthoff <mail@gms.tf>
# SPDX-License-Identifier: GPL-3.0-or-later
from eti.v9_0 import *
def modify_ioc(x, bs):
x.RequestHeader.MsgSeqNum += 1
x.OrderQty = (x.OrderQty + 1) % (2**64 - 1)
x.Price = (x.Price + 1) % (2**63 - 1)
x.ClOrdID = (x.ClOrdID + 1) % (2**64 - 1)
return x.pack_into(bs)
def test_pack_ioc(benchmark):
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.Side = Side.BUY
x.SimpleSecurityID = 23
x.RequestHeader.MsgSeqNum = 3
x.OrderQty = 42 * 10**4
x.Price = 404 * 10**8
x.ClOrdID = 666
bs = bytearray(96)
n = benchmark(modify_ioc, x, bs)
assert n == 96
def unpack_ioc(bs, x):
x.unpack_from(bs)
return x
def test_unpack_ioc(benchmark):
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.Side = Side.BUY
x.SimpleSecurityID = 23
x.RequestHeader.MsgSeqNum = 3
x.OrderQty = 42 * 10**4
x.Price = 404 * 10**8
x.ClOrdID = 666
bs = bytearray(96)
x.pack_into(bs)
y = NewOrderSingleShortRequest()
y = benchmark(unpack_ioc, bs, y)
y.rstrip()
assert y == x