Sviluppo TradingBot
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Alpaca.Markets;
|
||||
using DesktopBot.Models;
|
||||
|
||||
namespace DesktopBot.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Interfaccia per il servizio di trading - permette disaccoppiamento e testing
|
||||
/// </summary>
|
||||
public interface ITradingService
|
||||
{
|
||||
/// <summary>
|
||||
/// Inizializza il client di trading con le credenziali API
|
||||
/// </summary>
|
||||
/// <param name="apiKey">Chiave API Alpaca</param>
|
||||
/// <param name="apiSecret">Secret API Alpaca</param>
|
||||
/// <param name="isPaper">True per Paper Trading, False per Live</param>
|
||||
void Initialize(string apiKey, string apiSecret, bool isPaper);
|
||||
|
||||
/// <summary>
|
||||
/// Recupera il saldo disponibile del conto
|
||||
/// </summary>
|
||||
Task<decimal> GetAvailableEquityAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Recupera le informazioni complete del conto (saldo, P&L, buying power, ecc.)
|
||||
/// </summary>
|
||||
Task<IAccount> GetAccountAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Recupera le barre storiche (candele) per un simbolo
|
||||
/// </summary>
|
||||
/// <param name="symbol">Simbolo ticker (es. "AAPL")</param>
|
||||
/// <param name="timeframe">Timeframe delle candele</param>
|
||||
/// <param name="barCount">Numero di barre da recuperare (convertito in intervallo temporale appropriato)</param>
|
||||
Task<List<IBar>> GetHistoricalBarsAsync(string symbol, BarTimeFrame timeframe, int barCount);
|
||||
|
||||
/// <summary>
|
||||
/// Piazza un ordine bracket (con Take Profit e Stop Loss automatici).
|
||||
/// NON supportato per crypto su Alpaca: usare PlaceMarketOrderAsync + SL/TP separati.
|
||||
/// </summary>
|
||||
Task<IOrder> PlaceBracketOrderAsync(string symbol, decimal quantity, decimal entryPrice,
|
||||
decimal takeProfitPrice, decimal stopLossPrice, OrderSide side);
|
||||
|
||||
/// <summary>
|
||||
/// Piazza un ordine market semplice (buy o sell). Usare per crypto.
|
||||
/// </summary>
|
||||
Task<IOrder> PlaceMarketOrderAsync(string symbol, decimal quantity, OrderSide side);
|
||||
|
||||
/// <summary>
|
||||
/// Piazza un ordine stop-loss separato su una posizione aperta (per crypto).
|
||||
/// </summary>
|
||||
Task<IOrder> PlaceStopOrderAsync(string symbol, decimal quantity, decimal stopPrice, OrderSide side);
|
||||
|
||||
/// <summary>
|
||||
/// Piazza un ordine limit (take-profit) separato su una posizione aperta (per crypto).
|
||||
/// </summary>
|
||||
Task<IOrder> PlaceLimitOrderAsync(string symbol, decimal quantity, decimal limitPrice, OrderSide side);
|
||||
|
||||
/// <summary>
|
||||
/// Verifica se esiste una posizione aperta per un simbolo
|
||||
/// </summary>
|
||||
Task<bool> HasOpenPositionAsync(string symbol);
|
||||
|
||||
/// <summary>
|
||||
/// Recupera tutte le posizioni aperte
|
||||
/// </summary>
|
||||
Task<IReadOnlyList<IPosition>> GetAllPositionsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Recupera la posizione aperta per un simbolo specifico.
|
||||
/// Ritorna null se non esiste nessuna posizione aperta per quel simbolo.
|
||||
/// </summary>
|
||||
Task<IPosition> GetPositionAsync(string symbol);
|
||||
|
||||
/// <summary>
|
||||
/// Recupera l'ultimo prezzo di un simbolo
|
||||
/// </summary>
|
||||
Task<decimal> GetLatestPriceAsync(string symbol);
|
||||
|
||||
/// <summary>
|
||||
/// Chiude tutte le posizioni aperte
|
||||
/// </summary>
|
||||
Task CloseAllPositionsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Recupera gli ordini (aperti, chiusi o tutti)
|
||||
/// </summary>
|
||||
/// <param name="statusFilter">Filtro stato: Open, Closed, All</param>
|
||||
/// <param name="limit">Numero massimo di ordini da recuperare</param>
|
||||
Task<IReadOnlyList<IOrder>> GetOrdersAsync(OrderStatusFilter statusFilter = OrderStatusFilter.Open, int limit = 50);
|
||||
|
||||
/// <summary>
|
||||
/// Cancella un ordine specifico per ID
|
||||
/// </summary>
|
||||
Task CancelOrderAsync(Guid orderId);
|
||||
|
||||
/// <summary>
|
||||
/// Chiude una singola posizione aperta per simbolo
|
||||
/// </summary>
|
||||
Task ClosePositionAsync(string symbol);
|
||||
|
||||
/// <summary>
|
||||
/// Recupera solo le posizioni aperte originate da ordini del bot
|
||||
/// (riconosce gli ordini del bot tramite il prefisso BOT_ nel ClientOrderId).
|
||||
/// Ritorna un sottoinsieme di GetAllPositionsAsync filtrato sui simboli
|
||||
/// per cui esiste almeno un ordine buy filled con ClientOrderId che inizia per "BOT_".
|
||||
/// </summary>
|
||||
Task<IReadOnlyList<IPosition>> GetBotPositionsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Cerca asset disponibili su Alpaca per simbolo o nome.
|
||||
/// Ritorna al massimo <paramref name="maxResults"/> risultati tradabili.
|
||||
/// </summary>
|
||||
Task<List<AssetSearchResult>> SearchAssetsAsync(string query, int maxResults = 20);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user