Trading bot grain (#33)
* Trading bot Grain * Fix a bit more of the trading bot * Advance on the tradingbot grain * Fix build * Fix db script * Fix user login * Fix a bit backtest * Fix cooldown and backtest * start fixing bot start * Fix startup * Setup local db * Fix build and update candles and scenario * Add bot registry * Add reminder * Updateing the grains * fix bootstraping * Save stats on tick * Save bot data every tick * Fix serialization * fix save bot stats * Fix get candles * use dict instead of list for position * Switch hashset to dict * Fix a bit * Fix bot launch and bot view * add migrations * Remove the tolist * Add agent grain * Save agent summary * clean * Add save bot * Update get bots * Add get bots * Fix stop/restart * fix Update config * Update scanner table on new backtest saved * Fix backtestRowDetails.tsx * Fix agentIndex * Update agentIndex * Fix more things * Update user cache * Fix * Fix account load/start/restart/run
This commit is contained in:
@@ -26,7 +26,8 @@ public class UserController : BaseController
|
||||
/// <param name="userService">Service for user-related operations.</param>
|
||||
/// <param name="jwtUtils">Utility for JWT token operations.</param>
|
||||
/// <param name="webhookService">Service for webhook operations.</param>
|
||||
public UserController(IConfiguration config, IUserService userService, IJwtUtils jwtUtils, IWebhookService webhookService)
|
||||
public UserController(IConfiguration config, IUserService userService, IJwtUtils jwtUtils,
|
||||
IWebhookService webhookService)
|
||||
: base(userService)
|
||||
{
|
||||
_config = config;
|
||||
@@ -40,7 +41,7 @@ public class UserController : BaseController
|
||||
/// <param name="login">The login request containing user credentials.</param>
|
||||
/// <returns>A JWT token if authentication is successful; otherwise, an Unauthorized result.</returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost]
|
||||
[HttpPost("create-token")]
|
||||
public async Task<ActionResult<string>> CreateToken([FromBody] LoginRequest login)
|
||||
{
|
||||
var user = await _userService.Authenticate(login.Name, login.Address, login.Message, login.Signature);
|
||||
@@ -52,16 +53,18 @@ public class UserController : BaseController
|
||||
}
|
||||
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current user's information.
|
||||
/// </summary>
|
||||
/// <returns>The current user's information.</returns>
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<User>> GetCurrentUser()
|
||||
{
|
||||
var user = await base.GetUser();
|
||||
user = await _userService.GetUserByName(user.Name);
|
||||
return Ok(user);
|
||||
}
|
||||
|
||||
@@ -70,6 +73,7 @@ public class UserController : BaseController
|
||||
/// </summary>
|
||||
/// <param name="agentName">The new agent name to set.</param>
|
||||
/// <returns>The updated user with the new agent name.</returns>
|
||||
[Authorize]
|
||||
[HttpPut("agent-name")]
|
||||
public async Task<ActionResult<User>> UpdateAgentName([FromBody] string agentName)
|
||||
{
|
||||
@@ -83,6 +87,7 @@ public class UserController : BaseController
|
||||
/// </summary>
|
||||
/// <param name="avatarUrl">The new avatar URL to set.</param>
|
||||
/// <returns>The updated user with the new avatar URL.</returns>
|
||||
[Authorize]
|
||||
[HttpPut("avatar")]
|
||||
public async Task<ActionResult<User>> UpdateAvatarUrl([FromBody] string avatarUrl)
|
||||
{
|
||||
@@ -96,35 +101,37 @@ public class UserController : BaseController
|
||||
/// </summary>
|
||||
/// <param name="telegramChannel">The new Telegram channel to set.</param>
|
||||
/// <returns>The updated user with the new Telegram channel.</returns>
|
||||
[Authorize]
|
||||
[HttpPut("telegram-channel")]
|
||||
public async Task<ActionResult<User>> UpdateTelegramChannel([FromBody] string telegramChannel)
|
||||
{
|
||||
var user = await GetUser();
|
||||
var updatedUser = await _userService.UpdateTelegramChannel(user, telegramChannel);
|
||||
|
||||
|
||||
// Send welcome message to the newly configured telegram channel
|
||||
if (!string.IsNullOrEmpty(telegramChannel))
|
||||
{
|
||||
try
|
||||
{
|
||||
var welcomeMessage = $"🎉 **Trading Bot - Welcome!**\n\n" +
|
||||
$"🎯 **Agent:** {user.Name}\n" +
|
||||
$"📡 **Channel ID:** {telegramChannel}\n" +
|
||||
$"⏰ **Setup Time:** {DateTime.UtcNow:MMM dd, yyyy • HH:mm:ss} UTC\n\n" +
|
||||
$"🔔 **Notification Types:**\n" +
|
||||
$"• 📈 Position Opens & Closes\n" +
|
||||
$"• 🤖 Bot configuration changes\n\n" +
|
||||
$"🚀 **Welcome aboard!** Your trading notifications are now live.";
|
||||
$"🎯 **Agent:** {user.Name}\n" +
|
||||
$"📡 **Channel ID:** {telegramChannel}\n" +
|
||||
$"⏰ **Setup Time:** {DateTime.UtcNow:MMM dd, yyyy • HH:mm:ss} UTC\n\n" +
|
||||
$"🔔 **Notification Types:**\n" +
|
||||
$"• 📈 Position Opens & Closes\n" +
|
||||
$"• 🤖 Bot configuration changes\n\n" +
|
||||
$"🚀 **Welcome aboard!** Your trading notifications are now live.";
|
||||
|
||||
await _webhookService.SendMessage(welcomeMessage, telegramChannel);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Log the error but don't fail the update operation
|
||||
Console.WriteLine($"Failed to send welcome message to telegram channel {telegramChannel}: {ex.Message}");
|
||||
Console.WriteLine(
|
||||
$"Failed to send welcome message to telegram channel {telegramChannel}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Ok(updatedUser);
|
||||
}
|
||||
|
||||
@@ -132,11 +139,12 @@ public class UserController : BaseController
|
||||
/// Tests the Telegram channel configuration by sending a test message.
|
||||
/// </summary>
|
||||
/// <returns>A message indicating the test result.</returns>
|
||||
[Authorize]
|
||||
[HttpPost("telegram-channel/test")]
|
||||
public async Task<ActionResult<string>> TestTelegramChannel()
|
||||
{
|
||||
var user = await GetUser();
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(user.TelegramChannel))
|
||||
{
|
||||
return BadRequest("No Telegram channel configured for this user. Please set a Telegram channel first.");
|
||||
@@ -144,7 +152,7 @@ public class UserController : BaseController
|
||||
|
||||
try
|
||||
{
|
||||
var testMessage = $"🚀 **Trading Bot - Channel Test**\n\n" +
|
||||
var testMessage = $"🚀 **Trading Bot - Channel Test**\n\n" +
|
||||
$"🎯 **Agent:** {user.Name}\n" +
|
||||
$"📡 **Channel ID:** {user.TelegramChannel}\n" +
|
||||
$"⏰ **Test Time:** {DateTime.UtcNow:MMM dd, yyyy • HH:mm:ss} UTC\n\n" +
|
||||
@@ -154,13 +162,13 @@ public class UserController : BaseController
|
||||
$"🎉 **Ready to trade!** Your notifications are now active.";
|
||||
|
||||
await _webhookService.SendMessage(testMessage, user.TelegramChannel);
|
||||
|
||||
return Ok($"Test message sent successfully to Telegram channel {user.TelegramChannel}. Please check your Telegram to verify delivery.");
|
||||
|
||||
return Ok(
|
||||
$"Test message sent successfully to Telegram channel {user.TelegramChannel}. Please check your Telegram to verify delivery.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"Failed to send test message: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user