bitunix-automated-crypto-trading 3.3.1__py3-none-any.whl → 3.3.2__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.
@@ -143,8 +143,8 @@ class BitunixApi:
143
143
  "symbol": ticker,
144
144
  "tradeSide":tradeSide,
145
145
  "slPrice": slPrice,
146
- "slStopType": self.settings.PROFIT_LOSS_PRICE_TYPE,
147
- "slOrderType": self.settings.PROFIT_LOSS_ORDER_TYPE,
146
+ "slStopType": self.settings.STOP_LOSS_PRICE_TYPE,
147
+ "slOrderType": self.settings.STOP_LOSS_ORDER_TYPE,
148
148
  "slOrderPrice": slOrderPrice,
149
149
  "positionId":positionId
150
150
  }
@@ -158,8 +158,8 @@ class BitunixApi:
158
158
  "symbol": ticker,
159
159
  "tradeSide":tradeSide,
160
160
  "tpPrice": tpPrice,
161
- "tpStopType": self.settings.PROFIT_LOSS_PRICE_TYPE,
162
- "tpOrderType": self.settings.PROFIT_LOSS_ORDER_TYPE,
161
+ "tpStopType": self.settings.TAKE_PROFIT_PRICE_TYPE,
162
+ "tpOrderType": self.settings.TAKE_PROFIT_ORDER_TYPE,
163
163
  "tpOrderPrice":tpOrderPrice,
164
164
  "positionId":positionId
165
165
  }
@@ -173,12 +173,12 @@ class BitunixApi:
173
173
  "symbol": ticker,
174
174
  "tradeSide":tradeSide,
175
175
  "tpPrice": tpPrice,
176
- "tpStopType": self.settings.PROFIT_LOSS_PRICE_TYPE,
177
- "tpOrderType": self.settings.PROFIT_LOSS_ORDER_TYPE,
176
+ "tpStopType": self.settings.TAKE_PROFIT_PRICE_TYPE,
177
+ "tpOrderType": self.settings.TAKE_PROFIT_ORDER_TYPE,
178
178
  "tpOrderPrice":tpOrderPrice,
179
179
  "slPrice": slPrice,
180
- "slStopType": self.settings.PROFIT_LOSS_PRICE_TYPE,
181
- "slOrderType": self.settings.PROFIT_LOSS_ORDER_TYPE,
180
+ "slStopType": self.settings.STOP_LOSS_PRICE_TYPE,
181
+ "slOrderType": self.settings.STOP_LOSS_ORDER_TYPE,
182
182
  "slOrderPrice": slOrderPrice,
183
183
  "positionId":positionId
184
184
  }
@@ -716,7 +716,7 @@ class BitunixSignal:
716
716
  #open position upto a max of max_auto_trades from the signal list
717
717
  df=self.signaldf.copy(deep=False)
718
718
  for index, row in df.iterrows():
719
- await asyncio.sleep(5)
719
+ await asyncio.sleep(0.1) # Allow other tasks to run
720
720
  data=None
721
721
  # Calculate the duration in minutes since the position was opened
722
722
  data = await self.bitunixApi.GetPositionHistoryData({'symbol': row['symbol']})
@@ -749,7 +749,7 @@ class BitunixSignal:
749
749
  tpPrice=0
750
750
  tpOrderPrice=0
751
751
  if self.settings.PROFIT_AMOUNT > 0:
752
- tpPrice = (price * qty + float(self.settings.PROFIT_AMOUNT))/qty if side == "BUY" else (price * qty - float(self.settings.PROFIT_AMOUNT))/qty
752
+ tpPrice = price + float(self.settings.PROFIT_AMOUNT)/qty if side == "BUY" else price - float(self.settings.PROFIT_AMOUNT)/qty
753
753
  tpPrice = Decimal(await self.str_precision(tpPrice))
754
754
  tpPrice =float(str(tpPrice.quantize(Decimal(f'1e-{decimal_places}'))))
755
755
  tpOrderPrice = await self.increment_by_last_decimal(str(tpPrice))
@@ -762,7 +762,7 @@ class BitunixSignal:
762
762
  slPrice=0
763
763
  slOrderPrice=0
764
764
  if self.settings.LOSS_AMOUNT > 0:
