bitunix-automated-crypto-trading 3.0.7__py3-none-any.whl → 3.1.0__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.
@@ -28,7 +28,8 @@ class AsyncThreadRunner:
28
28
  )
29
29
  self.loop.run_forever()
30
30
  except Exception as e:
31
- logger.info(f"Async Thread function error: {e}")
31
+ logger.info(f"Async Thread function error: {e}, exiting app")
32
+ os._exit(1) # Exit the program if the thread is stopped
32
33
  finally:
33
34
  pending = asyncio.all_tasks(self.loop)
34
35
  for task in pending:
@@ -165,12 +165,13 @@ class BitunixSignal:
165
165
  self.AutoTradeProcessTask = AsyncThreadRunner(self.AutoTradeProcess, interval=int(self.settings.SIGNAL_CHECK_INTERVAL))
166
166
  self.AutoTradeProcessTask.start_thread(thread_name="AutoTradeProcess")
167
167
 
168
+ self.checkTickerAndAutotradeStatusTask = AsyncThreadRunner(self.checkTickerAndAutotradeStatus, interval=0)
169
+ self.checkTickerAndAutotradeStatusTask.start_thread(thread_name="checkTickerAndAutotradeStatus")
170
+
168
171
  if not self.settings.USE_PUBLIC_WEBSOCKET:
169
172
  self.GetTickerDataTask = AsyncThreadRunner(self.GetTickerData, interval=int(self.settings.TICKER_DATA_API_INTERVAL))
170
173
  self.GetTickerDataTask.start_thread(thread_name="GetTickerData")
171
174
 
172
- self.checkPeriodicProcessTask = AsyncThreadRunner(self.checkPeriodicProcess, interval=0)
173
- self.checkPeriodicProcessTask.start_thread(thread_name="checkPeriodicProcess")
174
175
 
175
176
 
176
177
  ###########################################################################################################
@@ -259,27 +260,31 @@ class BitunixSignal:
259
260
  self.cursor.execute("INSERT INTO benchmark (process_name, time) VALUES (?, ?)", ("GetTickerData", time.time()-start))
260
261
  self.connection.commit()
261
262
 
262
-
263
+ async def drain_queue(self, queue):
264
+ items = []
265
+ while not queue.empty():
266
+ items.append(await queue.get())
267
+ return deque(items[::-1][:self.settings.BATCH_PROCESS_SIZE]) # Reverse items
268
+
263
269
  #websocket data to update ticker lastprice and other relavent data
264
270
  # Function to add data to the last price deque
265
271
  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)
272
+ if self.settings.USE_PUBLIC_WEBSOCKET and message:
273
+ try:
274
+ data = json.loads(message)
275
+ if data.get('symbol') and data.get('ch') == 'ticker':
276
+ await self.ticker_que.put(data)
277
+ except json.JSONDecodeError as e:
278
+ logger.warning(f"Failed to decode message: {message}. Error: {e}")
272
279
 
273
280
  # Function to process the last price deque
274
281
  async def ProcessTickerData(self):
275
282
  while True:
276
283
  try:
277
- batch_size = self.settings.BATCH_PROCESS_SIZE
278
284
  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]
285
+ reversed_items = await self.drain_queue(self.ticker_que)
286
+ while reversed_items:
287
+ data = reversed_items.popleft()
283
288
  symbol = data["symbol"]
284
289
  ts = data["ts"]
285
290
  if symbol not in latest_data or ts > latest_data[symbol]['ts']:
@@ -295,26 +300,28 @@ class BitunixSignal:
295
300
  logger.info(f"Function: ProcessTickerData, {e}, {e.args}, {type(e).__name__}")
296
301
  logger.info(traceback.print_exc())
297
302
  await asyncio.sleep(0.5)
303
+ logger.info(f"ProcessTickerData: exitied out of the loop, exiting app")
304
+ os._exit(1) # Exit the program
305
+
298
306
 
299
307
  #websocket data to update bid and ask
300
308
  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)
309
+ if self.settings.USE_PUBLIC_WEBSOCKET and message:
310
+ try:
311
+ data = json.loads(message)
312
+ if data.get('symbol') and data.get('ch') == 'depth_book1':
313
+ await self.depth_que.put(data)
314
+ except json.JSONDecodeError as e:
315
+ logger.warning(f"Failed to decode message: {message}. Error: {e}")
307
316
 
308
317
  # Function to process the bid, ask
309
318
  async def ProcessDepthData(self):
310
319
  while True:
311
320
  try:
312
- batch_size = self.settings.BATCH_PROCESS_SIZE
313
321
  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]
322
+ reversed_items = await self.drain_queue(self.depth_que)
323
+ while reversed_items:
324
+ data = reversed_items.popleft()
318
325
  symbol = data["symbol"]
