diff --git a/.editorconfig b/.editorconfig index 2ce46714a..9cdbe97ac 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,4 +13,4 @@ indent_size = 2 [*.cs] dotnet_diagnostic.CA2227.severity = none dotnet_diagnostic.CA1305.severity = none -dotnet_diagnostic.CA1062.severity = none \ No newline at end of file +dotnet_diagnostic.CA1062.severity = none diff --git a/Client/Client.csproj b/Client/Client.csproj index e0ffc2167..4d4c7b398 100644 --- a/Client/Client.csproj +++ b/Client/Client.csproj @@ -7,9 +7,9 @@ - + - + diff --git a/Client/Pages/Recorder.razor b/Client/Pages/Recorder.razor new file mode 100644 index 000000000..8556adbb0 --- /dev/null +++ b/Client/Pages/Recorder.razor @@ -0,0 +1,3 @@ +@page "/recorder" + + diff --git a/Client/Pages/Recorder.razor.cs b/Client/Pages/Recorder.razor.cs new file mode 100644 index 000000000..38715aac7 --- /dev/null +++ b/Client/Pages/Recorder.razor.cs @@ -0,0 +1,88 @@ +using Client.Components; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Configuration; +using Schwab; +using Schwab.Messages; +using System; +using System.Collections.Generic; +using System.IO.Compression; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; +using System.Timers; +using Terminal.Core.Domains; +using Terminal.Core.Indicators; +using Terminal.Core.Models; + +namespace Client.Pages +{ + public partial class Recorder + { + [Inject] IConfiguration Configuration { get; set; } + + protected virtual IAccount Account { get; set; } + protected virtual PageComponent View { get; set; } + protected virtual PerformanceIndicator Performance { get; set; } + + protected override async Task OnAfterRenderAsync(bool setup) + { + if (setup) + { + View.OnPreConnect = CreateAccounts; + View.OnPostConnect = async () => await OnData(); + } + + await base.OnAfterRenderAsync(setup); + } + + protected virtual void CreateAccounts() + { + Account = new Account + { + Descriptor = Configuration["Schwab:Account"], + Instruments = new Dictionary + { + ["SPY"] = new InstrumentModel { Name = "SPY" } + } + }; + + View.Adapter = new Adapter + { + Account = Account, + Scope = new ScopeMessage + { + AccessToken = Configuration["Schwab:AccessToken"], + RefreshToken = Configuration["Schwab:RefreshToken"], + ConsumerKey = Configuration["Schwab:ConsumerKey"], + ConsumerSecret = Configuration["Schwab:ConsumerSecret"], + } + }; + + var aTimer = new Timer(); + aTimer.Elapsed += async (o, e) => await OnData(); + aTimer.Interval = 5000; + aTimer.Enabled = true; + } + + private async Task OnData() + { + var args = new OptionsArgs + { + Name = "SPY", + MinDate = DateTime.Now, + MaxDate = DateTime.Now.AddYears(1) + }; + + var options = await View.Adapter.GetOptions(args, []); + var content = JsonSerializer.Serialize(options); + var source = $"D:/Code/NET/Terminal/Data/SPY/{DateTime.UtcNow.Ticks}.zip"; + + using var archive = ZipFile.Open(source, ZipArchiveMode.Create); + using (var entry = archive.CreateEntry($"{DateTime.UtcNow.Ticks}").Open()) + { + var bytes = Encoding.ASCII.GetBytes(content); + entry.Write(bytes); + } + } + } +} diff --git a/Client/Themes/DashboardTheme.cs b/Client/Themes/DashboardTheme.cs index feb77bea3..f4c1836b2 100644 --- a/Client/Themes/DashboardTheme.cs +++ b/Client/Themes/DashboardTheme.cs @@ -6,7 +6,6 @@ public class DashboardTheme : MudTheme { public DashboardTheme() { - Palette = new PaletteDark(); LayoutProperties = new LayoutProperties() { DefaultBorderRadius = "5px", @@ -16,95 +15,7 @@ public DashboardTheme() { Default = new Default() { - FontFamily = new[] { "Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif" }, - FontSize = "1rem", - FontWeight = 300, - LineHeight = 1.5, - LetterSpacing = "normal" - }, - H1 = new H1() - { - FontFamily = new[] { "Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif" }, - FontSize = "5rem", - FontWeight = 300, - LineHeight = 1.5, - LetterSpacing = "normal" - }, - H2 = new H2() - { - FontFamily = new[] { "Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif" }, - FontSize = "3.75rem", - FontWeight = 300, - LineHeight = 1.5, - LetterSpacing = "normal" - }, - H3 = new H3() - { - FontFamily = new[] {"Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif" }, - FontSize = "3rem", - FontWeight = 500, - LineHeight = 1.5, - LetterSpacing = "normal" - }, - H4 = new H4() - { - FontFamily = new[] {"Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif" }, - FontSize = "2.15rem", - FontWeight = 500, - LineHeight = 1.5, - LetterSpacing = "normal" - }, - H5 = new H5() - { - FontFamily = new[] {"Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif" }, - FontSize = "1.5rem", - FontWeight = 500, - LineHeight = 1.5, - LetterSpacing = "normal" - }, - H6 = new H6() - { - FontFamily = new[] {"Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif" }, - FontSize = "1.25rem", - FontWeight = 500, - LineHeight = 1.5, - LetterSpacing = "normal" - }, - Button = new Button() - { - FontFamily = new[] {"Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif" }, - FontSize = "1rem", - FontWeight = 300, - LineHeight = 1.5, - LetterSpacing = "normal" - }, - Body1 = new Body1() - { - FontFamily = new[] {"Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif" }, - FontSize = "1rem", - FontWeight = 300, - LineHeight = 1.5, - LetterSpacing = "normal" - }, - Body2 = new Body2() - { - FontFamily = new[] {"Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif" }, - FontSize = "0.75rem", - FontWeight = 300, - LineHeight = 1.5, - LetterSpacing = "normal" - }, - Caption = new Caption() - { - FontFamily = new[] { "Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif" }, - FontSize = "1rem", - FontWeight = 300, - LineHeight = 1.5, - LetterSpacing = "normal" - }, - Subtitle2 = new Subtitle2() - { - FontFamily = new[] { "Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif" }, + FontFamily = ["Segoe UI", "SegoeUI", "Montserrat", "Helvetica Neue", "Helvetica", "Arial", "sans-serif"], FontSize = "1rem", FontWeight = 300, LineHeight = 1.5, diff --git a/Core/Extensions/Hashtable.cs b/Core/Extensions/Hashtable.cs index 92a317aaf..c148372d1 100644 --- a/Core/Extensions/Hashtable.cs +++ b/Core/Extensions/Hashtable.cs @@ -15,6 +15,11 @@ public static NameValueCollection Merge(this Hashtable source, params Hashtable[ { var response = HttpUtility.ParseQueryString(string.Empty); + foreach (DictionaryEntry o in source ?? []) + { + response[$"{o.Key}"] = $"{o.Value}"; + } + foreach (Hashtable map in maps ?? []) { foreach (DictionaryEntry o in map ?? []) diff --git a/Gateways/Alpaca/Libs/Alpaca.csproj b/Gateways/Alpaca/Libs/Alpaca.csproj index 57febf853..d5c79d84e 100644 --- a/Gateways/Alpaca/Libs/Alpaca.csproj +++ b/Gateways/Alpaca/Libs/Alpaca.csproj @@ -7,7 +7,7 @@ - + diff --git a/Gateways/Coinbase/Libs/Coinbase.csproj b/Gateways/Coinbase/Libs/Coinbase.csproj index 8e67ff6e4..a7bf154c7 100644 --- a/Gateways/Coinbase/Libs/Coinbase.csproj +++ b/Gateways/Coinbase/Libs/Coinbase.csproj @@ -7,9 +7,9 @@ - + - + diff --git a/Gateways/InteractiveBrokers/Libs/Adapter.cs b/Gateways/InteractiveBrokers/Libs/Adapter.cs index eb56a3bb8..e54c4bb3e 100644 --- a/Gateways/InteractiveBrokers/Libs/Adapter.cs +++ b/Gateways/InteractiveBrokers/Libs/Adapter.cs @@ -144,7 +144,6 @@ public override Task> Unsubscribe(InstrumentModel instrument) if (_subscriptions.TryGetValue(instrument.Name, out var id)) { _client?.ClientSocket?.cancelTickByTickData(id); - _subscriptions.Remove(instrument.Name); } } diff --git a/Gateways/InteractiveBrokers/Libs/InteractiveBrokers.csproj b/Gateways/InteractiveBrokers/Libs/InteractiveBrokers.csproj index 57febf853..d5c79d84e 100644 --- a/Gateways/InteractiveBrokers/Libs/InteractiveBrokers.csproj +++ b/Gateways/InteractiveBrokers/Libs/InteractiveBrokers.csproj @@ -7,7 +7,7 @@ - + diff --git a/Gateways/Schwab/Libs/Adapter.cs b/Gateways/Schwab/Libs/Adapter.cs index fd8777e80..6f0c98908 100644 --- a/Gateways/Schwab/Libs/Adapter.cs +++ b/Gateways/Schwab/Libs/Adapter.cs @@ -171,8 +171,8 @@ public override async Task>> GetOptions(Options var props = new Hashtable { ["symbol"] = args.Name, - ["fromDate"] = args.MinDate, - ["toDate"] = args.MaxDate + ["fromDate"] = $"{args.MinDate:yyyy-MM-dd}", + ["toDate"] = $"{args.MaxDate:yyyy-MM-dd}" }.Merge(criteria); @@ -493,7 +493,7 @@ protected virtual async Task> CreateOrder(OrderModel o if (exResponse.Message.Headers.TryGetValues("Location", out var orderData)) { var orderItem = orderData.First(); - var orderId = $"{orderItem.Substring(orderItem.LastIndexOf('/') + 1)}"; + var orderId = $"{orderItem[(orderItem.LastIndexOf('/') + 1)..]}"; if (string.IsNullOrEmpty(orderId)) { diff --git a/Gateways/Schwab/Libs/Schwab.csproj b/Gateways/Schwab/Libs/Schwab.csproj index bf2e4de47..e42f1553e 100644 --- a/Gateways/Schwab/Libs/Schwab.csproj +++ b/Gateways/Schwab/Libs/Schwab.csproj @@ -17,7 +17,7 @@ - + diff --git a/Gateways/Simulation/Tests/Tests.csproj b/Gateways/Simulation/Tests/Tests.csproj index 3ae1ed95c..45d7996ef 100644 --- a/Gateways/Simulation/Tests/Tests.csproj +++ b/Gateways/Simulation/Tests/Tests.csproj @@ -10,8 +10,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all