765
- slPrice = (price * qty - float(self.settings.LOSS_AMOUNT))/qty if side == "BUY" else (price * qty + float(self.settings.LOSS_AMOUNT))/qty
765
+ slPrice = price - float(self.settings.LOSS_AMOUNT)/qty if side == "BUY" else price + float(self.settings.LOSS_AMOUNT)/qty
766
766
  slPrice = Decimal(await self.str_precision(slPrice))
767
767
  slPrice = float(str(slPrice.quantize(Decimal(f'1e-{decimal_places}'))))
768
768
  slOrderPrice = await self.increment_by_last_decimal(str(slPrice))
@@ -777,14 +777,17 @@ class BitunixSignal:
777
777
  f'{colors.YELLOW} Opening {"long" if side=="BUY" else "short"} position for {row.symbol} with {qty} qty @ {price})'
778
778
  )
779
779
  datajs = None
780
- if tpPrice == 0 and slPrice == 0:
780
+ if self.settings.BOT_TAKE_PROFIT_STOP_LOSS:
781
781
  datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side)
782
- elif tpPrice == 0:
783
- datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side, slPrice=slPrice, slOrderPrice=slOrderPrice)
784
- elif slPrice == 0:
785
- datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side, tpPrice=tpPrice, tpOrderPrice=tpOrderPrice)
786
- else:
787
- datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side, tpPrice=tpPrice, tpOrderPrice=tpOrderPrice, slPrice=slPrice, slOrderPrice=slOrderPrice)
782
+ else:
783
+ if tpPrice == 0 and slPrice == 0:
784
+ datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side)
785
+ elif tpPrice == 0:
786
+ datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side, slPrice=slPrice, slOrderPrice=slOrderPrice)
787
+ elif slPrice == 0:
788
+ datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side, tpPrice=tpPrice, tpOrderPrice=tpOrderPrice)
789
+ else:
790
+ datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side, tpPrice=tpPrice, tpOrderPrice=tpOrderPrice, slPrice=slPrice, slOrderPrice=slOrderPrice)
788
791
  count=count+1
789
792
  else:
790
793
  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")
@@ -835,7 +838,77 @@ class BitunixSignal:
835
838
  select = False
836
839
 
837
840
  if select and int(self.settings.MAX_AUTO_TRADES)!=0:
