forked from crypto-chassis/ccapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
24 lines (24 loc) · 1.05 KB
/
main.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
import time
from ccapi import EventHandler, SessionOptions, SessionConfigs, Session, Subscription, Event
class MyEventHandler(EventHandler):
def __init__(self):
super().__init__()
def processEvent(self, event: Event, session: Session) -> bool:
if event.getType() == Event.Type_SUBSCRIPTION_DATA:
for message in event.getMessageList():
print(f'Best bid and ask at {message.getTimeISO()} are:')
for element in message.getElementList():
elementNameValueMap = element.getNameValueMap()
for name, value in elementNameValueMap.items():
print(f' {name} = {value}')
return True # This line is needed.
if __name__ == '__main__':
eventHandler = MyEventHandler()
option = SessionOptions()
config = SessionConfigs()
session = Session(option, config, eventHandler)
subscription = Subscription('coinbase', 'BTC-USD', 'MARKET_DEPTH')
session.subscribe(subscription)
time.sleep(10)
session.stop()
print('Bye')