bitunix-automated-crypto-trading 3.3.0__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']})
@@ -725,7 +725,8 @@ class BitunixSignal:
725
725
  xtime = float(data['positionList'][0]['mtime'])
726
726
  mtime = pd.to_datetime(xtime, unit='ms').tz_localize('UTC').tz_convert(cst).strftime('%Y-%m-%d %H:%M:%S')
727
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:
728
+ self.logger.info(f"row.symbol: {row.symbol} , duration_minutes: {duration_minutes}, last trade time: {mtime if duration_minutes is not None else 'N/A'}")
729
+ if duration_minutes is None or duration_minutes > self.settings.DELAY_IN_MINUTES_FOR_SAME_TICKER_TRADES:
729
730
  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 ""
730
731
  if side != "":
731
732
  select = True
@@ -748,7 +749,7 @@ class BitunixSignal:
748
749
  tpPrice=0
749
750
  tpOrderPrice=0
750
751
  if self.settings.PROFIT_AMOUNT > 0:
751
- 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
752
753
  tpPrice = Decimal(await self.str_precision(tpPrice))
753
754
  tpPrice =float(str(tpPrice.quantize(Decimal(f'1e-{decimal_places}'))))
754
755
  tpOrderPrice = await self.increment_by_last_decimal(str(tpPrice))
@@ -761,7 +762,7 @@ class BitunixSignal:
761
762
  slPrice=0
762
763
  slOrderPrice=0
763
764
  if self.settings.LOSS_AMOUNT > 0:
764
- 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
765
766
  slPrice = Decimal(await self.str_precision(slPrice))
766
767
  slPrice = float(str(slPrice.quantize(Decimal(f'1e-{decimal_places}'))))
767
768
  slOrderPrice = await self.increment_by_last_decimal(str(slPrice))
@@ -776,14 +777,17 @@ class BitunixSignal:
776
777
  f'{colors.YELLOW} Opening {"long" if side=="BUY" else "short"} position for {row.symbol} with {qty} qty @ {price})'
777
778
  )
778
779
  datajs = None
779
- if tpPrice == 0 and slPrice == 0:
780
+ if self.settings.BOT_TAKE_PROFIT_STOP_LOSS:
780
781
  datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side)
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)
785
- else:
786
- 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)
787
791
  count=count+1
788
792
  else:
789
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")
@@ -834,7 +838,77 @@ class BitunixSignal:
834
838
  select = False
835
839
 
836
840
  if select and int(self.settings.MAX_AUTO_TRADES)!=0:
837
-
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
+
838
912
  # Moving average comparison between fast and medium or medium and slow
839
913
  if self.settings.EMA_STUDY and self.settings.EMA_CHECK_ON_CLOSE:
840
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.0"
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.0
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=4b3duPz-2yhED_RdkDHES3mIGBEBMUjm62KWNWF0G60,77108
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=pBZAADr6KRwbPFnSX-lkJfCOxPfkVlEbwPaS4e7HXho,21
15
- bitunix_automated_crypto_trading-3.3.0.dist-info/METADATA,sha256=HghOyHcOXfwKWfkgBA2tcsyfrIMacffT39xHx7U_QfQ,996
16
- bitunix_automated_crypto_trading-3.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
- bitunix_automated_crypto_trading-3.3.0.dist-info/entry_points.txt,sha256=UXREYHuSl2XYd_tOtLIq0zg3d1kX3lixX5SpN8yGBw4,82
18
- bitunix_automated_crypto_trading-3.3.0.dist-info/top_level.txt,sha256=uyFzHUCOsp8elnG2Ovor6xXcf7dxRxY-C-Txiwix64Q,33
19
- bitunix_automated_crypto_trading-3.3.0.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,,