-
Notifications
You must be signed in to change notification settings - Fork 205
/
Copy pathmain.py
27 lines (22 loc) · 896 Bytes
/
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
25
26
27
# usage: when generating the binding code, do cmake -DCCAPI_ENABLE_LOG_TRACE=ON ..., see https://github.com/crypto-chassis/ccapi#non-c
from threading import Lock
import time
from ccapi import Logger, Session, Subscription
class MyLogger(Logger):
def __init__(self):
super().__init__()
self._lock = Lock()
def logMessage(self, severity: str, threadId: str, timeISO: str, fileName: str, lineNumber: str, message: str) -> None:
self._lock.acquire()
print(f'{threadId}: [{timeISO}] {{{fileName}:{lineNumber}}} {severity}{" " * 8}{message}')
self._lock.release()
myLogger = MyLogger()
Logger.logger = myLogger
if __name__ == "__main__":
session = Session()
subscription = Subscription("coinbase", "BTC-USD", "MARKET_DEPTH")
session.subscribe(subscription)
time.sleep(10)
session.stop()
print("Bye")
Logger.logger = None