feat(engine): add FinlyticEngine microservice with trade lifecycle, AI reasoning gate, composite scoring, and unit tests
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FinlyticEngine.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialEngineMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "DynamicSettings",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Key = table.Column<string>(type: "character varying(150)", maxLength: 150, nullable: false),
|
||||
ValueJson = table.Column<string>(type: "text", nullable: false),
|
||||
ServiceIdentifier = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
LastUpdatedUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_DynamicSettings", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "engine_evaluation_snapshots",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Isin = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
||||
Symbol = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
|
||||
TechnicalScore = table.Column<decimal>(type: "numeric(6,2)", nullable: false),
|
||||
SentimentScore = table.Column<decimal>(type: "numeric(6,2)", nullable: false),
|
||||
FundamentalScore = table.Column<decimal>(type: "numeric(6,2)", nullable: false),
|
||||
CompositeOpportunityScore = table.Column<decimal>(type: "numeric(6,2)", nullable: false),
|
||||
PassedEarningsLockout = table.Column<bool>(type: "boolean", nullable: false),
|
||||
DaysToNextEarnings = table.Column<int>(type: "integer", nullable: true),
|
||||
PassedAiValidation = table.Column<bool>(type: "boolean", nullable: false),
|
||||
AiThesisSummary = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: false),
|
||||
EvaluatedAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_engine_evaluation_snapshots", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "engine_trade_proposals",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
UnderlyingIsin = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
||||
Symbol = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
|
||||
StrategyKey = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
Direction = table.Column<int>(type: "integer", nullable: false),
|
||||
QualityScore = table.Column<decimal>(type: "numeric(6,2)", nullable: false),
|
||||
CompositeScore = table.Column<decimal>(type: "numeric(6,2)", nullable: false),
|
||||
CurrentPrice = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
EntryPrice = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
StopLoss = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
TakeProfit1 = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
RiskRewardRatio = table.Column<decimal>(type: "numeric(8,2)", nullable: false),
|
||||
ExitPlan = table.Column<string>(type: "jsonb", nullable: false),
|
||||
SelectedDerivative = table.Column<string>(type: "jsonb", nullable: true),
|
||||
AiValidation = table.Column<string>(type: "jsonb", nullable: false),
|
||||
IsActive = table.Column<bool>(type: "boolean", nullable: false),
|
||||
CreatedAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
ExpiresAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_engine_trade_proposals", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "engine_trades",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
ProposalId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
UnderlyingIsin = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
||||
Symbol = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
|
||||
DerivativeIsin = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true),
|
||||
DerivativeWkn = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: true),
|
||||
ExecutionMode = table.Column<int>(type: "integer", nullable: false),
|
||||
InstrumentType = table.Column<int>(type: "integer", nullable: false),
|
||||
Direction = table.Column<int>(type: "integer", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
AverageBuyIn = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
TotalQuantity = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
InitialStopLoss = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
CurrentStopLoss = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
CurrentPrice = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
TakeProfit1 = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
TakeProfit2 = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
TakeProfitRunner = table.Column<decimal>(type: "numeric(18,4)", nullable: true),
|
||||
RealizedPnlEur = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
TotalFeesEur = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
ExitPlan = table.Column<string>(type: "jsonb", nullable: false),
|
||||
ScoreBreakdownJson = table.Column<string>(type: "text", nullable: false),
|
||||
OpenedAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
ClosedAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
LastUpdatedAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_engine_trades", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "engine_trade_fills",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
TradeId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
ExecutedAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
Price = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
Quantity = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
Fee = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
Note = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_engine_trade_fills", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_engine_trade_fills_engine_trades_TradeId",
|
||||
column: x => x.TradeId,
|
||||
principalTable: "engine_trades",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_DynamicSettings_Key",
|
||||
table: "DynamicSettings",
|
||||
column: "Key",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_engine_evaluation_snapshots_CompositeOpportunityScore",
|
||||
table: "engine_evaluation_snapshots",
|
||||
column: "CompositeOpportunityScore");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_engine_evaluation_snapshots_Isin_EvaluatedAtUtc",
|
||||
table: "engine_evaluation_snapshots",
|
||||
columns: new[] { "Isin", "EvaluatedAtUtc" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_engine_trade_fills_TradeId_ExecutedAtUtc",
|
||||
table: "engine_trade_fills",
|
||||
columns: new[] { "TradeId", "ExecutedAtUtc" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_engine_trade_proposals_CompositeScore",
|
||||
table: "engine_trade_proposals",
|
||||
column: "CompositeScore");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_engine_trade_proposals_CreatedAtUtc",
|
||||
table: "engine_trade_proposals",
|
||||
column: "CreatedAtUtc");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_engine_trade_proposals_UnderlyingIsin_IsActive_ExpiresAtUtc",
|
||||
table: "engine_trade_proposals",
|
||||
columns: new[] { "UnderlyingIsin", "IsActive", "ExpiresAtUtc" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_engine_trades_OpenedAtUtc",
|
||||
table: "engine_trades",
|
||||
column: "OpenedAtUtc");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_engine_trades_Status_UnderlyingIsin",
|
||||
table: "engine_trades",
|
||||
columns: new[] { "Status", "UnderlyingIsin" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "DynamicSettings");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "engine_evaluation_snapshots");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "engine_trade_fills");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "engine_trade_proposals");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "engine_trades");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user