-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathexample_app_equities.py
More file actions
90 lines (72 loc) · 3.13 KB
/
example_app_equities.py
File metadata and controls
90 lines (72 loc) · 3.13 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import threading
import signal
import time
import sys
import datetime
from threading import Timer,Thread,Event,Lock
from intriniorealtime.equities_client import IntrinioRealtimeEquitiesClient
from intriniorealtime.equities_replay_client import IntrinioReplayEquitiesClient
from intriniorealtime.equities_client import EquitiesQuote
from intriniorealtime.equities_client import EquitiesTrade
equities_trade_count = 0
equities_ask_count = 0
equities_bid_count = 0
equities_backlog_count = 0
def on_quote(quote, backlog):
global equities_ask_count
global equities_bid_count
global equities_backlog_count
equities_backlog_count = backlog
if isinstance(quote, EquitiesQuote) and 'type' in quote.__dict__:
if quote.type == "ask": equities_ask_count += 1
else: equities_bid_count += 1
def on_trade(trade, backlog):
global equities_trade_count
global equities_backlog_count
equities_backlog_count = backlog
equities_trade_count += 1
class Summarize(threading.Thread):
def __init__(self, stop_flag):
threading.Thread.__init__(self, group=None, args=(), kwargs={})
self.daemon = True
self.stop_flag = stop_flag
def run(self):
global equities_trade_count
global equities_bid_count
global equities_ask_count
global equities_backlog_count
while not self.stop_flag.wait(5):
print("trades: " + str(equities_trade_count) + "; asks: " + str(equities_ask_count) + "; bids: " + str(equities_bid_count) + "; backlog: " + str(equities_backlog_count))
configuration = {
'api_key': 'API_KEY_HERE',
'provider': 'IEX' # 'REALTIME' (IEX), or 'IEX', or 'DELAYED_SIP', or 'NASDAQ_BASIC', or 'CBOE_ONE', or 'EQUITIES_EDGE'
# ,'delayed': True # Add this if you have realtime (nondelayed) access and want to force delayed mode. If you only have delayed mode access, this is redundant.
# ,'replay_date': datetime.date.today() - datetime.timedelta(days=1) # needed for ReplayClient. The date to replay.
# ,'with_simulated_delay': False # needed for ReplayClient. This plays back the events at the same rate they happened in market.
# ,'delete_file_when_done': True # needed for ReplayClient
# ,'write_to_csv': False # needed for ReplayClient
# ,'csv_file_path': 'data.csv' # needed for ReplayClient
# ,'bypass_parsing': True # if you want to handle parsing yourself, set this to True. Otherwise, leave it alone.
# ,'debug': True
# ,'max_queue_size': 250000
}
client = IntrinioRealtimeEquitiesClient(configuration, on_trade, on_quote)
# client = IntrinioReplayClient(options, on_trade, on_quote)
stop_event = Event()
def on_kill_process(sig, frame):
print("Stopping")
stop_event.set()
client.disconnect()
sys.exit(0)
signal.signal(signal.SIGINT, on_kill_process)
client.connect()
client.join(['AAPL','GE','MSFT'])
# client.join(['lobby'])
summarize_thread = Summarize(stop_event)
summarize_thread.start()
time.sleep(60 * 60 * 24)
# sigint, or ctrl+c, during the thread wait will also perform the same below code.
print("Stopping")
stop_event.set()
client.disconnect()
sys.exit(0)