增加指标信号传送功能
This commit is contained in:
+47
@@ -1,4 +1,5 @@
|
||||
using MtApi5;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Reflection;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -305,6 +306,47 @@ app.MapGet("/history/deals", (string date_from, string date_to, string? symbol,
|
||||
return new { data = dealList, count = dealList.Count, format = "json" };
|
||||
});
|
||||
|
||||
app.MapGet("/gvar", (HttpContext context) =>
|
||||
{
|
||||
var mt = context.RequestServices.GetRequiredService<MtApi5Client>();
|
||||
var total = mt.GlobalVariablesTotal();
|
||||
var vars = new List<object>();
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
var name = mt.GlobalVariableName(i) ?? "";
|
||||
var value = mt.GlobalVariableGet(name);
|
||||
vars.Add(new { name, value });
|
||||
}
|
||||
return Results.Ok(new { data = vars, count = vars.Count, format = "json" });
|
||||
});
|
||||
|
||||
app.MapGet("/gvar/{name}", (HttpContext context, string name) =>
|
||||
{
|
||||
var mt = context.RequestServices.GetRequiredService<MtApi5Client>();
|
||||
if (!mt.GlobalVariableCheck(name))
|
||||
return Results.NotFound(new { detail = $"GlobalVariable '{name}' not found" });
|
||||
var value = mt.GlobalVariableGet(name);
|
||||
return Results.Ok(new { name, value });
|
||||
});
|
||||
|
||||
app.MapPost("/gvar/{name}", async (HttpContext context, string name) =>
|
||||
{
|
||||
var mt = context.RequestServices.GetRequiredService<MtApi5Client>();
|
||||
var body = await context.Request.ReadFromJsonAsync<GvarSetDto>();
|
||||
if (body == null) return Results.BadRequest("Invalid body");
|
||||
mt.GlobalVariableSet(name, body.value);
|
||||
return Results.Ok(new { name, value = body.value });
|
||||
});
|
||||
|
||||
app.MapDelete("/gvar/{name}", (HttpContext context, string name) =>
|
||||
{
|
||||
var mt = context.RequestServices.GetRequiredService<MtApi5Client>();
|
||||
if (!mt.GlobalVariableCheck(name))
|
||||
return Results.NotFound(new { detail = $"GlobalVariable '{name}' not found" });
|
||||
mt.GlobalVariableDel(name);
|
||||
return Results.Ok(new { deleted = name });
|
||||
});
|
||||
|
||||
app.Run();
|
||||
|
||||
DateTime MtTimeToDateTime(long mtTime)
|
||||
@@ -352,6 +394,11 @@ class TradeRequestBody
|
||||
public TradeRequestDto request { get; set; } = new();
|
||||
}
|
||||
|
||||
class GvarSetDto
|
||||
{
|
||||
public double value { get; set; }
|
||||
}
|
||||
|
||||
class MtConnectionService : BackgroundService
|
||||
{
|
||||
private readonly MtApi5Client _client;
|
||||
|
||||
Reference in New Issue
Block a user