bitunix-automated-crypto-trading 3.2.8__tar.gz → 3.3.0__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 (25) hide show
  1. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/PKG-INFO +1 -1
  2. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/BitunixApi.py +16 -16
  3. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/BitunixSignal.py +53 -20
  4. bitunix_automated_crypto_trading-3.3.0/bitunix_automated_crypto_trading/version.py +1 -0
  5. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading.egg-info/PKG-INFO +1 -1
  6. bitunix_automated_crypto_trading-3.2.8/bitunix_automated_crypto_trading/version.py +0 -1
  7. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/README.md +0 -0
  8. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/AsyncThreadRunner.py +0 -0
  9. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/BitunixWebSocket.py +0 -0
  10. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/DataFrameHtmlRenderer.py +0 -0
  11. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/NotificationManager.py +0 -0
  12. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/SupportResistance.py +0 -0
  13. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/ThreadManager.py +0 -0
  14. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/TickerManager.py +0 -0
  15. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/__init__.py +0 -0
  16. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/bitunix.py +0 -0
  17. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/config.py +0 -0
  18. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading/logger.py +0 -0
  19. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading.egg-info/SOURCES.txt +0 -0
  20. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading.egg-info/dependency_links.txt +0 -0
  21. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading.egg-info/entry_points.txt +0 -0
  22. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading.egg-info/requires.txt +0 -0
  23. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/bitunix_automated_crypto_trading.egg-info/top_level.txt +0 -0
  24. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/setup.cfg +0 -0
  25. {bitunix_automated_crypto_trading-3.2.8 → bitunix_automated_crypto_trading-3.3.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bitunix_automated_crypto_trading
3
- Version: 3.2.8
3
+ Version: 3.3.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
@@ -120,9 +120,9 @@ class BitunixApi:
120
120
  response.raise_for_status()
121
121
  return response.json()
122
122
 
123
- async def PlaceOrder(self, ticker, qty, price, side, positionId=0, tradeSide="OPEN",reduceOnly=False, takeProfitPrice=0, stopLossPrice=0):
123
+ async def PlaceOrder(self, ticker, qty, price, side, positionId=0, tradeSide="OPEN",reduceOnly=False, tpPrice=0, tpOrderPrice=0, slPrice=0, slOrderPrice=0):
124
124
  datajs = None
125
- if takeProfitPrice == 0 or stopLossPrice == 0:
125
+ if tpPrice == 0 and slPrice == 0:
126
126
  data = {
127
127
  "side": side,
128
128
  "orderType":"LIMIT",
@@ -134,7 +134,7 @@ class BitunixApi:
134
134
  "positionId":positionId
135
135
  }
136
136
  datajs = await self._post_authenticated(self.placeOrder_Url,data)
137
- elif takeProfitPrice == 0:
137
+ elif tpPrice == 0:
138
138
  data = {
139
139
  "side": side,
140
140
  "orderType":"LIMIT",
@@ -142,14 +142,14 @@ class BitunixApi:
142
142
  "price": price,
143
143
  "symbol": ticker,
144
144
  "tradeSide":tradeSide,
145
- "slPrice": stopLossPrice,
146
- "slStopType":'MARK_PRICE',
145
+ "slPrice": slPrice,
147
146
  "slStopType": self.settings.PROFIT_LOSS_PRICE_TYPE,
148
- "slpOrderType": self.settings.PROFIT_LOSS_ORDER_TYPE,
147
+ "slOrderType": self.settings.PROFIT_LOSS_ORDER_TYPE,
148
+ "slOrderPrice": slOrderPrice,
149
149
  "positionId":positionId
150
150
  }
151
151
  datajs = await self._post_authenticated(self.placeOrder_Url,data)
152
- elif stopLossPrice == 0:
152
+ elif slPrice == 0:
153
153
  data = {
154
154
  "side": side,
155
155
  "orderType":"LIMIT",
@@ -157,10 +157,10 @@ class BitunixApi:
157
157
  "price": price,
158
158
  "symbol": ticker,
159
159
  "tradeSide":tradeSide,
160
- "tpPrice": takeProfitPrice,
160
+ "tpPrice": tpPrice,
161
161
  "tpStopType": self.settings.PROFIT_LOSS_PRICE_TYPE,
162
- "tppOrderType": self.settings.PROFIT_LOSS_ORDER_TYPE,
163
- "tpOrderPrice":takeProfitPrice,
162
+ "tpOrderType": self.settings.PROFIT_LOSS_ORDER_TYPE,
163
+ "tpOrderPrice":tpOrderPrice,
164
164
  "positionId":positionId
165
165
  }
166
166
  datajs = await self._post_authenticated(self.placeOrder_Url,data)
@@ -172,14 +172,14 @@ class BitunixApi:
172
172
  "price": price,
173
173
  "symbol": ticker,
174
174
  "tradeSide":tradeSide,
175
- "tpPrice": takeProfitPrice,
175
+ "tpPrice": tpPrice,
176
176
  "tpStopType": self.settings.PROFIT_LOSS_PRICE_TYPE,
177
- "tppOrderType": self.settings.PROFIT_LOSS_ORDER_TYPE,
178
- "tpOrderPrice":takeProfitPrice,
179
- "slPrice": stopLossPrice,
177
+ "tpOrderType": self.settings.PROFIT_LOSS_ORDER_TYPE,
178
+ "tpOrderPrice":tpOrderPrice,
179
+ "slPrice": slPrice,
180
180
  "slStopType": self.settings.PROFIT_LOSS_PRICE_TYPE,
181
- "slpOrderType": self.settings.PROFIT_LOSS_ORDER_TYPE,
182
- "slOrderPrice": stopLossPrice,
181
+ "slOrderType": self.settings.PROFIT_LOSS_ORDER_TYPE,
182
+ "slOrderPrice": slOrderPrice,
183
183
  "positionId":positionId
184
184
  }
