Home

Awesome

An initiative of Ouinex Exchange and BizUnity

StockPlot

A Technical analysis library for AvaloniaUI, based on ScottPlot DataVisualization Library (v 4.1.63).

StockPlot (will) allow you to have a full Stock Market Analysis module in your application only by using a single UserControl and a single class.

StockPlot are in a very early stage (started in April 2023). A lot of features need to be created before deploying a proper and working Nuget Package. Some refactoring may need to be done a couple of time, **do not use it in a production yet. ** Play around, do not hesitate to contribute <3 .

Current features

Features planned

How to use

  1. From you IDE, add the reference to StockPlot.Charts. This library contains all the controls and logics.

  2. In your Window or UserControl add the reference to StockPlot.Charts : xmlns:stockPlot="using:StockPlot.Charts.Controls"

  3. Add the StockChart control in your axaml code :

<stockPlot:StockChart CandleDownColor="OrangeRed"
                      CandleWickColor="Black"
		      CandleUpColor="#07BF7D"
		      DisplayPrice="Candlestick"
		      ResetAxisOnDoubleClick="True"
		      Name="StockChart"/>
  1. In your C# code, find the StockChart control :
StockChart _chart = this.Find<StockChart>("StockChart");
  1. Create a new StockPricesModel and provide the StockChart control with it :
var model = new StockPricesModel();
_chart.PricesModel = model;
  1. FullFill the model with datas. For this exemple we will use Binance API using Binance.NET library. With this exemple, price is working in live using WebSocket.
    var client = new BinanceClient();

    var request = await client.SpotApi.ExchangeData.GetUiKlinesAsync("BTCUSDT", Binance.Net.Enums.KlineInterval.OneMinute, limit: 500);

    if (request.Success)
    {
        var bars = request.Data.Select(x => new OHLC((double)x.OpenPrice,
        (double)x.HighPrice, 
        (double)x.LowPrice, 
        (double)x.ClosePrice, 
        x.OpenTime, 
        TimeSpan.FromMinutes(1))).ToArray();

        // Append the all bars
        model.Append(bars);

        var socket = new BinanceSocketClient();
        await socket.SpotStreams.SubscribeToKlineUpdatesAsync("BTCUSDT", Binance.Net.Enums.KlineInterval.OneMinute, async (data) =>
        {
            await Dispatcher.UIThread.InvokeAsync(() =>
            {
                var candle = data.Data.Data;

                var toUpdate = model.Prices.FirstOrDefault(x => x.DateTime == candle.OpenTime);

                // Check if the data time are the same as the last. If not, it means we have to add a new bar
                if (toUpdate != null)
                {
                    toUpdate.Volume = (double)candle.Volume;
                    toUpdate.High = (double)candle.HighPrice;
                    toUpdate.Close = (double)candle.ClosePrice;
                    toUpdate.Low = (double)candle.LowPrice;

                    // Update the last bar
                    model.UpdateBar(toUpdate);
                }
                else
                {
                    var newBar = new OHLC((double)candle.OpenPrice, 
                    (double)candle.HighPrice,
                    (double)candle.LowPrice, 
                    (double)candle.ClosePrice, 
                    candle.OpenTime, TimeSpan.FromMinutes(1));

                    // Append the new bar
                    model.Append(newBar);
                }
            }, DispatcherPriority.Background);                       
        });
    }

It is very easy to fullfill the chart with datas just by using Append() and UpdateBar(). **