838
-
841
+ if self.settings.BOT_TAKE_PROFIT_STOP_LOSS:
842
+ # check take profit amount or accept loss amount
843
+ if float(self.settings.LOSS_AMOUNT) > 0 and total_pnl < -float(self.settings.LOSS_AMOUNT):
844
+ last, bid, ask, mtv = await self.GetTickerBidLastAsk(row.symbol)
845
+ price = (ask if row['side'] == "BUY" else bid if row['side'] == "SELL" else last) if bid<=last<=ask else last
846
+
847
+ self.notifications.add_notification(
848
+ f'{colors.CYAN} Closing {"long" if side=="BUY" else "short"} position due to stop loss amount for {row.symbol} with {row.qty} qty @ {price})'
849
+ )
850
+ datajs = await self.bitunixApi.PlaceOrder(
851
+ positionId=row.positionId,
852
+ ticker=row.symbol,
853
+ qty=row.qty,
854
+ price=price,
855
+ side=row.side,
856
+ tradeSide="CLOSE"
857
+ )
858
+ continue
859
+
860
+ if float(self.settings.PROFIT_AMOUNT) > 0 and total_pnl > float(self.settings.PROFIT_AMOUNT):
861
+ last, bid, ask, mtv = await self.GetTickerBidLastAsk(row.symbol)
862
+ price = (ask if row['side'] == "BUY" else bid if row['side'] == "SELL" else last) if bid<=last<=ask else last
863
+
864
+ self.notifications.add_notification(
865
+ f'{colors.CYAN} Closing {"long" if side=="BUY" else "short"} position due to take profit amount for {row.symbol} with {row.qty} qty @ {price})'
866
+ )
867
+ datajs = await self.bitunixApi.PlaceOrder(
868
+ positionId=row.positionId,
869
+ ticker=row.symbol,
870
+ qty=row.qty,
871
+ price=price,
872
+ side=row.side,
873
+ tradeSide="CLOSE"
874
+ )
875
+ continue
876
+
877
+ # check take profit percentage or accept loss percentage
878
+ if float(self.settings.LOSS_PERCENTAGE) > 0 and row['ROI'] < -float(self.settings.LOSS_PERCENTAGE):
879
+ last, bid, ask, mtv = await self.GetTickerBidLastAsk(row.symbol)
880
+ price = (ask if row['side'] == "BUY" else bid if row['side'] == "SELL" else last) if bid<=last<=ask else last
881
+
882
+ self.notifications.add_notification(
883
+ f'{colors.CYAN} Closing {"long" if side=="BUY" else "short"} position due to stop loss percentage for {row.symbol} with {row.qty} qty @ {price})'
884
+ )
885
+ datajs = await self.bitunixApi.PlaceOrder(
886
+ positionId=row.positionId,
887
+ ticker=row.symbol,
888
+ qty=row.qty,
889
+ price=price,
890
+ side=row.side,
891
+ tradeSide="CLOSE"
892
+ )
893
+ continue
894
+
895
+ if float(self.settings.PROFIT_PERCENTAGE) > 0 and row['ROI'] > float(self.settings.PROFIT_PERCENTAGE):
896
+ last, bid, ask, mtv = await self.GetTickerBidLastAsk(row.symbol)
897
+ price = (ask if row['side'] == "BUY" else bid if row['side'] == "SELL" else last) if bid<=last<=ask else last
898
+
899
+ self.notifications.add_notification(
900
+ f'{colors.CYAN} Closing {"long" if side=="BUY" else "short"} position due to take profit percentage for {row.symbol} with {row.qty} qty @ {price})'
901
+ )
902
+ datajs = await self.bitunixApi.PlaceOrder(
903
+ positionId=row.positionId,
904
+ ticker=row.symbol,
905
+ qty=row.qty,
906
+ price=price,
907
+ side=row.side,
908
+ tradeSide="CLOSE"
909
+ )
910
+ continue
911
+
839
912
  # Moving average comparison between fast and medium or medium and slow
840
913
  if self.settings.EMA_STUDY and self.settings.EMA_CHECK_ON_CLOSE:
841
914
  if row.side == 'BUY' and self.signaldf_full.at[row.symbol, f'{period}_ema_close'] == "SELL":
@@ -21,8 +21,11 @@ class Settings(BaseSettings):
21
21
  LOSS_PERCENTAGE: float = Field(default=10, ge=0.0)
22
22
  PROFIT_AMOUNT: float = Field(default=0, ge=0.0)
23
23
  LOSS_AMOUNT: float = Field(default=5.0, ge=0.0)
24
- PROFIT_LOSS_PRICE_TYPE: str = Field(default="MARK_PRICE")
25
- PROFIT_LOSS_ORDER_TYPE: str = Field(default="LIMIT")
24
+ BOT_TAKE_PROFIT_STOP_LOSS: bool = Field(default=False)
25
+ TAKE_PROFIT_PRICE_TYPE: str = Field(default="MARK_PRICE")
26
+ TAKE_PROFIT_ORDER_TYPE: str = Field(default="LIMIT")
27
+ STOP_LOSS_PRICE_TYPE: str = Field(default="MARK_PRICE")
28
+ STOP_LOSS_ORDER_TYPE: str = Field(default="MARKET")
26
29
  OPTION_MOVING_AVERAGE: str = Field(default="1h")
27
30
  DELAY_IN_MINUTES_FOR_SAME_TICKER_TRADES: int = Field(default=15, ge=0)
28
31
  BARS: int = Field(default=100, ge=1)
@@ -1 +1 @@
1
- __version__ = "3.3.1"
1
+ __version__ = "3.3.2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bitunix_automated_crypto_trading
3
- Version: 3.3.1
3
+ Version: 3.3.2
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=bNIM_1xRYQOFEsIn74EX6qVpC59-GMhhr2CeiPr_GWg,3253
2
- bitunix_automated_crypto_trading/BitunixApi.py,sha256=P5lAToQDl-q8yjLD0bH3G8ajY_fxx3XKet0rS9UP7Pg,13504
3
- bitunix_automated_crypto_trading/BitunixSignal.py,sha256=AbOhi9ehn_QY7ZAVlU_fnIUNKWoVKuy7VLZIE2v75kU,77286
2
+ bitunix_automated_crypto_trading/BitunixApi.py,sha256=4iiqiN3uvX6-bmZ5WtG3pt1No0C6eNlqdLA5jylXRp8,13496
3
+ bitunix_automated_crypto_trading/BitunixSignal.py,sha256=rVoVBSb3T3Zw-lJt1s4gRV-e8tZSZu4EINdbiilQgUc,82493
4
4
  bitunix_automated_crypto_trading/BitunixWebSocket.py,sha256=uiqAcis3u-ct07tjaTiC87ujzvcAtVRZ31CMiTBDW_M,11309
