using System.Text.Json.Serialization; namespace IBKRTrader.Core.IBKR; // ─── DB Entities ───────────────────────────────────────────────────────────── /// /// Repräsentiert ein IBKR-Instrument in core_ibkr_instruments. /// ibkr_conid ist der zentrale, eindeutige IBKR-Schlüssel. /// public class IBKRInstrument { public long Id { get; set; } public long IbkrConid { get; set; } public string Symbol { get; set; } = ""; public string SecType { get; set; } = "STK"; public string Exchange { get; set; } = "SMART"; public string? PrimaryExchange { get; set; } public string Currency { get; set; } = "USD"; public string? CompanyName { get; set; } public string? Isin { get; set; } public string? Sector { get; set; } public string? Industry { get; set; } public string? Description { get; set; } public bool Active { get; set; } = true; public DateTime? LastFetched { get; set; } public DateTime CreatedAt { get; set; } public DateTime UpdatedAt { get; set; } } /// /// Repräsentiert einen OHLCV-Balken in core_ibkr_market_data. /// public class IBKRMarketBar { public long InstrumentId { get; set; } public string BarSize { get; set; } = "daily"; public DateTime Timestamp { get; set; } public decimal Open { get; set; } public decimal High { get; set; } public decimal Low { get; set; } public decimal Close { get; set; } public long Volume { get; set; } public decimal? Wap { get; set; } public int? BarCount { get; set; } } /// /// Externes Ticker-Mapping in core_ibkr_external_identifiers. /// public class IBKRExternalIdentifier { public long Id { get; set; } public long InstrumentId { get; set; } public string Source { get; set; } = ""; public string Ticker { get; set; } = ""; } // ─── API Response DTOs ─────────────────────────────────────────────────────── /// /// Response von GET /iserver/auth/status /// public class IBKRAuthStatus { [JsonPropertyName("authenticated")] public bool Authenticated { get; set; } [JsonPropertyName("competing")] public bool Competing { get; set; } [JsonPropertyName("connected")] public bool Connected { get; set; } [JsonPropertyName("message")] public string? Message { get; set; } [JsonPropertyName("fail")] public string? Fail { get; set; } } /// /// Einzelnes Ergebnis der Contract-Suche (POST /iserver/secdef/search). /// public class IBKRContractSearchResult { [JsonPropertyName("conid")] public long ConId { get; set; } [JsonPropertyName("companyHeader")] public string? CompanyHeader { get; set; } [JsonPropertyName("companyName")] public string? CompanyName { get; set; } [JsonPropertyName("symbol")] public string? Symbol { get; set; } [JsonPropertyName("description")] public string? Description { get; set; } [JsonPropertyName("restricted")] public string? Restricted { get; set; } [JsonPropertyName("fop")] public string? Fop { get; set; } [JsonPropertyName("opt")] public string? Opt { get; set; } [JsonPropertyName("war")] public string? War { get; set; } [JsonPropertyName("sections")] public List? Sections { get; set; } } /// /// Sections innerhalb eines Contract-Suchergebnisses. /// public class IBKRContractSection { [JsonPropertyName("secType")] public string? SecType { get; set; } [JsonPropertyName("months")] public string? Months { get; set; } [JsonPropertyName("symbol")] public string? Symbol { get; set; } [JsonPropertyName("exchange")] public string? Exchange { get; set; } [JsonPropertyName("legStr")] public string? LegStr { get; set; } } /// /// Response von GET /iserver/contract/{conid}/info /// public class IBKRContractInfo { [JsonPropertyName("cfi_code")] public string? CfiCode { get; set; } [JsonPropertyName("symbol")] public string? Symbol { get; set; } [JsonPropertyName("cusip")] public string? Cusip { get; set; } [JsonPropertyName("expiry_full")] public string? ExpiryFull { get; set; } [JsonPropertyName("con_id")] public long ConId { get; set; } [JsonPropertyName("maturity_date")] public string? MaturityDate { get; set; } [JsonPropertyName("industry")] public string? Industry { get; set; } [JsonPropertyName("instrument_type")] public string? InstrumentType { get; set; } [JsonPropertyName("trading_class")] public string? TradingClass { get; set; } [JsonPropertyName("valid_exchanges")] public string? ValidExchanges { get; set; } [JsonPropertyName("allow_sell_long")] public bool? AllowSellLong { get; set; } [JsonPropertyName("is_zero_commission_security")] public bool? IsZeroCommissionSecurity { get; set; } [JsonPropertyName("local_symbol")] public string? LocalSymbol { get; set; } [JsonPropertyName("classifier")] public string? Classifier { get; set; } [JsonPropertyName("currency")] public string? Currency { get; set; } [JsonPropertyName("text")] public string? Text { get; set; } [JsonPropertyName("underlying_con_id")] public long? UnderlyingConId { get; set; } [JsonPropertyName("r_t_h")] public bool? Rth { get; set; } [JsonPropertyName("company_name")] public string? CompanyName { get; set; } [JsonPropertyName("smart_available")] public bool? SmartAvailable { get; set; } [JsonPropertyName("exchange")] public string? Exchange { get; set; } [JsonPropertyName("listing_exchange")] public string? ListingExchange { get; set; } [JsonPropertyName("category")] public string? Category { get; set; } [JsonPropertyName("sector")] public string? Sector { get; set; } } /// /// Response von GET /iserver/marketdata/history /// public class IBKRHistoricalDataResponse { [JsonPropertyName("symbol")] public string? Symbol { get; set; } [JsonPropertyName("text")] public string? Text { get; set; } [JsonPropertyName("priceFactor")] public int? PriceFactor { get; set; } [JsonPropertyName("startTime")] public string? StartTime { get; set; } [JsonPropertyName("high")] public string? High { get; set; } [JsonPropertyName("low")] public string? Low { get; set; } [JsonPropertyName("timePeriod")] public string? TimePeriod { get; set; } [JsonPropertyName("barLength")] public int? BarLength { get; set; } [JsonPropertyName("mdAvailability")] public string? MdAvailability { get; set; } [JsonPropertyName("mktDataDelay")] public int? MktDataDelay { get; set; } [JsonPropertyName("outsideRth")] public bool? OutsideRth { get; set; } [JsonPropertyName("tradingDayDuration")] public int? TradingDayDuration { get; set; } [JsonPropertyName("volumeFactor")] public int? VolumeFactor { get; set; } [JsonPropertyName("priceDisplayRule")] public int? PriceDisplayRule { get; set; } [JsonPropertyName("priceDisplayValue")] public string? PriceDisplayValue { get; set; } [JsonPropertyName("negativeCapable")] public bool? NegativeCapable { get; set; } [JsonPropertyName("messageVersion")] public int? MessageVersion { get; set; } [JsonPropertyName("data")] public List? Data { get; set; } [JsonPropertyName("points")] public int? Points { get; set; } [JsonPropertyName("travelTime")] public int? TravelTime { get; set; } } /// /// Einzelner OHLCV-Balken aus der IBKR Historical Data Response. /// public class IBKRHistoricalBar { [JsonPropertyName("o")] public decimal Open { get; set; } [JsonPropertyName("c")] public decimal Close { get; set; } [JsonPropertyName("h")] public decimal High { get; set; } [JsonPropertyName("l")] public decimal Low { get; set; } [JsonPropertyName("v")] public long Volume { get; set; } [JsonPropertyName("t")] public long Timestamp { get; set; } // Unix timestamp in ms } /// /// Response von GET /trsrv/stocks?symbols=... /// Die API gibt ein Dictionary zurück: { "AAPL": [{ ... }] } /// public class IBKRStockContract { [JsonPropertyName("name")] public string? Name { get; set; } [JsonPropertyName("chineseName")] public string? ChineseName { get; set; } [JsonPropertyName("assetClass")] public string? AssetClass { get; set; } [JsonPropertyName("contracts")] public List? Contracts { get; set; } } public class IBKRStockContractEntry { [JsonPropertyName("conid")] public long ConId { get; set; } [JsonPropertyName("exchange")] public string? Exchange { get; set; } [JsonPropertyName("isUS")] public bool? IsUS { get; set; } }