Fix a bit bots
This commit is contained in:
@@ -510,12 +510,14 @@ public class TradingBot : Bot, ITradingBot
|
||||
var position = await new OpenPositionCommandHandler(ExchangeService, AccountService, TradingService)
|
||||
.Handle(command);
|
||||
|
||||
|
||||
if (position != null)
|
||||
{
|
||||
position.SignalIdentifier = signal.Identifier;
|
||||
Positions.Add(position);
|
||||
|
||||
if (position.Open.Status != TradeStatus.Cancelled)
|
||||
{
|
||||
position.SignalIdentifier = signal.Identifier;
|
||||
Positions.Add(position);
|
||||
SetSignalStatus(signal.Identifier, SignalStatus.PositionOpen);
|
||||
|
||||
if (!IsForBacktest)
|
||||
@@ -534,8 +536,11 @@ public class TradingBot : Bot, ITradingBot
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Keep signal open for debug purpose
|
||||
//SetSignalStatus(signal.Identifier, SignalStatus.Expired);
|
||||
SetSignalStatus(signal.Identifier, SignalStatus.Expired);
|
||||
await LogWarning($"Cannot open trade : {ex.Message}");
|
||||
|
||||
await LogWarning($"Cannot open trade : {ex.Message}, stackTrace : {ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +42,7 @@ namespace Managing.Application.Trading
|
||||
? request.Price.Value
|
||||
: exchangeService.GetPrice(account, request.Ticker, DateTime.Now);
|
||||
var quantity = balanceAtRisk / price;
|
||||
var fee = request.IsForPaperTrading
|
||||
? request.Fee.GetValueOrDefault()
|
||||
: tradingService.GetFee(account, request.IsForPaperTrading);
|
||||
|
||||
var expectedStatus = GetExpectedStatus(request);
|
||||
// var expectedStatus = GetExpectedStatus(request);
|
||||
// position.Open = TradingPolicies.OpenPosition(expectedStatus).Execute(async () => { });
|
||||
|
||||
var openPrice = request.IsForPaperTrading || request.Price.HasValue
|
||||
@@ -70,7 +66,7 @@ namespace Managing.Application.Trading
|
||||
stopLossPrice: stopLossPrice, // Pass determined SL price
|
||||
takeProfitPrice: takeProfitPrice); // Pass determined TP price
|
||||
|
||||
trade.Fee = TradingHelpers.GetFeeAmount(fee, openPrice * quantity, account.Exchange);
|
||||
//trade.Fee = TradingHelpers.GetFeeAmount(fee, openPrice * quantity, account.Exchange);
|
||||
position.Open = trade;
|
||||
|
||||
var closeDirection = request.Direction == TradeDirection.Long
|
||||
@@ -88,8 +84,8 @@ namespace Managing.Application.Trading
|
||||
request.Date,
|
||||
TradeStatus.Requested);
|
||||
|
||||
position.StopLoss.Fee = TradingHelpers.GetFeeAmount(fee,
|
||||
position.StopLoss.Price * position.StopLoss.Quantity, account.Exchange);
|
||||
// position.StopLoss.Fee = TradingHelpers.GetFeeAmount(fee,
|
||||
// position.StopLoss.Price * position.StopLoss.Quantity, account.Exchange);
|
||||
|
||||
// Take profit - Use the determined price
|
||||
position.TakeProfit1 = exchangeService.BuildEmptyTrade(
|
||||
|
||||
Reference in New Issue
Block a user