185
185
  datajs = await self._post_authenticated(self.placeOrder_Url,data)
@@ -3,6 +3,8 @@ import pandas as pd
3
3
  import json
4
4
  import asyncio
5
5
  from datetime import datetime, timedelta, timezone
6
+ from decimal import Decimal
7
+
6
8
  from collections import defaultdict
7
9
  import traceback
8
10
  import time
@@ -664,7 +666,18 @@ class BitunixSignal:
664
666
 
665
667
  return round(duration_minutes)
666
668
 
667
-
669
+ async def str_precision(self,num):
670
+ num_decimal = Decimal(str(num)) # Convert to Decimal to preserve precision
671
+ decimal_places = abs(num_decimal.as_tuple().exponent) # Get original decimal places
672
+ return f"{num:.{decimal_places}f}" # Format with the original precision
673
+
674
+ async def increment_by_last_decimal(self, value_str):
675
+ value = Decimal(value_str)
676
+ # Count number of decimal places
677
+ decimal_places = abs(value.as_tuple().exponent)
678
+ increment = Decimal(f'1e-{decimal_places}')
679
+ return float(value + increment)
680
+
668
681
 
669
682
  async def calculate_candles(self, timeframe, duration_minutes):
670
683
 
@@ -703,13 +716,16 @@ class BitunixSignal:
703
716
  #open position upto a max of max_auto_trades from the signal list
704
717
  df=self.signaldf.copy(deep=False)
705
718
  for index, row in df.iterrows():
706
-
719
+ await asyncio.sleep(5)
720
+ data=None
707
721
  # Calculate the duration in minutes since the position was opened
708
722
  data = await self.bitunixApi.GetPositionHistoryData({'symbol': row['symbol']})
709
- xtime = float(data['positionList'][0]['mtime'])
710
- mtime = pd.to_datetime(xtime, unit='ms').tz_localize('UTC').tz_convert(cst).strftime('%Y-%m-%d %H:%M:%S')
711
- duration_minutes = await self.get_duration(mtime)
712
- if duration_minutes > self.settings.DELAY_IN_MINUTES_FOR_SAME_TICKER_TRADES:
723
+ duration_minutes = None
724
+ if data and 'positionList' in data and len(data['positionList']) > 0:
725
+ xtime = float(data['positionList'][0]['mtime'])
726
+ mtime = pd.to_datetime(xtime, unit='ms').tz_localize('UTC').tz_convert(cst).strftime('%Y-%m-%d %H:%M:%S')
727
+ duration_minutes = await self.get_duration(mtime)
728
+ if duration_minutes > self.settings.DELAY_IN_MINUTES_FOR_SAME_TICKER_TRADES or duration_minutes is None:
713
729
  side = "BUY" if row[f'{period}_barcolor'] == self.green and row[f'{period}_trend'] == "BUY" else "SELL" if row[f'{period}_barcolor'] == self.red and row[f'{period}_trend'] == "SELL" else ""
714
730
  if side != "":
715
731
  select = True
@@ -720,37 +736,54 @@ class BitunixSignal:
720
736
  if self.pendingOrders and len(self.pendingOrders['orderList']) == 1:
721
737
  select = False
722
738
  if select:
739
+ balance = float(self.portfoliodf["available"].iloc[0]) + float(self.portfoliodf["crossUnrealizedPNL"].iloc[0])
740
+
723
741
  last, bid, ask, mtv = await self.GetTickerBidLastAsk(row.symbol)
724
742
 
725
743
  price = (bid if side == "BUY" else ask if side == "SELL" else last) if bid<=last<=ask else last
744
+ qty= str(max(balance * (float(self.settings.ORDER_AMOUNT_PERCENTAGE) / 100 ) / price * int(self.settings.LEVERAGE),mtv))
726
745
 
727
- tp_price=0
746
+ decimal_places = abs(Decimal(str(price)).as_tuple().exponent)
747
+
748
+ tpPrice=0
749
+ tpOrderPrice=0
728
750
  if self.settings.PROFIT_AMOUNT > 0:
