-
Notifications
You must be signed in to change notification settings - Fork 9
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
8d7d030
commit b447e73
Showing
47 changed files
with
777 additions
and
748 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
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 "/coins" | ||
|
||
<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,166 @@ | ||
using Alpaca; | ||
using Canvas.Core.Models; | ||
using Canvas.Core.Shapes; | ||
using Client.Components; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.Extensions.Configuration; | ||
using SkiaSharp; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Terminal.Core.Domains; | ||
using Terminal.Core.Enums; | ||
using Terminal.Core.Indicators; | ||
using Terminal.Core.Models; | ||
|
||
namespace Client.Pages | ||
{ | ||
public partial class Coins | ||
{ | ||
[Inject] IConfiguration Configuration { get; set; } | ||
|
||
/// <summary> | ||
/// Strategy | ||
/// </summary> | ||
const string _asset = "BTCUSD"; | ||
|
||
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) | ||
{ | ||
var indUp = new ComponentModel { Color = SKColors.DeepSkyBlue }; | ||
var indDown = new ComponentModel { Color = SKColors.OrangeRed }; | ||
var indAreas = new GroupShape(); | ||
var indCharts = new GroupShape(); | ||
|
||
indCharts.Groups["Range"] = new AreaShape { Component = indUp }; | ||
indAreas.Groups["Prices"] = indCharts; | ||
|
||
await View.ChartsView.Create(indAreas); | ||
|
||
var pnlGain = new ComponentModel { Color = SKColors.OrangeRed, Size = 5 }; | ||
var pnlBalance = new ComponentModel { Color = SKColors.Black }; | ||
var pnlAreas = new GroupShape(); | ||
var pnlCharts = new GroupShape(); | ||
|
||
pnlCharts.Groups["PnL"] = new LineShape { Component = pnlGain }; | ||
pnlCharts.Groups["Balance"] = new AreaShape { Component = pnlBalance }; | ||
pnlAreas.Groups["Performance"] = pnlCharts; | ||
|
||
await View.ReportsView.Create(pnlAreas); | ||
|
||
View.Setup = () => | ||
{ | ||
Account = new Account | ||
{ | ||
Name = "Demo", | ||
Balance = 25000, | ||
Instruments = new Dictionary<string, Instrument> | ||
{ | ||
[_asset] = new Instrument { Name = _asset }, | ||
} | ||
}; | ||
|
||
// organizations/65659d9f-81c5-4b3b-ad84-fbca8aad60c5/apiKeys/af337ce4-9b36-49c8-8c5c-63858f111dfa | ||
// -----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIEnZS9VkznxoLHnHO+gJ8ht/pxLhybl4E+XXhSfgrxF5oAoGCCqGSM49\nAwEHoUQDQgAEO2jBy6XKCG4ksmyCnijcxSxTOrX5nRXGHl/Jg9ThtU+wDomO5+0I\nCbWemshTjfO9NfHnaFm3cHrXpY2WilxW+g==\n-----END EC PRIVATE KEY-----\n | ||
|
||
// 6mb099rhmbg | ||
// 35793761dc5d2cfb20e233a119d6a214 | ||
// XeMjlgaDDSO401h9f4u7C9XbvTwx8s+YS4pUkxi8N1JPYQL/VE1sDjD4Ew3oDgH3qIeYDb2rWqn/VVfMidk0jQ== | ||
View.Adapter = new Adapter | ||
{ | ||
Account = Account, | ||
//ConsumerKey = "35793761dc5d2cfb20e233a119d6a214", | ||
//ConsumerSecret = "XeMjlgaDDSO401h9f4u7C9XbvTwx8s+YS4pUkxi8N1JPYQL/VE1sDjD4Ew3oDgH3qIeYDb2rWqn/VVfMidk0jQ==", | ||
ConsumerKey = "account-ANUzTVQTkYcHyk7wo3QI", | ||
ConsumerSecret = "4VgrY182eCM6m6pv1jVqWpPsXNwj", | ||
DataUri = "https://api.sandbox.gemini.com" | ||
//Source = "https://api-public.sandbox.exchange.coinbase.com", | ||
//StreamSource = "wss://ws-feed-public.sandbox.exchange.coinbase.com" | ||
}; | ||
|
||
Performance = new PerformanceIndicator { Name = "Balance" }; | ||
|
||
Account | ||
.Instruments | ||
.Values | ||
.ForEach(o => o.Points.CollectionChanged += (_, e) => e | ||
.NewItems | ||
.OfType<PointModel>() | ||
.ForEach(o => { })); | ||
}; | ||
} | ||
|
||
await base.OnAfterRenderAsync(setup); | ||
} | ||
|
||
private (string, string) OpenPositions(IInstrument assetBuy, IInstrument assetSell) | ||
{ | ||
var orderSell = new OrderModel | ||
{ | ||
Side = OrderSideEnum.Sell, | ||
Type = OrderTypeEnum.Market, | ||
Transaction = new() | ||
{ | ||
Volume = 1, | ||
Instrument = assetSell | ||
} | ||
}; | ||
|
||
var orderBuy = new OrderModel | ||
{ | ||
Side = OrderSideEnum.Buy, | ||
Type = OrderTypeEnum.Market, | ||
Transaction = new() | ||
{ | ||
Volume = 1, | ||
Instrument = assetBuy | ||
} | ||
}; | ||
|
||
View.Adapter.CreateOrders(orderBuy); | ||
View.Adapter.CreateOrders(orderSell); | ||
|
||
var account = View.Adapter.Account; | ||
var buy = account.ActivePositions.Values.First(o => o.Order.Side == OrderSideEnum.Buy); | ||
var sell = account.ActivePositions.Values.First(o => o.Order.Side == OrderSideEnum.Sell); | ||
|
||
//points.Add(new PointModel { Time = buy.Time, Name = nameof(OrderSideEnum.Buy), Last = buy.OpenPrices.Last().Price }); | ||
//points.Add(new PointModel { Time = sell.Time, Name = nameof(OrderSideEnum.Sell), Last = sell.OpenPrices.Last().Price }); | ||
|
||
return (orderSell.Transaction.Id, orderBuy.Transaction.Id); | ||
} | ||
|
||
private void ClosePositions() | ||
{ | ||
foreach (var position in View.Adapter.Account.ActivePositions.Values) | ||
{ | ||
var side = OrderSideEnum.Buy; | ||
|
||
if (Equals(position.Order.Side, OrderSideEnum.Buy)) | ||
{ | ||
side = OrderSideEnum.Sell; | ||
} | ||
|
||
var order = new OrderModel | ||
{ | ||
Side = side, | ||
Type = OrderTypeEnum.Market, | ||
Transaction = new() | ||
{ | ||
Volume = position.Order.Transaction.Volume, | ||
Instrument = position.Order.Transaction.Instrument | ||
} | ||
}; | ||
|
||
View.Adapter.CreateOrders(order); | ||
|
||
//points.Add(new PointModel { Time = order.Time, Name = nameof(OrderSideEnum.Buy), Last = price }); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.