Add ROI to botPaginated
This commit is contained in:
@@ -365,7 +365,7 @@ public class BotController : BaseController
|
||||
string? name = null,
|
||||
string? ticker = null,
|
||||
string? agentName = null,
|
||||
string sortBy = "CreateDate",
|
||||
BotSortableColumn sortBy = BotSortableColumn.CreateDate,
|
||||
string sortDirection = "Desc")
|
||||
{
|
||||
try
|
||||
@@ -456,6 +456,7 @@ public class BotController : BaseController
|
||||
? item.TradeWins / (item.TradeWins + item.TradeLosses)
|
||||
: 0,
|
||||
ProfitAndLoss = item.Pnl,
|
||||
Roi = item.Roi,
|
||||
Identifier = item.Identifier.ToString(),
|
||||
AgentName = item.User.AgentName,
|
||||
CreateDate = item.CreateDate,
|
||||
|
||||
@@ -43,10 +43,10 @@ public class GetBotsPaginatedRequest
|
||||
public string? AgentName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sort field. Valid values: "Name", "Ticker", "Status", "CreateDate", "StartupTime", "Pnl", "WinRate", "AgentName".
|
||||
/// Default is "CreateDate".
|
||||
/// Sort field as enum to restrict allowed values.
|
||||
/// Default is CreateDate.
|
||||
/// </summary>
|
||||
public string SortBy { get; set; } = "CreateDate";
|
||||
public BotSortableColumn SortBy { get; set; } = BotSortableColumn.CreateDate;
|
||||
|
||||
/// <summary>
|
||||
/// Sort direction. Default is "Desc" (descending).
|
||||
|
||||
@@ -44,6 +44,12 @@ namespace Managing.Api.Models.Responses
|
||||
[Required]
|
||||
public decimal ProfitAndLoss { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current return on investment percentage
|
||||
/// </summary>
|
||||
[Required]
|
||||
public decimal Roi { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Unique identifier for the bot
|
||||
/// </summary>
|
||||
|
||||
@@ -35,7 +35,7 @@ public interface IBotRepository
|
||||
string? name = null,
|
||||
string? ticker = null,
|
||||
string? agentName = null,
|
||||
string sortBy = "CreateDate",
|
||||
BotSortableColumn sortBy = BotSortableColumn.CreateDate,
|
||||
string sortDirection = "Desc");
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -55,7 +55,7 @@ public interface IBotService
|
||||
string? name = null,
|
||||
string? ticker = null,
|
||||
string? agentName = null,
|
||||
string sortBy = "CreateDate",
|
||||
BotSortableColumn sortBy = BotSortableColumn.CreateDate,
|
||||
string sortDirection = "Desc");
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -451,7 +451,7 @@ namespace Managing.Application.ManageBot
|
||||
string? name = null,
|
||||
string? ticker = null,
|
||||
string? agentName = null,
|
||||
string sortBy = "CreateDate",
|
||||
BotSortableColumn sortBy = BotSortableColumn.CreateDate,
|
||||
string sortDirection = "Desc")
|
||||
{
|
||||
return await ServiceScopeHelpers.WithScopedService<IBotRepository, (IEnumerable<Bot> Bots, int TotalCount)>(
|
||||
|
||||
@@ -81,6 +81,22 @@ public static class Enums
|
||||
Running,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sortable columns for bots pagination endpoints
|
||||
/// </summary>
|
||||
public enum BotSortableColumn
|
||||
{
|
||||
CreateDate,
|
||||
Name,
|
||||
Ticker,
|
||||
Status,
|
||||
StartupTime,
|
||||
Roi,
|
||||
Pnl,
|
||||
WinRate,
|
||||
AgentName
|
||||
}
|
||||
|
||||
public enum SignalStatus
|
||||
{
|
||||
WaitingForPosition,
|
||||
|
||||
@@ -170,7 +170,7 @@ public class PostgreSqlBotRepository : IBotRepository
|
||||
string? name = null,
|
||||
string? ticker = null,
|
||||
string? agentName = null,
|
||||
string sortBy = "CreateDate",
|
||||
BotSortableColumn sortBy = BotSortableColumn.CreateDate,
|
||||
string sortDirection = "Desc")
|
||||
{
|
||||
// Build the query with filters
|
||||
@@ -204,32 +204,35 @@ public class PostgreSqlBotRepository : IBotRepository
|
||||
var totalCount = await query.CountAsync().ConfigureAwait(false);
|
||||
|
||||
// Apply sorting
|
||||
query = sortBy.ToLower() switch
|
||||
query = sortBy switch
|
||||
{
|
||||
"name" => sortDirection.ToLower() == "asc"
|
||||
BotSortableColumn.Name => sortDirection.ToLower() == "asc"
|
||||
? query.OrderBy(b => b.Name)
|
||||
: query.OrderByDescending(b => b.Name),
|
||||
"ticker" => sortDirection.ToLower() == "asc"
|
||||
BotSortableColumn.Ticker => sortDirection.ToLower() == "asc"
|
||||
? query.OrderBy(b => b.Ticker)
|
||||
: query.OrderByDescending(b => b.Ticker),
|
||||
"status" => sortDirection.ToLower() == "asc"
|
||||
BotSortableColumn.Status => sortDirection.ToLower() == "asc"
|
||||
? query.OrderBy(b => b.Status)
|
||||
: query.OrderByDescending(b => b.Status),
|
||||
"startuptime" => sortDirection.ToLower() == "asc"
|
||||
BotSortableColumn.StartupTime => sortDirection.ToLower() == "asc"
|
||||
? query.OrderBy(b => b.StartupTime)
|
||||
: query.OrderByDescending(b => b.StartupTime),
|
||||
"pnl" => sortDirection.ToLower() == "asc"
|
||||
BotSortableColumn.Roi => sortDirection.ToLower() == "asc"
|
||||
? query.OrderBy(b => b.Roi)
|
||||
: query.OrderByDescending(b => b.Roi),
|
||||
BotSortableColumn.Pnl => sortDirection.ToLower() == "asc"
|
||||
? query.OrderBy(b => b.Pnl)
|
||||
: query.OrderByDescending(b => b.Pnl),
|
||||
"winrate" => sortDirection.ToLower() == "asc"
|
||||
BotSortableColumn.WinRate => sortDirection.ToLower() == "asc"
|
||||
? query.OrderBy(b => (b.TradeWins + b.TradeLosses) > 0 ? (double)b.TradeWins / (b.TradeWins + b.TradeLosses) : 0)
|
||||
: query.OrderByDescending(b => (b.TradeWins + b.TradeLosses) > 0 ? (double)b.TradeWins / (b.TradeWins + b.TradeLosses) : 0),
|
||||
"agentname" => sortDirection.ToLower() == "asc"
|
||||
BotSortableColumn.AgentName => sortDirection.ToLower() == "asc"
|
||||
? query.OrderBy(b => b.User.AgentName)
|
||||
: query.OrderByDescending(b => b.User.AgentName),
|
||||
_ => sortDirection.ToLower() == "asc"
|
||||
? query.OrderBy(b => b.CreateDate)
|
||||
: query.OrderByDescending(b => b.CreateDate) // Default to CreateDate
|
||||
: query.OrderByDescending(b => b.CreateDate)
|
||||
};
|
||||
|
||||
// Apply pagination
|
||||
|
||||
@@ -1534,7 +1534,7 @@ export class BotClient extends AuthorizedApiBase {
|
||||
return Promise.resolve<TradingBotResponse[]>(null as any);
|
||||
}
|
||||
|
||||
bot_GetBotsPaginated(pageNumber: number | undefined, pageSize: number | undefined, status: BotStatus | null | undefined, name: string | null | undefined, ticker: string | null | undefined, agentName: string | null | undefined, sortBy: string | null | undefined, sortDirection: string | null | undefined): Promise<PaginatedResponseOfTradingBotResponse> {
|
||||
bot_GetBotsPaginated(pageNumber: number | undefined, pageSize: number | undefined, status: BotStatus | null | undefined, name: string | null | undefined, ticker: string | null | undefined, agentName: string | null | undefined, sortBy: BotSortableColumn | undefined, sortDirection: string | null | undefined): Promise<PaginatedResponseOfTradingBotResponse> {
|
||||
let url_ = this.baseUrl + "/Bot/Paginated?";
|
||||
if (pageNumber === null)
|
||||
throw new Error("The parameter 'pageNumber' cannot be null.");
|
||||
@@ -1552,7 +1552,9 @@ export class BotClient extends AuthorizedApiBase {
|
||||
url_ += "ticker=" + encodeURIComponent("" + ticker) + "&";
|
||||
if (agentName !== undefined && agentName !== null)
|
||||
url_ += "agentName=" + encodeURIComponent("" + agentName) + "&";
|
||||
if (sortBy !== undefined && sortBy !== null)
|
||||
if (sortBy === null)
|
||||
throw new Error("The parameter 'sortBy' cannot be null.");
|
||||
else if (sortBy !== undefined)
|
||||
url_ += "sortBy=" + encodeURIComponent("" + sortBy) + "&";
|
||||
if (sortDirection !== undefined && sortDirection !== null)
|
||||
url_ += "sortDirection=" + encodeURIComponent("" + sortDirection) + "&";
|
||||
@@ -2179,55 +2181,6 @@ export class DataClient extends AuthorizedApiBase {
|
||||
return Promise.resolve<AgentBalanceHistory>(null as any);
|
||||
}
|
||||
|
||||
data_GetBestAgents(startDate: Date | undefined, endDate: Date | null | undefined, page: number | undefined, pageSize: number | undefined): Promise<BestAgentsResponse> {
|
||||
let url_ = this.baseUrl + "/Data/GetBestAgents?";
|
||||
if (startDate === null)
|
||||
throw new Error("The parameter 'startDate' cannot be null.");
|
||||
else if (startDate !== undefined)
|
||||
url_ += "startDate=" + encodeURIComponent(startDate ? "" + startDate.toISOString() : "") + "&";
|
||||
if (endDate !== undefined && endDate !== null)
|
||||
url_ += "endDate=" + encodeURIComponent(endDate ? "" + endDate.toISOString() : "") + "&";
|
||||
if (page === null)
|
||||
throw new Error("The parameter 'page' cannot be null.");
|
||||
else if (page !== undefined)
|
||||
url_ += "page=" + encodeURIComponent("" + page) + "&";
|
||||
if (pageSize === null)
|
||||
throw new Error("The parameter 'pageSize' cannot be null.");
|
||||
else if (pageSize !== undefined)
|
||||
url_ += "pageSize=" + encodeURIComponent("" + pageSize) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: RequestInit = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
return this.transformOptions(options_).then(transformedOptions_ => {
|
||||
return this.http.fetch(url_, transformedOptions_);
|
||||
}).then((_response: Response) => {
|
||||
return this.processData_GetBestAgents(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processData_GetBestAgents(response: Response): Promise<BestAgentsResponse> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result200: any = null;
|
||||
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as BestAgentsResponse;
|
||||
return result200;
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<BestAgentsResponse>(null as any);
|
||||
}
|
||||
|
||||
data_GetOnlineAgent(): Promise<string[]> {
|
||||
let url_ = this.baseUrl + "/Data/GetOnlineAgent";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
@@ -4288,6 +4241,17 @@ export interface PaginatedResponseOfTradingBotResponse {
|
||||
hasNextPage?: boolean;
|
||||
}
|
||||
|
||||
export enum BotSortableColumn {
|
||||
CreateDate = "CreateDate",
|
||||
Name = "Name",
|
||||
Ticker = "Ticker",
|
||||
Status = "Status",
|
||||
StartupTime = "StartupTime",
|
||||
Pnl = "Pnl",
|
||||
WinRate = "WinRate",
|
||||
AgentName = "AgentName",
|
||||
}
|
||||
|
||||
export interface OpenPositionManuallyRequest {
|
||||
identifier?: string;
|
||||
direction?: TradeDirection;
|
||||
@@ -4607,14 +4571,6 @@ export interface AgentBalance {
|
||||
time?: Date;
|
||||
}
|
||||
|
||||
export interface BestAgentsResponse {
|
||||
agents?: AgentBalanceHistory[] | null;
|
||||
totalCount?: number;
|
||||
currentPage?: number;
|
||||
pageSize?: number;
|
||||
totalPages?: number;
|
||||
}
|
||||
|
||||
export interface ScenarioViewModel {
|
||||
name: string;
|
||||
indicators: IndicatorViewModel[];
|
||||
|
||||
@@ -771,6 +771,17 @@ export interface PaginatedResponseOfTradingBotResponse {
|
||||
hasNextPage?: boolean;
|
||||
}
|
||||
|
||||
export enum BotSortableColumn {
|
||||
CreateDate = "CreateDate",
|
||||
Name = "Name",
|
||||
Ticker = "Ticker",
|
||||
Status = "Status",
|
||||
StartupTime = "StartupTime",
|
||||
Pnl = "Pnl",
|
||||
WinRate = "WinRate",
|
||||
AgentName = "AgentName",
|
||||
}
|
||||
|
||||
export interface OpenPositionManuallyRequest {
|
||||
identifier?: string;
|
||||
direction?: TradeDirection;
|
||||
@@ -1090,14 +1101,6 @@ export interface AgentBalance {
|
||||
time?: Date;
|
||||
}
|
||||
|
||||
export interface BestAgentsResponse {
|
||||
agents?: AgentBalanceHistory[] | null;
|
||||
totalCount?: number;
|
||||
currentPage?: number;
|
||||
pageSize?: number;
|
||||
totalPages?: number;
|
||||
}
|
||||
|
||||
export interface ScenarioViewModel {
|
||||
name: string;
|
||||
indicators: IndicatorViewModel[];
|
||||
|
||||
Reference in New Issue
Block a user