From 42aab0cfbb5ecda81b99383eb67942452d6fca41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=82=8B=E3=81=BF?= Date: Fri, 15 Apr 2022 15:35:29 +0800 Subject: [PATCH] python: move examples --- python/{ => examples}/query_klines.py | 0 python/{ => examples}/stream.py | 0 python/{ => examples}/subscribe.py | 0 python/examples/subscribe_user_data.py | 24 ++++++++++++++++++++++++ 4 files changed, 24 insertions(+) rename python/{ => examples}/query_klines.py (100%) rename python/{ => examples}/stream.py (100%) rename python/{ => examples}/subscribe.py (100%) create mode 100644 python/examples/subscribe_user_data.py diff --git a/python/query_klines.py b/python/examples/query_klines.py similarity index 100% rename from python/query_klines.py rename to python/examples/query_klines.py diff --git a/python/stream.py b/python/examples/stream.py similarity index 100% rename from python/stream.py rename to python/examples/stream.py diff --git a/python/subscribe.py b/python/examples/subscribe.py similarity index 100% rename from python/subscribe.py rename to python/examples/subscribe.py diff --git a/python/examples/subscribe_user_data.py b/python/examples/subscribe_user_data.py new file mode 100644 index 000000000..9db07d6df --- /dev/null +++ b/python/examples/subscribe_user_data.py @@ -0,0 +1,24 @@ +import grpc +from loguru import logger + +import bbgo_pb2 +import bbgo_pb2_grpc +from bbgo.data import UserDataEvent + + +def main(): + host = '127.0.0.1' + port = 50051 + address = f'{host}:{port}' + channel = grpc.insecure_channel(address) + stub = bbgo_pb2_grpc.UserDataServiceStub(channel) + + request = bbgo_pb2.UserDataRequest(session='max') + response_iter = stub.Subscribe(request) + for response in response_iter: + event = UserDataEvent.from_pb(response) + logger.info(event) + + +if __name__ == '__main__': + main()