bbgo_origin/python/stream.py

28 lines
602 B
Python
Raw Normal View History

2022-04-13 06:52:34 +00:00
import click
from loguru import logger
from bbgo import Stream
2022-04-13 10:11:21 +00:00
from bbgo.data import Event
from bbgo.handlers import UpdateHandler
2022-04-13 06:52:34 +00:00
2022-04-13 10:11:21 +00:00
class LogBook(UpdateHandler):
2022-04-13 06:52:34 +00:00
2022-04-13 10:11:21 +00:00
def handle(self, event: Event) -> None:
2022-04-13 06:52:34 +00:00
logger.info(event)
2022-04-13 10:11:21 +00:00
@click.command()
@click.option('--host', default='127.0.0.1')
@click.option('--port', default=50051)
def main(host, port):
stream = Stream(host, port)
stream.subscribe('max', 'book', 'BTCUSDT', 'full')
stream.subscribe('max', 'book', 'ETHUSDT', 'full')
stream.add_event_handler(LogBook())
2022-04-13 06:52:34 +00:00
stream.start()
if __name__ == '__main__':
main()