Phase 3c: Unkritische Call-Sites auf Repositories umgestellt
- MarketSyncService: markets-Zugriffe -> IMarketRepository (kein _db mehr). - PolymarketWssClient: demo_positions -> IPositionRepository, accounts -> IAccountRepository (closed_trades bleibt vorerst auf _db, ClosedTrade-Repo folgt in Phase 5). - Build 0 Fehler. Hot-Path (CopyTradingEngine, TraderMonitorService) und frm_main-UI bewusst noch NICHT migriert (Schritt B / Phase 5). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using MongoDB.Driver;
|
||||
using PolyTrader.Core.Persistence;
|
||||
using PolyTraderSharp.Extensions;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@@ -23,7 +24,9 @@ namespace PolyTraderSharp.Services
|
||||
private readonly PolymarketClobClient _clob;
|
||||
private readonly TerminalLogger _logger;
|
||||
private readonly IMongoDatabase _db;
|
||||
|
||||
private readonly IPositionRepository _positionRepo;
|
||||
private readonly IAccountRepository _accountRepo;
|
||||
|
||||
// Tracking rate limits for auto redeem: max 2 attempts per position, 5 min apart
|
||||
private readonly ConcurrentDictionary<string, (int Count, DateTime LastAttempt)> _redeemAttempts = new();
|
||||
|
||||
@@ -32,13 +35,17 @@ namespace PolyTraderSharp.Services
|
||||
ServerSettings settings,
|
||||
PolymarketClobClient clob,
|
||||
TerminalLogger logger,
|
||||
IMongoDatabase db)
|
||||
IMongoDatabase db,
|
||||
IPositionRepository positionRepo,
|
||||
IAccountRepository accountRepo)
|
||||
{
|
||||
_state = state;
|
||||
_settings = settings;
|
||||
_clob = clob;
|
||||
_logger = logger;
|
||||
_db = db;
|
||||
_positionRepo = positionRepo;
|
||||
_accountRepo = accountRepo;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
@@ -248,7 +255,7 @@ namespace PolyTraderSharp.Services
|
||||
{
|
||||
if (acc.OpenPositions.TryRemove(pos.TokenId, out _))
|
||||
{
|
||||
_db.GetCollection<Position>($"demo_positions_{acc.AccountId}").Delete(pos.TokenId);
|
||||
_positionRepo.DeleteDemo(acc.AccountId, pos.TokenId);
|
||||
|
||||
decimal exactLimitPrice = acc.PreRedeemLimit;
|
||||
decimal exitUsd = pos.Size * exactLimitPrice;
|
||||
@@ -278,7 +285,7 @@ namespace PolyTraderSharp.Services
|
||||
};
|
||||
|
||||
_db.GetCollection<ClosedTrade>("closed_trades").Insert(ct);
|
||||
_db.GetCollection<AccountState>("accounts").Upsert(acc);
|
||||
_accountRepo.Upsert(acc);
|
||||
|
||||
_logger.Trade($"✅ [AUTO REDEEM DEMO ERFOLGREICH] {pos.MarketQuestion} | Exit: {pos.Size:F2} @ {exactLimitPrice:F3} | PnL: ${realizedPnl:F2}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user