5
5
  bitunix_automated_crypto_trading/DataFrameHtmlRenderer.py,sha256=Pqdzhh_nfIxFEZH9L_R5QXB8moDPbgeTGT_hmBkHWMg,2899
6
6
  bitunix_automated_crypto_trading/NotificationManager.py,sha256=exs6REABBA1omTeTGuUuECzxs5dGqdyL7oI8WyxS6Xc,798
@@ -9,11 +9,11 @@ bitunix_automated_crypto_trading/ThreadManager.py,sha256=Lw5_1EIT0m3AFSv5CIMpnjt
9
9
  bitunix_automated_crypto_trading/TickerManager.py,sha256=E6U08wO1LKY4XctB6frtoAmlactMng3xwRrqG59qDt8,43030
10
10
  bitunix_automated_crypto_trading/__init__.py,sha256=1hzk6nX8NnUCr1tsq8oFq1qGCNhNwnwldWE75641Eew,78
11
11
  bitunix_automated_crypto_trading/bitunix.py,sha256=lxwnYARxldA2oU6GdjupilXIlnUh4RX8rQLCOn7x13I,27143
12
- bitunix_automated_crypto_trading/config.py,sha256=7h8GvMH1SFuFPhKM3azA2pVS0w2CRzKtUankhI-IKHY,5655
12
+ bitunix_automated_crypto_trading/config.py,sha256=OASGCVl0avfVSLqdaZC4fxFSiVIrmdMvin3wJMB3Kq0,5830
13
13
  bitunix_automated_crypto_trading/logger.py,sha256=NHnA5JZdUFkTAhB7i-1iCAwrdf1fxhDuRvJUkbKPi9Y,2923
14
- bitunix_automated_crypto_trading/version.py,sha256=vFVFOckEr44mXptQFYzU0w8rn7ILjARfK9BoWOrTJxA,21
15
- bitunix_automated_crypto_trading-3.3.1.dist-info/METADATA,sha256=pjC1qj0p9YPnHNXbIfllgnuedbaHWH61mk9tgBqrHJo,996
16
- bitunix_automated_crypto_trading-3.3.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
- bitunix_automated_crypto_trading-3.3.1.dist-info/entry_points.txt,sha256=UXREYHuSl2XYd_tOtLIq0zg3d1kX3lixX5SpN8yGBw4,82
18
- bitunix_automated_crypto_trading-3.3.1.dist-info/top_level.txt,sha256=uyFzHUCOsp8elnG2Ovor6xXcf7dxRxY-C-Txiwix64Q,33
19
- bitunix_automated_crypto_trading-3.3.1.dist-info/RECORD,,
14
+ bitunix_automated_crypto_trading/version.py,sha256=atqyGOnhrhSlkFH4WgeEJ48n-b00QDPSS9LvTLmvhmU,21
15
+ bitunix_automated_crypto_trading-3.3.2.dist-info/METADATA,sha256=m_1FPUbtyZuXsTNhtwPOAZRSiKclI6kdnJ7O2HIudmo,996
16
+ bitunix_automated_crypto_trading-3.3.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
+ bitunix_automated_crypto_trading-3.3.2.dist-info/entry_points.txt,sha256=UXREYHuSl2XYd_tOtLIq0zg3d1kX3lixX5SpN8yGBw4,82
18
+ bitunix_automated_crypto_trading-3.3.2.dist-info/top_level.txt,sha256=uyFzHUCOsp8elnG2Ovor6xXcf7dxRxY-C-Txiwix64Q,33
19
+ bitunix_automated_crypto_trading-3.3.2.dist-info/RECORD,,