bitunix-automated-crypto-trading 3.0.2__tar.gz → 3.0.5__tar.gz

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.
Files changed (22) hide show
  1. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/PKG-INFO +1 -1
  2. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading/BitunixSignal.py +24 -82
  3. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading.egg-info/PKG-INFO +1 -1
  4. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/setup.py +1 -1
  5. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/README.md +0 -0
  6. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading/AsyncThreadRunner.py +0 -0
  7. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading/BitunixApi.py +0 -0
  8. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading/BitunixWebSocket.py +0 -0
  9. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading/DataFrameHtmlRenderer.py +0 -0
  10. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading/NotificationManager.py +0 -0
  11. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading/ThreadManager.py +0 -0
  12. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading/TickerManager.py +0 -0
  13. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading/__init__.py +0 -0
  14. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading/bitunix.py +0 -0
  15. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading/config.py +0 -0
  16. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading/logger.py +0 -0
  17. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading.egg-info/SOURCES.txt +0 -0
  18. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading.egg-info/dependency_links.txt +0 -0
  19. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading.egg-info/entry_points.txt +0 -0
  20. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading.egg-info/requires.txt +0 -0
  21. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/bitunix_automated_crypto_trading.egg-info/top_level.txt +0 -0
  22. {bitunix_automated_crypto_trading-3.0.2 → bitunix_automated_crypto_trading-3.0.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bitunix_automated_crypto_trading
3
- Version: 3.0.2
3
+ Version: 3.0.5
4
4
  Summary: Bitunix Futures Auto Trading Platform
5
5
  Home-page: https://github.com/tcj2001/bitunix-automated-crypto-trading
6
6
  Author: tcj2001
@@ -17,6 +17,7 @@ logger = Logger(__name__).get_logger()
17
17
  colors = Colors()
18
18
  import gc
19
19
  from concurrent.futures import ProcessPoolExecutor
20
+ import sqlite3
20
21
 
21
22
  cst = pytz.timezone('US/Central')
22
23
 
@@ -84,6 +85,11 @@ class BitunixSignal:
84
85
  self.lastAutoTradeTime = time.time()
85
86
  self.lastTickerDataTime = time.time()
86
87
 
88
+ #sqllite database connection
89
+ self.connection = sqlite3.connect("bitunix.db")
90
+ self.cursor = self.connection.cursor()
91
+ self.cursor.execute("CREATE TABLE IF NOT EXISTS benchmark (id INTEGER PRIMARY KEY, process_name TEXT, time INTEGER)")
92
+
87
93
  async def update_settings(self, settings):
88
94
  self.settings = settings
89
95
  self.tickerObjects.update_settings(settings)
@@ -129,38 +135,6 @@ class BitunixSignal:
129
135
  self.GetPositionHistoryDataTask = AsyncThreadRunner(self.GetPositionHistoryData, interval=int(self.settings.POSITION_HISTORY_API_INTERVAL))
130
136
  self.GetPositionHistoryDataTask.start_thread(thread_name="GetPositionHistoryData")
131
137
 
132
- #run restartable asynch thread
133
- await self.restartable_jobs()
134
-
135
- async def restart_jobs(self):
136
-
137
- #stop websocket async thread jobs
138
- await self.bitunixPrivateWebSocketClient.stop_websocket()
139
- await self.ProcessPrivateDataTask.stop_thread()
140
-
141
- if self.settings.USE_PUBLIC_WEBSOCKET:
142
- await self.bitunixPublicDepthWebSocketClient.stop_websocket()
143
- await self.UpdateDepthDataTask.stop_thread()
144
-
145
- await self.bitunixPublicTickerWebSocketClient.stop_websocket()
146
- await self.UpdateTickerDataTask.stop_thread()
147
-
148
- #kill the loop to restart public websocket
149
- #not using for now
150
- #await self.restartPublicWebsocketTask.stop_thread()
151
-
152
- #stop onetime / periodic async thread jobs
153
- await self.LoadKlineHistoryTask.stop_thread()
154
- await self.GetTickerDataTask.stop_thread()
155
- await self.AutoTradeProcessTask.stop_thread()
156
-
157
- #start jobs
158
- await self.load_tickers()
159
- await self.restartable_jobs()
160
-
161
- async def restartable_jobs(self):
162
- #start cancelable async jobs
163
- #websocket jobs
164
138
  self.ProcessPrivateDataTask = AsyncThreadRunner(self.bitunixPrivateWebSocketClient.run_websocket, 0, self.ProcessPrivateData)
165
139
  self.ProcessPrivateDataTask.start_thread(thread_name="ProcessPrivateData")
166
140
 
@@ -184,39 +158,6 @@ class BitunixSignal:
184
158
  self.AutoTradeProcessTask = AsyncThreadRunner(self.AutoTradeProcess, interval=int(self.settings.SIGNAL_CHECK_INTERVAL))
185
159
  self.AutoTradeProcessTask.start_thread(thread_name="AutoTradeProcess")
186
160
 
187
- #start the loop to restart public websocket
188
- #if self.settings.USE_PUBLIC_WEBSOCKET:
189
- # self.restartPublicWebsocketTask = AsyncThreadRunner(self.restartPublicWebsocket, interval=0)
190
- # self.restartPublicWebsocketTask.start_thread(thread_name="restartPublicWebsocket")
191
-
192
- #this is a normal task runing in a async thread, that can be cancelled
193
- # this runs in a async thread to stop and start the public websocket, as we found some lagging when it runs continously
194
- #not used now
195
- async def restartPublicWebsocket(self):
196
- while True:
197
- await asyncio.sleep(int(self.settings.PUBLIC_WEBSOCKET_RESTART_INTERVAL))
198
-
199
- if self.settings.VERBOSE_LOGGING:
200
- self.notifications.add_notification('Restarting public websocket')
201
- logger.info(f"Restarting public websocket")
202
-
203
- if self.settings.USE_PUBLIC_WEBSOCKET:
204
- await self.UpdateDepthDataTask.stop_thread()
205
- await self.UpdateTickerDataTask.stop_thread()
206
-
207
- await asyncio.sleep(30)
208
-
209
- if self.settings.USE_PUBLIC_WEBSOCKET:
210
- self.bitunixPublicDepthWebSocketClient.tickerList = self.tickerList
211
- self.UpdateDepthDataTask = AsyncThreadRunner(self.bitunixPublicDepthWebSocketClient.run_websocket, 0, self.UpdateDepthData)
212
- self.UpdateDepthDataTask.start_thread(thread_name="UpdateDepthData")
213
-
214
- self.bitunixPublicTickerWebSocketClient.tickerList = self.tickerList
215
- self.UpdateTickerDataTask = AsyncThreadRunner(self.bitunixPublicTickerWebSocketClient.run_websocket, 0, self.UpdateTickerData)
216
- self.UpdateTickerDataTask.start_thread(thread_name="UpdateTickerData")
217
-
218
- if self.settings.VERBOSE_LOGGING:
219
- self.notifications.add_notification('Restared public websocket')
220
161
 
221
162
  ###########################################################################################################
222
163
  async def DefinehtmlRenderers(self):
@@ -300,7 +241,7 @@ class BitunixSignal:
300
241
  logger.info(f"GetTickerData: elapsed time {time.time()-start}")
301
242
 
302
243
 
303
- #websocket data
244
+ #websocket data to update ticker lastprice and other relavent data
304
245
  async def UpdateTickerData(self, message):
305
246
  if message=="":
306
247
  return
@@ -327,7 +268,7 @@ class BitunixSignal:
327
268
  if self.settings.VERBOSE_LOGGING:
328
269
  logger.info(f"Function: UpdateTickerData, time:{ts}, symbol:{symbol}, highest:{highest}, lowest:{lowest}, volume:{volume}, volumeInCurrency:{volumeInCurrency}")
329
270
 
330
- #websocket data
271
+ #websocket data to update bid and ask
331
272
  async def UpdateDepthData(self, message):
332
273
  if message=="":
333
274
  return
@@ -457,14 +398,14 @@ class BitunixSignal:
457
398
  #if not self.settings.USE_PUBLIC_WEBSOCKET:
458
399
  #get bid las ask using api for the symbols in pending psotion
459
400
  if not self.positiondf.empty:
460
- if self.settings.USE_PUBLIC_WEBSOCKET:
401
+ if not self.settings.USE_PUBLIC_WEBSOCKET:
461
402
  await asyncio.create_task(self.apply_last_data(','.join(self.positiondf['symbol'].astype(str).tolist())))
462
- await asyncio.gather(
463
- *[
464
- asyncio.create_task(self.apply_depth_data(row['symbol']))
465
- for index, row in self.positiondf.iterrows()
466
- ]
467
- )
403
+ await asyncio.gather(
404
+ *[
405
+ asyncio.create_task(self.apply_depth_data(row['symbol']))
406
+ for index, row in self.positiondf.iterrows()
407
+ ]
408
+ )
468
409
 
469
410
 
470
411
  except Exception as e:
@@ -496,8 +437,9 @@ class BitunixSignal:
496
437
  try:
497
438
  self.positionHistoryData = await self.bitunixApi.GetPositionHistoryData()
498
439
  if self.positionHistoryData and 'positionList' in self.positionHistoryData:
499
- self.positionHistorydf = pd.DataFrame(self.positionHistoryData['positionList'], columns=["symbol", "side","realizedPNL", "ctime", "maxQty", "closePrice","fee", "funding"])
440
+ self.positionHistorydf = pd.DataFrame(self.positionHistoryData['positionList'], columns=["symbol", "side","realizedPNL", "ctime", "mtime","maxQty", "closePrice","fee", "funding"])
500
441
  self.positionHistorydf['ctime'] = pd.to_datetime(self.positionHistorydf['ctime'].astype(float), unit='ms').dt.tz_localize('UTC').dt.tz_convert(cst).dt.strftime('%Y-%m-%d %H:%M:%S')
442
+ self.positionHistorydf['mtime'] = pd.to_datetime(self.positionHistorydf['mtime'].astype(float), unit='ms').dt.tz_localize('UTC').dt.tz_convert(cst).dt.strftime('%Y-%m-%d %H:%M:%S')
501
443
  self.positionHistorydf['charts'] = self.positionHistorydf.apply(self.add_charts_button, axis=1)
502
444
  self.positionHistorydf['bitunix'] = self.positionHistorydf.apply(self.add_bitunix_button, axis=1)
503
445
 
@@ -597,14 +539,14 @@ class BitunixSignal:
597
539
  #get bid las ask using api for max_auto_trades rows
598
540
  if not self.signaldf.empty:
599
541
  m = min(self.signaldf.shape[0], int(self.settings.MAX_AUTO_TRADES))
600
- if self.settings.USE_PUBLIC_WEBSOCKET:
542
+ if not self.settings.USE_PUBLIC_WEBSOCKET:
601
543
  await asyncio.create_task(self.apply_last_data(','.join(self.signaldf['symbol'][:m].astype(str).tolist())))
602
- await asyncio.gather(
603
- *[
604
- asyncio.create_task(self.apply_depth_data(row['symbol']))
605
- for index, row in self.signaldf[:m].iterrows()
606
- ]
607
- )
544
+ await asyncio.gather(
545
+ *[
546
+ asyncio.create_task(self.apply_depth_data(row['symbol']))
547
+ for index, row in self.signaldf[:m].iterrows()
548
+ ]
549
+ )
608
550
 
609
551
  except Exception as e:
610
552
  logger.info(f"Function: BuySellList, {e}, {e.args}, {type(e).__name__}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bitunix_automated_crypto_trading
3
- Version: 3.0.2
3
+ Version: 3.0.5
4
4
  Summary: Bitunix Futures Auto Trading Platform
5
5
  Home-page: https://github.com/tcj2001/bitunix-automated-crypto-trading
6
6
  Author: tcj2001
@@ -66,7 +66,7 @@ class CustomInstall(install):
66
66
 
67
67
  setup(
68
68
  name="bitunix_automated_crypto_trading",
69
- version="3.0.2",
69
+ version="3.0.5",
70
70
  license="MIT",
71
71
  author="tcj2001",
72
72
  author_email="thomsonmathews@hotmail.com",