bitunix-automated-crypto-trading 3.3.5__py3-none-any.whl → 3.3.6__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.
- bitunix_automated_crypto_trading/BitunixSignal.py +53 -38
- bitunix_automated_crypto_trading/config.py +2 -1
- bitunix_automated_crypto_trading/version.py +1 -1
- {bitunix_automated_crypto_trading-3.3.5.dist-info → bitunix_automated_crypto_trading-3.3.6.dist-info}/METADATA +1 -1
- {bitunix_automated_crypto_trading-3.3.5.dist-info → bitunix_automated_crypto_trading-3.3.6.dist-info}/RECORD +8 -8
- {bitunix_automated_crypto_trading-3.3.5.dist-info → bitunix_automated_crypto_trading-3.3.6.dist-info}/WHEEL +0 -0
- {bitunix_automated_crypto_trading-3.3.5.dist-info → bitunix_automated_crypto_trading-3.3.6.dist-info}/entry_points.txt +0 -0
- {bitunix_automated_crypto_trading-3.3.5.dist-info → bitunix_automated_crypto_trading-3.3.6.dist-info}/top_level.txt +0 -0
@@ -643,27 +643,21 @@ class BitunixSignal:
|
|
643
643
|
del inuse1, inuse2, inuseTickers
|
644
644
|
gc.collect()
|
645
645
|
|
646
|
-
|
647
|
-
"""Calculates the duration in minutes from trade time to current time."""
|
648
|
-
current_time_unix = int(time.time()) # Get current Unix timestamp
|
649
|
-
print(f"Current time (Unix): {current_time_unix}, Trade time (Unix): {trade_time_unix}")
|
650
|
-
duration_seconds = current_time_unix - trade_time_unix
|
651
|
-
duration_minutes = duration_seconds / 60 # Convert seconds to minutes
|
652
|
-
return round(duration_minutes)
|
653
|
-
|
646
|
+
|
654
647
|
async def get_duration(self,datetime_str):
|
655
648
|
"""Calculates the duration in minutes from a given datetime string to the current time."""
|
656
649
|
# Convert input datetime string to a datetime object
|
657
650
|
trade_time = datetime.strptime(datetime_str, "%Y-%m-%d %H:%M:%S")
|
658
|
-
|
659
|
-
# Convert datetime object to Unix timestamp
|
651
|
+
# Convert datetime object to Unix timestamp)
|
660
652
|
trade_time_unix = int(trade_time.timestamp())
|
661
|
-
|
653
|
+
print(f"trade_time_unix: {trade_time_unix}, trade_time: {trade_time}")
|
662
654
|
# Get current Unix timestamp
|
663
655
|
current_time_unix = int(time.time())
|
664
|
-
|
656
|
+
print(f"current_time_unix: {current_time_unix}, time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
665
657
|
# Calculate duration in minutes
|
666
658
|
duration_minutes = (current_time_unix - trade_time_unix) / 60
|
659
|
+
print(f"diff: {current_time_unix - trade_time_unix}")
|
660
|
+
print(f"duration_minutes: {duration_minutes}")
|
667
661
|
|
668
662
|
return round(duration_minutes)
|
669
663
|
|
@@ -812,7 +806,7 @@ class BitunixSignal:
|
|
812
806
|
current_time = time.time() * 1000
|
813
807
|
df=self.orderdf.copy(deep=False)
|
814
808
|
for index, row in df.iterrows():
|
815
|
-
if current_time - int(row.ctime) >
|
809
|
+
if current_time - int(row.ctime) > 60000:
|
816
810
|
self.notifications.add_notification(
|
817
811
|
f'{colors.LBLUE} Canceling order {row.orderId}, {row.symbol} {row.qty} created at {row.rtime} '
|
818
812
|
)
|
@@ -829,8 +823,8 @@ class BitunixSignal:
|
|
829
823
|
|
830
824
|
# Calculate the duration in minutes since the position was opened
|
831
825
|
ctime = row['ctime']
|
832
|
-
duration_minutes = await self.get_duration(ctime)
|
833
|
-
no_of_candles_since_current_open = await self.calculate_candles(period, duration_minutes)
|
826
|
+
#duration_minutes = await self.get_duration(ctime)
|
827
|
+
#no_of_candles_since_current_open = await self.calculate_candles(period, duration_minutes)
|
834
828
|
|
835
829
|
requiredCols=[f'{period}_open', f'{period}_close', f'{period}_high', f'{period}_low', f'{period}_ema_open', f"{period}_ema_close", f'{period}_macd', f'{period}_bbm', f'{period}_rsi', f'{period}_trendline', f'{period}_candle_trend', f'{period}_trend', f'{period}_cb', f'{period}_barcolor']
|
836
830
|
required_cols = set(requiredCols)
|
@@ -846,7 +840,7 @@ class BitunixSignal:
|
|
846
840
|
|
847
841
|
if select and int(self.settings.MAX_AUTO_TRADES)!=0:
|
848
842
|
|
849
|
-
if self.settings.
|
843
|
+
if self.settings.PROFIT_PERCENTAGE > 0 and self.settings.LOSS_PERCENTAGE > 0:
|
850
844
|
last, bid, ask, mtv = await self.GetTickerBidLastAsk(row.symbol)
|
851
845
|
price = (bid if side == "BUY" else ask if side == "SELL" else last) if bid<=last<=ask else last
|
852
846
|
decimal_places = abs(Decimal(str(price)).as_tuple().exponent)
|
@@ -861,13 +855,17 @@ class BitunixSignal:
|
|
861
855
|
old_tpPrice = None
|
862
856
|
tpStopType = self.settings.SL_STOP_TYPE
|
863
857
|
tpOrderType = self.settings.SL_ORDER_TYPE
|
858
|
+
tpOrderPrice = None
|
864
859
|
|
865
860
|
slPrice = None
|
866
861
|
slorderId = None
|
867
862
|
old_slPrice = None
|
868
863
|
slStopType = self.settings.SL_STOP_TYPE
|
869
864
|
slOrderType = self.settings.SL_ORDER_TYPE
|
865
|
+
slOrderPrice = None
|
870
866
|
|
867
|
+
roi = round((row['unrealizedPNL'] / (row['qty'] * row['avgOpenPrice'])) * 100 * self.settings.LEVERAGE,2)
|
868
|
+
|
871
869
|
datajs = await self.bitunixApi.GetPendingTpSlOrderData({'symbol': symbol})
|
872
870
|
if datajs:
|
873
871
|
for order in datajs:
|
@@ -885,33 +883,50 @@ class BitunixSignal:
|
|
885
883
|
old_slPrice = slPrice
|
886
884
|
|
887
885
|
# move TP and SL in the direction of profit
|
888
|
-
|
889
|
-
|
886
|
+
tp_midpoint = None
|
887
|
+
sl_midpoint = None
|
888
|
+
if self.settings.BOT_TRAIL_TP:
|
889
|
+
if old_tpPrice is not None:
|
890
|
+
tp_midpoint = old_tpPrice / (1 + self.settings.PROFIT_PERCENTAGE/100/self.settings.LEVERAGE) if side == "BUY" else old_tpPrice / (1 - self.settings.PROFIT_PERCENTAGE/100/self.settings.LEVERAGE) if tpPrice is not None else None
|
891
|
+
if tp_midpoint is not None and (price > tp_midpoint and side == "BUY" or price < tp_midpoint and side == "SELL"):
|
892
|
+
|
893
|
+
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)
|
894
|
+
tpPrice = Decimal(await self.str_precision(tpPrice))
|
895
|
+
tpPrice =float(str(tpPrice.quantize(Decimal(f'1e-{decimal_places}'))))
|
896
|
+
tpOrderPrice = await self.decrement_by_last_decimal(str(tpPrice))
|
890
897
|
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
898
|
+
|
899
|
+
if self.settings.BOT_TRAIL_SL:
|
900
|
+
if old_slPrice is not None:
|
901
|
+
sl_midpoint = old_slPrice / (1 - self.settings.LOSS_PERCENTAGE/100/self.settings.LEVERAGE) if side == "BUY" else old_slPrice / (1 + self.settings.LOSS_PERCENTAGE/100/self.settings.LEVERAGE) if tpPrice is not None else None
|
902
|
+
if sl_midpoint is not None and (price > sl_midpoint and side == "BUY" or price < sl_midpoint and side == "SELL"):
|
895
903
|
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
904
|
+
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)
|
905
|
+
slPrice = Decimal(await self.str_precision(slPrice))
|
906
|
+
slPrice = float(str(slPrice.quantize(Decimal(f'1e-{decimal_places}'))))
|
907
|
+
slOrderPrice = await self.increment_by_last_decimal(await self.str_precision(slPrice))
|
900
908
|
|
909
|
+
if (self.settings.BOT_TRAIL_TP and tpOrderPrice is not None) or (self.settings.BOT_TRAIL_SL and slOrderPrice is not None):
|
901
910
|
self.notifications.add_notification(
|
902
|
-
f'{colors.CYAN} {row.symbol} TP
|
911
|
+
f'{colors.CYAN} {row.symbol} price: {price}, ROI: {roi}%, TP: {old_tpPrice}, TP midpoint: {tp_midpoint}, new TP: {tpPrice}, SL: {old_slPrice}, SL midpoint: {sl_midpoint}, new SL: {slPrice}'
|
903
912
|
)
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
913
|
+
|
914
|
+
|
915
|
+
if self.settings.BOT_TRAIL_TP and tpPrice is not None and tpOrderPrice is not None:
|
916
|
+
datajs2 = await self.bitunixApi.ModifyTpSlOrder({'orderId':tporderId,'tpPrice':str(tpPrice), 'tpOrderPrice':str(tpOrderPrice), 'tpQty':str(qty),'tpStopType':tpStopType,'tpOrderType':tpOrderType})
|
917
|
+
if datajs2 is not None:
|
918
|
+
self.notifications.add_notification(
|
919
|
+
f'{colors.CYAN} Take Profit order for {row.symbol} moved from {old_tpPrice} to {tpPrice}'
|
920
|
+
)
|
921
|
+
|
922
|
+
if self.settings.BOT_TRAIL_SL and slPrice is not None and slOrderPrice is not None:
|
923
|
+
datajs3 = await self.bitunixApi.ModifyTpSlOrder({'orderId':slorderId,'slPrice':str(slPrice),'slQty':str(qty),'slStopType':slStopType,'slOrderType':slOrderType})
|
924
|
+
if datajs3 is not None:
|
925
|
+
self.notifications.add_notification(
|
926
|
+
f'{colors.CYAN} Stop Loss order for {row.symbol} moved from {old_slPrice} to {slPrice}'
|
927
|
+
)
|
928
|
+
|
929
|
+
|
915
930
|
|
916
931
|
if self.settings.BOT_CONTROLS_TP_SL:
|
917
932
|
# check take profit amount or accept loss amount
|
@@ -22,7 +22,8 @@ class Settings(BaseSettings):
|
|
22
22
|
PROFIT_AMOUNT: float = Field(default=0, ge=0.0)
|
23
23
|
LOSS_AMOUNT: float = Field(default=5.0, ge=0.0)
|
24
24
|
BOT_CONTROLS_TP_SL: bool = Field(default=False)
|
25
|
-
|
25
|
+
BOT_TRAIL_TP: bool = Field(default=False)
|
26
|
+
BOT_TRAIL_SL: bool = Field(default=False)
|
26
27
|
TP_STOP_TYPE: str = Field(default="MARK_PRICE")
|
27
28
|
TP_ORDER_TYPE: str = Field(default="LIMIT")
|
28
29
|
SL_STOP_TYPE: str = Field(default="MARK_PRICE")
|
@@ -1 +1 @@
|
|
1
|
-
__version__ = "3.3.
|
1
|
+
__version__ = "3.3.6"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
bitunix_automated_crypto_trading/AsyncThreadRunner.py,sha256=bNIM_1xRYQOFEsIn74EX6qVpC59-GMhhr2CeiPr_GWg,3253
|
2
2
|
bitunix_automated_crypto_trading/BitunixApi.py,sha256=5qg-K5IcsAbb6K1feP9zL7RzSz7JzdGAxoY8R_YWxWE,15666
|
3
|
-
bitunix_automated_crypto_trading/BitunixSignal.py,sha256=
|
3
|
+
bitunix_automated_crypto_trading/BitunixSignal.py,sha256=bZjkTPT74iwWglfgAuHiJUppX1Xu_jPLFIaup1sxDAo,89701
|
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=CLd7pvE-qyYBPBauy--A54z7srmMMJsiaWcrY4ezFFU,41939
|
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
|
12
|
+
bitunix_automated_crypto_trading/config.py,sha256=-gP54OFwQkSfJFCGvFW7kJ7z4n6fsLfG493cwcdp42g,5881
|
13
13
|
bitunix_automated_crypto_trading/logger.py,sha256=NHnA5JZdUFkTAhB7i-1iCAwrdf1fxhDuRvJUkbKPi9Y,2923
|
14
|
-
bitunix_automated_crypto_trading/version.py,sha256=
|
15
|
-
bitunix_automated_crypto_trading-3.3.
|
16
|
-
bitunix_automated_crypto_trading-3.3.
|
17
|
-
bitunix_automated_crypto_trading-3.3.
|
18
|
-
bitunix_automated_crypto_trading-3.3.
|
19
|
-
bitunix_automated_crypto_trading-3.3.
|
14
|
+
bitunix_automated_crypto_trading/version.py,sha256=QlDzkQK9qeebPm7w86m1PXgNyblEjljJHbkYgYpwrx4,21
|
15
|
+
bitunix_automated_crypto_trading-3.3.6.dist-info/METADATA,sha256=kVSH1fSEHWwEVPWarKVC5FpXcTVjrv6I4m9xXGtrTeE,996
|
16
|
+
bitunix_automated_crypto_trading-3.3.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
17
|
+
bitunix_automated_crypto_trading-3.3.6.dist-info/entry_points.txt,sha256=UXREYHuSl2XYd_tOtLIq0zg3d1kX3lixX5SpN8yGBw4,82
|
18
|
+
bitunix_automated_crypto_trading-3.3.6.dist-info/top_level.txt,sha256=uyFzHUCOsp8elnG2Ovor6xXcf7dxRxY-C-Txiwix64Q,33
|
19
|
+
bitunix_automated_crypto_trading-3.3.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|