729
- tp_price = price * (1 + float(self.settings.PROFIT_AMOUNT)) if side == "BUY" else price * (1 - float(self.settings.PROFIT_AMOUNT))
751
+ tpPrice = (price * qty + float(self.settings.PROFIT_AMOUNT))/qty if side == "BUY" else (price * qty - float(self.settings.PROFIT_AMOUNT))/qty
752
+ tpPrice = Decimal(await self.str_precision(tpPrice))
753
+ tpPrice =float(str(tpPrice.quantize(Decimal(f'1e-{decimal_places}'))))
754
+ tpOrderPrice = await self.increment_by_last_decimal(str(tpPrice))
730
755
  if self.settings.PROFIT_PERCENTAGE > 0 or self.settings.PROFIT_AMOUNT > 0:
731
- tp_price = price * (1 + float(self.settings.PROFIT_PERCENTAGE) / 100 / self.settings.LEVERAGE) if side == "BUY" else price * (1 - float(self.settings.PROFIT_PERCENTAGE) / 100 / self.settings.LEVERAGE)
756
+ tpPrice = price * (1 + float(self.settings.PROFIT_PERCENTAGE) / 100 / self.settings.LEVERAGE) if side == "BUY" else price * (1 - float(self.settings.PROFIT_PERCENTAGE) / 100 / self.settings.LEVERAGE)
757
+ tpPrice = Decimal(await self.str_precision(tpPrice))
758
+ tpPrice = float(str(tpPrice.quantize(Decimal(f'1e-{decimal_places}'))))
759
+ tpOrderPrice = await self.increment_by_last_decimal(await self.str_precision(tpPrice))
732
760
 
733
- lp_price=0
761
+ slPrice=0
762
+ slOrderPrice=0
734
763
  if self.settings.LOSS_AMOUNT > 0:
735
- lp_price = price * (1 - float(self.settings.LOSS_AMOUNT)) if side == "BUY" else price * (1 + float(self.settings.LOSS_AMOUNT))
764
+ slPrice = (price * qty - float(self.settings.LOSS_AMOUNT))/qty if side == "BUY" else (price * qty + float(self.settings.LOSS_AMOUNT))/qty
765
+ slPrice = Decimal(await self.str_precision(slPrice))
766
+ slPrice = float(str(slPrice.quantize(Decimal(f'1e-{decimal_places}'))))
767
+ slOrderPrice = await self.increment_by_last_decimal(str(slPrice))
736
768
  if self.settings.LOSS_PERCENTAGE > 0 or self.settings.LOSS_AMOUNT > 0:
737
- lp_price = price * (1 - float(self.settings.LOSS_PERCENTAGE) / 100 / self.settings.LEVERAGE) if side == "BUY" else price * (1 + float(self.settings.LOSS_PERCENTAGE) / 100 / self.settings.LEVERAGE)
769
+ slPrice = price * (1 - float(self.settings.LOSS_PERCENTAGE) / 100 / self.settings.LEVERAGE) if side == "BUY" else price * (1 + float(self.settings.LOSS_PERCENTAGE) / 100 / self.settings.LEVERAGE)
770
+ slPrice = Decimal(await self.str_precision(slPrice))
771
+ slPrice = float(str(slPrice.quantize(Decimal(f'1e-{decimal_places}'))))
772
+ slOrderPrice = await self.increment_by_last_decimal(await self.str_precision(slPrice))
738
773
 
739
- balance = float(self.portfoliodf["available"].iloc[0]) + float(self.portfoliodf["crossUnrealizedPNL"].iloc[0])
740
- qty= str(max(balance * (float(self.settings.ORDER_AMOUNT_PERCENTAGE) / 100 ) / price * int(self.settings.LEVERAGE),mtv))
741
774
 
742
775
  self.notifications.add_notification(
743
776
  f'{colors.YELLOW} Opening {"long" if side=="BUY" else "short"} position for {row.symbol} with {qty} qty @ {price})'
744
777
  )
745
778
  datajs = None
746
- if tp_price == 0 and lp_price == 0:
779
+ if tpPrice == 0 and slPrice == 0:
747
780
  datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side)
748
- elif tp_price == 0:
749
- datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side, stopLossPrice=lp_price)
750
- elif lp_price == 0:
751
- datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side, takeProfitPrice=tp_price)
781
+ elif tpPrice == 0:
782
+ datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side, slPrice=slPrice, slOrderPrice=slOrderPrice)
783
+ elif slPrice == 0:
784
+ datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side, tpPrice=tpPrice, tpOrderPrice=tpOrderPrice)
752
785
  else:
753
- datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side, takeProfitPrice=tp_price, stopLossPrice=lp_price)
786
+ datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side, tpPrice=tpPrice, tpOrderPrice=tpOrderPrice, slPrice=slPrice, slOrderPrice=slOrderPrice)
754
787
  count=count+1
755
788
  else:
756
789
  self.logger.info(f"Skipping {row.symbol} as it has been opened for less than {self.settings.DELAY_IN_MINUTES_FOR_SAME_TICKER_TRADES} minutes")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bitunix_automated_crypto_trading
3
- Version: 3.2.8
3
+ Version: 3.3.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