Skip to content

Commit 8072cb9

Browse files
Resolve "163 uniform the msg parameter" (#164)
1 parent 534e83d commit 8072cb9

7 files changed

Lines changed: 41 additions & 40 deletions

File tree

examples/futures_trading_bot_template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def __init__(self: TradingBot, config: dict) -> None:
6464
self.__market: Market = Market(key=config["key"], secret=config["secret"])
6565
self.__funding: Funding = Funding(key=config["key"], secret=config["secret"])
6666

67-
async def on_message(self: TradingBot, msg: Union[list, dict]) -> None:
67+
async def on_message(self: TradingBot, message: Union[list, dict]) -> None:
6868
"""Receives all messages that came form the websocket feed(s)"""
69-
logging.info(msg)
69+
logging.info(message)
7070

7171
# == apply your trading strategy here ==
7272

examples/futures_ws_examples.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ async def main() -> None:
3939
class Client(KrakenFuturesWSClient):
4040
"""Can be used to create a custom trading strategy"""
4141

42-
async def on_message(self: "Client", msg: Union[list, dict]) -> None:
42+
async def on_message(self: Client, message: Union[list, dict]) -> None:
4343
"""Receives the websocket messages"""
44-
logging.info(msg)
44+
logging.info(message)
4545
# … apply your trading strategy here
4646
# … you can also combine this with the Futures REST clients
4747

@@ -106,8 +106,8 @@ async def on_message(self: "Client", msg: Union[list, dict]) -> None:
106106
# from kraken.futures import KrakenFuturesWSClient
107107
# import asyncio
108108

109-
# async def on_message(msg):
110-
# print(msg)
109+
# async def on_message(message):
110+
# print(message)
111111

112112
# async def main() -> None:
113113
# async with KrakenFuturesWSClient(callback=on_message) as session:

examples/spot_ws_examples_v1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ async def on_message(self: Client, message: Union[list, dict]) -> None:
110110
# from kraken.spot import KrakenSpotWSClientV1
111111
# import asyncio
112112

113-
# async def on_message(msg):
114-
# print(msg)
113+
# async def on_message(message):
114+
# print(message)
115115

116116
# async def main() -> None:
117117
# async with KrakenSpotWSClientV1(callback=on_message) as session:

kraken/futures/websocket/__init__.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def __run(self: ConnectFuturesWebsocket, event: asyncio.Event) -> None:
8686

8787
while keep_alive:
8888
try:
89-
_msg = await asyncio.wait_for(self.__socket.recv(), timeout=15)
89+
_message = await asyncio.wait_for(self.__socket.recv(), timeout=15)
9090
except asyncio.TimeoutError:
9191
logging.debug( # important
9292
"Timeout error in %s",
@@ -98,9 +98,9 @@ async def __run(self: ConnectFuturesWebsocket, event: asyncio.Event) -> None:
9898
await self.__callback({"error": "asyncio.CancelledError"})
9999
else:
100100
try:
101-
message: dict = json.loads(_msg)
101+
message: dict = json.loads(_message)
102102
except ValueError:
103-
logging.warning(_msg)
103+
logging.warning(_message)
104104
else:
105105
forward: bool = True
106106
if "event" in message:
@@ -200,15 +200,15 @@ async def __recover_subscription_req_msg(
200200

201201
async def send_message(
202202
self: ConnectFuturesWebsocket,
203-
msg: dict,
203+
message: dict,
204204
*,
205205
private: bool = False,
206206
) -> None:
207207
"""
208208
Enables sending a message via the websocket connection
209209
210-
:param msg: The message as dictionary
211-
:type msg: dict
210+
:param message: The message as dictionary
211+
:type message: dict
212212
:param private: If the message requires authentication (default: ``False``)
213213
:type private: bool, optional
214214
:rtype: Coroutine
@@ -224,14 +224,14 @@ async def send_message(
224224
if not self.__challenge_ready:
225225
await self.__check_challenge_ready()
226226

227-
msg["api_key"] = self.__client.key
228-
msg["original_challenge"] = self.__last_challenge
229-
msg["signed_challenge"] = self.__new_challenge
227+
message["api_key"] = self.__client.key
228+
message["original_challenge"] = self.__last_challenge
229+
message["signed_challenge"] = self.__new_challenge
230230

231-
await self.__socket.send(json.dumps(msg))
231+
await self.__socket.send(json.dumps(message))
232232

233-
def __handle_new_challenge(self: ConnectFuturesWebsocket, msg: dict) -> None:
234-
self.__last_challenge = msg["message"]
233+
def __handle_new_challenge(self: ConnectFuturesWebsocket, message: dict) -> None:
234+
self.__last_challenge = message["message"]
235235
self.__new_challenge = self.__client.get_sign_challenge(self.__last_challenge)
236236
self.__challenge_ready = True
237237

@@ -249,13 +249,15 @@ def __get_reconnect_wait(self, attempts: int) -> float:
249249
random() * min(60 * 3, (2**attempts) - 1) + 1, # noqa: S311
250250
)
251251

252-
def __append_subscription(self: ConnectFuturesWebsocket, msg: dict) -> None:
253-
self.__remove_subscription(msg=msg) # remove from list, to avoid duplicates
254-
sub: dict = self.__build_subscription(msg)
252+
def __append_subscription(self: ConnectFuturesWebsocket, message: dict) -> None:
253+
self.__remove_subscription(
254+
message=message,
255+
) # remove from list, to avoid duplicates
256+
sub: dict = self.__build_subscription(message)
255257
self.__subscriptions.append(sub)
256258

257-
def __remove_subscription(self: ConnectFuturesWebsocket, msg: dict) -> None:
258-
sub: dict = self.__build_subscription(msg)
259+
def __remove_subscription(self: ConnectFuturesWebsocket, message: dict) -> None:
260+
sub: dict = self.__build_subscription(message)
259261
self.__subscriptions = [x for x in self.__subscriptions if x != sub]
260262

261263
def __build_subscription(

kraken/futures/ws_client.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ async def on_message(self, event: dict) -> None:
8686
import asyncio
8787
from kraken.futures import KrakenFuturesWSClient
8888
89-
async def on_message(msg):
90-
print(msg)
89+
async def on_messageessage):
90+
print(message)
9191
9292
async def main() -> None:
9393
async with KrakenFuturesWSClient(callback=on_message) as session:
@@ -164,24 +164,23 @@ def get_sign_challenge(self: KrakenFuturesWSClient, challenge: str) -> str:
164164
).digest(),
165165
).decode("utf-8")
166166

167-
async def on_message(self: KrakenFuturesWSClient, msg: dict) -> None:
167+
async def on_message(self: KrakenFuturesWSClient, message: dict) -> None:
168168
"""
169169
Method that serves as the default callback function Calls the defined callback function (if defined)
170170
or overload this function.
171171
172172
This is the default method which just logs the messages. In production you want to overload this
173173
with your custom methods, as shown in the Example of :class:`kraken.futures.KrakenFuturesWSClient`.
174174
175-
:param msg: The message that was send by Kraken via the websocket connection.
176-
:type msg: dict
177-
:rtype: NOne
175+
:param message: The message that was send by Kraken via the websocket connection.
176+
:type message: dict
177+
:rtype: None
178178
"""
179-
# todo: rename the msg parameter to message
180179
if self.__callback is not None:
181-
await self.__callback(msg)
180+
await self.__callback(message)
182181
else:
183182
logging.warning("Received event but no callback is defined")
184-
logging.info(msg)
183+
logging.info(message)
185184

186185
async def subscribe(
187186
self: KrakenFuturesWSClient,

kraken/spot/websocket/connectors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ async def __run(self: ConnectSpotWebsocketBase, event: asyncio.Event) -> None:
130130
if time() - self._last_ping > self.PING_INTERVAL:
131131
await self.send_ping()
132132
try:
133-
_msg = await asyncio.wait_for(self.socket.recv(), timeout=15)
133+
_message = await asyncio.wait_for(self.socket.recv(), timeout=15)
134134
except asyncio.TimeoutError: # important
135135
await self.send_ping()
136136
except asyncio.CancelledError:
@@ -139,9 +139,9 @@ async def __run(self: ConnectSpotWebsocketBase, event: asyncio.Event) -> None:
139139
await self.__callback({"error": "asyncio.CancelledError"})
140140
else:
141141
try:
142-
message: dict = json.loads(_msg)
142+
message: dict = json.loads(_message)
143143
except ValueError:
144-
self.LOG.warning(_msg)
144+
self.LOG.warning(_message)
145145
else:
146146
self.LOG.debug(message)
147147
self._manage_subscriptions(message=message)

tests/futures/helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def __init__(
5555

5656
async def on_message(
5757
self: "FuturesWebsocketClientTestWrapper",
58-
msg: Union[list, dict],
58+
message: Union[list, dict],
5959
) -> None:
6060
"""
6161
This is the callback function that must be implemented
6262
to handle custom websocket messages.
6363
"""
64-
self.LOG.info(msg) # the log is read within the tests
64+
self.LOG.info(message) # the log is read within the tests
6565

6666
log: str = ""
6767
try:
@@ -71,4 +71,4 @@ async def on_message(
7171
pass
7272

7373
with open("futures_ws.log", "w", encoding="utf-8") as logfile:
74-
logfile.write(f"{log}\n{msg}")
74+
logfile.write(f"{log}\n{message}")

0 commit comments

Comments
 (0)