bitunix-automated-crypto-trading 3.3.0__tar.gz → 3.3.2__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.
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/PKG-INFO +1 -1
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/BitunixApi.py +8 -8
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/BitunixSignal.py +86 -12
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/config.py +5 -2
- bitunix_automated_crypto_trading-3.3.2/bitunix_automated_crypto_trading/version.py +1 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading.egg-info/PKG-INFO +1 -1
- bitunix_automated_crypto_trading-3.3.0/bitunix_automated_crypto_trading/version.py +0 -1
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/README.md +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/AsyncThreadRunner.py +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/BitunixWebSocket.py +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/DataFrameHtmlRenderer.py +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/NotificationManager.py +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/SupportResistance.py +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/ThreadManager.py +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/TickerManager.py +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/__init__.py +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/bitunix.py +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading/logger.py +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading.egg-info/SOURCES.txt +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading.egg-info/dependency_links.txt +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading.egg-info/entry_points.txt +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading.egg-info/requires.txt +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/bitunix_automated_crypto_trading.egg-info/top_level.txt +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/setup.cfg +0 -0
- {bitunix_automated_crypto_trading-3.3.0 → bitunix_automated_crypto_trading-3.3.2}/setup.py +0 -0
@@ -143,8 +143,8 @@ class BitunixApi:
|
|
143
143
|
"symbol": ticker,
|
144
144
|
"tradeSide":tradeSide,
|
145
145
|
"slPrice": slPrice,
|
146
|
-
"slStopType": self.settings.
|
147
|
-
"slOrderType": self.settings.
|
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.
|
162
|
-
"tpOrderType": self.settings.
|
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.
|
177
|
-
"tpOrderType": self.settings.
|
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.
|
181
|
-
"slOrderType": self.settings.
|
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(
|
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
|
-
|
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 =
|
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 =
|
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
|
780
|
+
if self.settings.BOT_TAKE_PROFIT_STOP_LOSS:
|
780
781
|
datajs = await self.bitunixApi.PlaceOrder(row.symbol, qty, price, side)
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
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
|
-
|
25
|
-
|
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)
|
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = "3.3.2"
|
@@ -1 +0,0 @@
|
|
1
|
-
__version__ = "3.3.0"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|