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()