-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathstream.py
More file actions
executable file
·76 lines (59 loc) · 1.69 KB
/
stream.py
File metadata and controls
executable file
·76 lines (59 loc) · 1.69 KB
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
#!/usr/bin/env python
import argparse
import common.config
import common.args
from .view import price_to_string, heartbeat_to_string
def main():
"""
Stream the prices for a list of Instruments for the active Account.
"""
parser = argparse.ArgumentParser()
common.config.add_argument(parser)
parser.add_argument(
'--instrument', "-i",
type=common.args.instrument,
required=True,
action="append",
help="Instrument to get prices for"
)
parser.add_argument(
'--snapshot',
action="store_true",
default=True,
help="Request an initial snapshot"
)
parser.add_argument(
'--no-snapshot',
dest="snapshot",
action="store_false",
help="Do not request an initial snapshot"
)
parser.add_argument(
'--show-heartbeats', "-s",
action='store_true',
default=False,
help="display heartbeats"
)
args = parser.parse_args()
account_id = args.config.active_account
api = args.config.create_streaming_context()
# api.set_convert_decimal_number_to_native(False)
# api.set_stream_timeout(3)
#
# Subscribe to the pricing stream
#
response = api.pricing.stream(
account_id,
snapshot=args.snapshot,
instruments=",".join(args.instrument),
)
#
# Print out each price as it is received
#
for msg_type, msg in response.parts():
if msg_type == "pricing.PricingHeartbeat" and args.show_heartbeats:
print(heartbeat_to_string(msg))
elif msg_type == "pricing.ClientPrice":
print(price_to_string(msg))
if __name__ == "__main__":
main()