-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acaac27
commit 2914bc3
Showing
13 changed files
with
110 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@page "/recorder" | ||
|
||
<PageComponent @ref="View"></PageComponent> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, InstrumentModel> | ||
{ | ||
["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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters