bitunix-automated-crypto-trading 3.0.7__py3-none-any.whl → 3.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -259,27 +259,31 @@ class BitunixSignal:
259
259
  self.cursor.execute("INSERT INTO benchmark (process_name, time) VALUES (?, ?)", ("GetTickerData", time.time()-start))
260
260
  self.connection.commit()
261
261
 
262
-
262
+ async def drain_queue(self, queue):
263
+ items = []
264
+ while not queue.empty():
265
+ items.append(await queue.get())
266
+ return deque(items[::-1][:self.settings.BATCH_PROCESS_SIZE]) # Reverse items
267
+
263
268
  #websocket data to update ticker lastprice and other relavent data
264
269
  # Function to add data to the last price deque
265
270
  async def StoreTickerData(self, message):
266
- if self.settings.USE_PUBLIC_WEBSOCKET:
267
- if message=="":
268
- return
269
- data = json.loads(message)
270
- if 'symbol' in data and data['ch'] in ['ticker']:
271
- await self.ticker_que.put(data)
271
+ if self.settings.USE_PUBLIC_WEBSOCKET and message:
272
+ try:
273
+ data = json.loads(message)
274
+ if data.get('symbol') and data.get('ch') == 'ticker':
275
+ await self.ticker_que.put(data)
276
+ except json.JSONDecodeError as e:
277
+ logger.warning(f"Failed to decode message: {message}. Error: {e}")
272
278
 
273
279
  # Function to process the last price deque
274
280
  async def ProcessTickerData(self):
275
281
  while True:
276
282
  try:
277
- batch_size = self.settings.BATCH_PROCESS_SIZE
278
283
  latest_data = {}
279
- reversed_items = list(self.ticker_que._queue)[::-1]
280
- self.ticker_que._queue.clear()
281
- for i in range(min(batch_size, len(reversed_items))):
282
- data = reversed_items[i]
284
+ reversed_items = await self.drain_queue(self.ticker_que)
285
+ while reversed_items:
286
+ data = reversed_items.popleft()
283
287
  symbol = data["symbol"]
284
288
  ts = data["ts"]
285
289
  if symbol not in latest_data or ts > latest_data[symbol]['ts']:
@@ -298,23 +302,22 @@ class BitunixSignal:
298
302
 
299
303
  #websocket data to update bid and ask
300
304
  async def StoreDepthData(self, message):
301
- if self.settings.USE_PUBLIC_WEBSOCKET:
302
- if message=="":
303
- return
304
- data = json.loads(message)
305
- if 'symbol' in data and data['ch'] in ['depth_book1']:
306
- await self.depth_que.put(data)
305
+ if self.settings.USE_PUBLIC_WEBSOCKET and message:
306
+ try:
307
+ data = json.loads(message)
308
+ if data.get('symbol') and data.get('ch') == 'depth_book1':
309
+ await self.depth_que.put(data)
310
+ except json.JSONDecodeError as e:
311
+ logger.warning(f"Failed to decode message: {message}. Error: {e}")
307
312
 
308
313
  # Function to process the bid, ask
309
314
  async def ProcessDepthData(self):
310
315
  while True:
311
316
  try:
312
- batch_size = self.settings.BATCH_PROCESS_SIZE
313
317
  latest_data = {}
314
- reversed_items = list(self.depth_que._queue)[::-1]
315
- self.depth_que._queue.clear()
316
- for i in range(min(batch_size, len(reversed_items))):
317
- data = reversed_items[i]
318
+ reversed_items = await self.drain_queue(self.depth_que)
319
+ while reversed_items:
320
+ data = reversed_items.popleft()
318
321
  symbol = data["symbol"]
319
322
  ts = data["ts"]
320
323
  if symbol not in latest_data or ts > latest_data[symbol]['ts']:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bitunix_automated_crypto_trading
3
- Version: 3.0.7
3
+ Version: 3.0.9
4
4
  Summary: Bitunix Futures Auto Trading Platform
5
5
  Home-page: https://github.com/tcj2001/bitunix-automated-crypto-trading
6
6
  Author: tcj2001
@@ -1,6 +1,6 @@
1
1
  bitunix_automated_crypto_trading/AsyncThreadRunner.py,sha256=JDpAUiTZLB9KV4tGPonAvAUJyBqZz2-ehblH6vsunz8,3142
2
2
  bitunix_automated_crypto_trading/BitunixApi.py,sha256=wJhknpmVFrckoL89h-nlWUAMsPxhIacY0nOGJT9M6Vw,11360
3
- bitunix_automated_crypto_trading/BitunixSignal.py,sha256=fqmarMKcJi8qmXaF-O0EjN-ROTR5BBAbeGCmlkF-zgA,64164
3
+ bitunix_automated_crypto_trading/BitunixSignal.py,sha256=sArNBVXFZu4unBeTBhv3S1yNuZd-8PZtu10yGBGVkW8,64377
4
4
  bitunix_automated_crypto_trading/BitunixWebSocket.py,sha256=mbuvk8UFWKgv4KLV07TgLgxLVTRJnOKuf02mLB-VoCY,11143
5
5
  bitunix_automated_crypto_trading/DataFrameHtmlRenderer.py,sha256=Pqdzhh_nfIxFEZH9L_R5QXB8moDPbgeTGT_hmBkHWMg,2899
6
6
  bitunix_automated_crypto_trading/NotificationManager.py,sha256=pqDquEe-oujD2v8B543524vo62aRMjfB4YW-3DMhVGQ,795
@@ -10,8 +10,8 @@ bitunix_automated_crypto_trading/__init__.py,sha256=1hzk6nX8NnUCr1tsq8oFq1qGCNhN
10
10
  bitunix_automated_crypto_trading/bitunix.py,sha256=XLYaSSX0g2MMQ6TgR762qL1ppthKm2Ki6vMR77xSpdM,32248
11
11
  bitunix_automated_crypto_trading/config.py,sha256=QWAe5Ruq8A5anaFS-CamVm-3t1wMJjGG1DWaPIIWfiM,4521
12
12
  bitunix_automated_crypto_trading/logger.py,sha256=tAaTQcv5r--zupk_Fhfe1USfBAzSiXzVa4QRnaOFIFY,2933
13
- bitunix_automated_crypto_trading-3.0.7.dist-info/METADATA,sha256=6XzEoQONyYR3KuG5Q3r-8-td9F3AtWdQU0M0vWrUXTw,996
14
- bitunix_automated_crypto_trading-3.0.7.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
15
- bitunix_automated_crypto_trading-3.0.7.dist-info/entry_points.txt,sha256=UXREYHuSl2XYd_tOtLIq0zg3d1kX3lixX5SpN8yGBw4,82
16
- bitunix_automated_crypto_trading-3.0.7.dist-info/top_level.txt,sha256=uyFzHUCOsp8elnG2Ovor6xXcf7dxRxY-C-Txiwix64Q,33
17
- bitunix_automated_crypto_trading-3.0.7.dist-info/RECORD,,
13
+ bitunix_automated_crypto_trading-3.0.9.dist-info/METADATA,sha256=h3fxV9vRsIa5kna4waL0fpixwZ_PnpqTgOSTcyjB2U4,996
14
+ bitunix_automated_crypto_trading-3.0.9.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
15
+ bitunix_automated_crypto_trading-3.0.9.dist-info/entry_points.txt,sha256=UXREYHuSl2XYd_tOtLIq0zg3d1kX3lixX5SpN8yGBw4,82
16
+ bitunix_automated_crypto_trading-3.0.9.dist-info/top_level.txt,sha256=uyFzHUCOsp8elnG2Ovor6xXcf7dxRxY-C-Txiwix64Q,33
17
+ bitunix_automated_crypto_trading-3.0.9.dist-info/RECORD,,