Skip to content

Commit 983a19d

Browse files
WS API
1 parent c68c7f2 commit 983a19d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

binance_websocket_api_futures.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
# -*- coding: utf-8 -*-
33
# ¯\_(ツ)_/¯
44

5+
from dotenv import load_dotenv
56
from unicorn_binance_websocket_api import BinanceWebSocketApiManager
67
import asyncio
78
import logging
89
import os
910

10-
api_key = ""
11-
api_secret = ""
1211
market = "BTCUSDC"
1312

1413
async def binance_api(ubwa):
@@ -17,7 +16,9 @@ async def handle_socket_message(stream_id=None):
1716
data = await ubwa.get_stream_data_from_asyncio_queue(stream_id=stream_id)
1817
print(f"received data:\r\n{data}\r\n")
1918

20-
api_stream = ubwa.create_stream(api=True, api_key=api_key, api_secret=api_secret,
19+
api_stream = ubwa.create_stream(api=True,
20+
api_key=os.getenv('BINANCE_API_KEY'),
21+
api_secret=os.getenv('BINANCE_API_SECRET'),
2122
stream_label="Bobs Future Websocket API",
2223
process_asyncio_queue=handle_socket_message)
2324
print(f"Start:")
@@ -42,6 +43,7 @@ async def handle_socket_message(stream_id=None):
4243
filename=os.path.basename(__file__) + '.log',
4344
format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
4445
style="{")
46+
load_dotenv()
4547

4648
# To use this library you need a valid UNICORN Binance Suite License:
4749
# https://shop.lucit.services

binance_websocket_api_spot.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
# -*- coding: utf-8 -*-
33
# ¯\_(ツ)_/¯
44

5+
from dotenv import load_dotenv
56
from unicorn_binance_websocket_api import BinanceWebSocketApiManager
67
import asyncio
78
import logging
89
import os
910

10-
api_key = ""
11-
api_secret = ""
1211
market = "BTCUSDT"
1312

1413
async def binance_api(ubwa):
@@ -17,7 +16,9 @@ async def handle_socket_message(stream_id=None):
1716
data = await ubwa.get_stream_data_from_asyncio_queue(stream_id=stream_id)
1817
print(f"received data:\r\n{data}\r\n")
1918
print(f"Starting Stream:")
20-
api_stream = ubwa.create_stream(api=True, api_key=api_key, api_secret=api_secret,
19+
api_stream = ubwa.create_stream(api=True,
20+
api_key=os.getenv('BINANCE_API_KEY'),
21+
api_secret=os.getenv('BINANCE_API_SECRET'),
2122
stream_label="Bobs Spot Websocket API",
2223
process_asyncio_queue=handle_socket_message)
2324
print(f"Commands")
@@ -53,6 +54,7 @@ async def handle_socket_message(stream_id=None):
5354
filename=os.path.basename(__file__) + '.log',
5455
format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",
5556
style="{")
57+
load_dotenv()
5658

5759
# To use this library you need a valid UNICORN Binance Suite License:
5860
# https://shop.lucit.services

0 commit comments

Comments
 (0)