319
326
  ts = data["ts"]
320
327
  if symbol not in latest_data or ts > latest_data[symbol]['ts']:
@@ -328,6 +335,8 @@ class BitunixSignal:
328
335
  logger.info(f"Function: ProcessTickerData, {e}, {e.args}, {type(e).__name__}")
329
336
  logger.info(traceback.print_exc())
330
337
  await asyncio.sleep(0.5)
338
+ logger.info(f"ProcessDepthData: exitied out of the loop, exiting app")
339
+ os._exit(1) # Exit the program
331
340
 
332
341
  def apply_depth_data2(self, row):
333
342
  row["tickerObj"].set_ask(row["ask"])
@@ -382,7 +391,7 @@ class BitunixSignal:
382
391
  gc.collect()
383
392
 
384
393
  ###########################################################################################################
385
- async def checkPeriodicProcess(self):
394
+ async def checkTickerAndAutotradeStatus(self):
386
395
  while True:
387
396
  if self.lastAutoTradeTime + 300 < time.time() or self.lastTickerDataTime + 300 < time.time():
388
397
  self.notifications.add_notification("AutoTradeProcess or GetTickerData is not running")
@@ -525,16 +525,26 @@ async def wschart(websocket):
525
525
 
526
526
  queue = asyncio.Queue()
527
527
  queueTask = asyncio.create_task(send_data_queue(websocket, queue))
528
-
528
+ period=settings.OPTION_MOVING_AVERAGE
529
529
  while True:
530
530
  stime=time.time()
531
531
  try:
532
532
 
533
+ # Receive period changed data from the WebSocket
534
+ try:
535
+ message = await asyncio.wait_for(websocket.receive_text(), timeout=0.01)
536
+ if message!="ping" and message!="":
537
+ # Decode the new period from the incoming message
538
+ data = json.loads(message)
539
+ if "period" in data:
540
+ period = data["period"]
541
+ except asyncio.TimeoutError:
542
+ pass
543
+
533
544
  # Handle incoming ping messages
534
545
  await asyncio.create_task(send_pong(websocket,queue))
535
546
 
536
547
  if ticker in bitunix.bitunixSignal.tickerObjects.symbols():
537
- period=settings.OPTION_MOVING_AVERAGE
538
548
  bars=settings.BARS
539
549
  chart=list(bitunix.bitunixSignal.tickerObjects.get(ticker).get_interval_ticks(period).get_data()[-bars:])
540
550
  buysell=list(bitunix.bitunixSignal.tickerObjects.get(ticker).trades)
@@ -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.1.0
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,17 +1,17 @@
1
- bitunix_automated_crypto_trading/AsyncThreadRunner.py,sha256=JDpAUiTZLB9KV4tGPonAvAUJyBqZz2-ehblH6vsunz8,3142
1
+ bitunix_automated_crypto_trading/AsyncThreadRunner.py,sha256=LJ6ny1KSCVoIbfeNypsY4aHYcbkGME9M3epQ9e8B1O8,3224
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=LKxWy_-alKkawB_l9_AdzwtCt0rx6lTqfBDuiGBMoe4,64669
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
7
7
  bitunix_automated_crypto_trading/ThreadManager.py,sha256=WmYRQu8aNrgp5HwSqpBqX1WESNSEpbD2CznPFpd9HuI,2330
8
8
  bitunix_automated_crypto_trading/TickerManager.py,sha256=eeOK5paiae10XHjKMbucJnVAZkAsEC86N37bRPuCcFc,33427
9
9
  bitunix_automated_crypto_trading/__init__.py,sha256=1hzk6nX8NnUCr1tsq8oFq1qGCNhNwnwldWE75641Eew,78
10
- bitunix_automated_crypto_trading/bitunix.py,sha256=XLYaSSX0g2MMQ6TgR762qL1ppthKm2Ki6vMR77xSpdM,32248
10
+ bitunix_automated_crypto_trading/bitunix.py,sha256=c5vKRuN1-UaNz_ZB5Txu4-2UM6PsnRhs-ztvhRtpEzc,32779
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.1.0.dist-info/METADATA,sha256=XCBZ2j36c5DL7EKdjcUkS7dzCLMcq9c1TW9Ru5wt9pY,996
14
+ bitunix_automated_crypto_trading-3.1.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
15
+ bitunix_automated_crypto_trading-3.1.0.dist-info/entry_points.txt,sha256=UXREYHuSl2XYd_tOtLIq0zg3d1kX3lixX5SpN8yGBw4,82
16
+ bitunix_automated_crypto_trading-3.1.0.dist-info/top_level.txt,sha256=uyFzHUCOsp8elnG2Ovor6xXcf7dxRxY-C-Txiwix64Q,33
17
+ bitunix_automated_crypto_trading-3.1.0.dist-info/RECORD,,