Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Plugins/.samples.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,10 +5,52 @@
{
"name": "All placements"
},
{
"name": "ActiveFrameChanged Sample"
},
{
"name": "AlgoRegistry Sample"
},
{
"name": "BacktestingInPlugins Sample"
},
{
"name": "ChartId Sample"
},
{
"name": "ChartIndicators Sample"
},
{
"name": "ChartRobots Sample"
},
{
"name": "Commands Sample"
},
{
"name": "CoordinatesConversion Sample"
},
{
"name": "Custom Frame Sample"
},
{
"name": "IndicatorTitles Sample"
},
{
"name": "Interactive WebView"
},
{
"name": "Order by Margin"
},
{
"name": "PositionCurrentPrice Sample"
},
{
"name": "SmoothMouseMove Sample"
},
{
"name": "TradeWatch Tab Sample"
},
{
"name": "WebSocket Sample"
}
]
10 changes: 5 additions & 5 deletions Plugins/AlgoRegistry Sample/AlgoRegistry Sample.sln
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,18 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlgoRegistry Sample", "AlgoRegistry Sample\AlgoRegistry Sample.csproj", "{253c1137-a441-477f-bbdd-8dffcad26446}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlgoRegistry Sample", "AlgoRegistry Sample\AlgoRegistry Sample.csproj", "{43349484-218e-4bf3-a452-0e44bf636cfe}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{253c1137-a441-477f-bbdd-8dffcad26446}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{253c1137-a441-477f-bbdd-8dffcad26446}.Debug|Any CPU.Build.0 = Debug|Any CPU
{253c1137-a441-477f-bbdd-8dffcad26446}.Release|Any CPU.ActiveCfg = Release|Any CPU
{253c1137-a441-477f-bbdd-8dffcad26446}.Release|Any CPU.Build.0 = Release|Any CPU
{43349484-218e-4bf3-a452-0e44bf636cfe}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43349484-218e-4bf3-a452-0e44bf636cfe}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43349484-218e-4bf3-a452-0e44bf636cfe}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43349484-218e-4bf3-a452-0e44bf636cfe}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,99 +5,31 @@
// This code is intended to be used as a sample and does not guarantee any particular outcome or
// profit of any kind. Use it at your own risk.
//
// This sample adds a new block into the ASP. The block displays statistics about the number of
// different types of algorithms installed on the user's machine. Information in the block is
// updated every second to make sure that it is always accurate.
// This sample adds a trade watch tab, and uses AlgoRegistry API to show stats about installed algo types.
//
// -------------------------------------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Plugins
{
[Plugin(AccessRights = AccessRights.None)]
public class AlgoRegistrySample : Plugin
{
// Declaring the TextBlock for displaying data about
// custom indicators
private TextBlock _customIndicatorsBlock = new TextBlock
{
FontSize = 12,
FontWeight = FontWeight.Bold,
TextAlignment = TextAlignment.Left,
Padding = new Thickness(5, 5, 5, 5),
};

// Declaring the TextBlock for displaying data about
// built-in indicators
private TextBlock _indicatorsBlock = new TextBlock
{
FontSize = 12,
FontWeight = FontWeight.Bold,
TextAlignment = TextAlignment.Left,
Padding = new Thickness(5, 5, 5, 5),
};

// Declaring the TextBlock for displaying data about
// cBots
private TextBlock _robotsBlock = new TextBlock
{
FontSize = 12,
FontWeight = FontWeight.Bold,
TextAlignment = TextAlignment.Left,
Padding = new Thickness(5, 5, 5, 5),
};

// Declaring the TextBlock for displaying data about
// plugins
private TextBlock _pluginsBlock = new TextBlock
{
FontSize = 12,
FontWeight = FontWeight.Bold,
TextAlignment = TextAlignment.Left,
Padding = new Thickness(5, 5, 5, 5),
};

// Declaring the Grid to store custom controls
private Grid _grid = new Grid(4, 1);

protected override void OnStart()
{
// Adding a new block into the ASP and adding
// the Grid with all TextBlocks as a child
var aspBlock = Asp.SymbolTab.AddBlock("Algo Registry");
aspBlock.IsExpanded = true;
aspBlock.Height = 200;

_grid.AddChild(_robotsBlock, 0, 0);
_grid.AddChild(_indicatorsBlock, 1, 0);
_grid.AddChild(_customIndicatorsBlock, 2, 0);
_grid.AddChild(_pluginsBlock, 3, 0);
var tradeWatchTab = TradeWatch.AddTab("Algo Registry");

aspBlock.Child = _grid;
var panel = new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Center,
};

panel.AddChild(new AlgoStatsControl(AlgoRegistry){Margin = 10, VerticalAlignment = VerticalAlignment.Top});
panel.AddChild(new AlgoTypeInfoControl(AlgoRegistry){Margin = 10, VerticalAlignment = VerticalAlignment.Top});

// Starting the Timer to refresh information
// in all TextBlocks
Timer.Start(TimeSpan.FromSeconds(1));
tradeWatchTab.Child = panel;
}

protected override void OnTimer()
{
// Using the AlgoRegistry to attain information about the
// different AlgoKinds installed on the user's machine
_robotsBlock.Text = $"cBots:{AlgoRegistry.GetCount(AlgoKind.Robot)}"
_customIndicatorsBlock.Text = $"Custom indicators:{AlgoRegistry.GetCount(AlgoKind.CustomIndicator)}"
_indicatorsBlock.Text = $"Indicators:{AlgoRegistry.GetCount(AlgoKind.StandardIndicator)}"
_pluginsBlock.Text = $"Plugins:{AlgoRegistry.GetCount(AlgoKind.Plugin)}"
}

}
}
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
using System.Linq;
using cAlgo.API;

namespace cAlgo.Plugins;

public class AlgoStatsControl: CustomControl
{
private const string FontFamily = "Calibri"

private readonly AlgoRegistry _algoRegistry;
private readonly TextBlock _algosCountTextBlock;
private readonly TextBlock _customIndicatorsCountTextBlock;
private readonly TextBlock _standardIndicatorsCountTextBlock;
private readonly TextBlock _botsCountTextBlock;
private readonly TextBlock _pluginsCountTextBlock;

public AlgoStatsControl(AlgoRegistry algoRegistry)
{
_algoRegistry = algoRegistry;

var panel = new Grid(6, 2);

var titleTextBlock = GetTextBlock("Algo Stats");

titleTextBlock.HorizontalAlignment = HorizontalAlignment.Center;

panel.AddChild(titleTextBlock, 0, 0, 1, 2);

panel.AddChild(GetTextBlock("Algos #"), 1, 0);

_algosCountTextBlock = GetTextBlock();

panel.AddChild(_algosCountTextBlock, 1, 1);

panel.AddChild(GetTextBlock("Standard Indicators #"), 2, 0);

_standardIndicatorsCountTextBlock = GetTextBlock();

panel.AddChild(_standardIndicatorsCountTextBlock, 2, 1);

panel.AddChild(GetTextBlock("Custom Indicators #"), 3, 0);

_customIndicatorsCountTextBlock = GetTextBlock();

panel.AddChild(_customIndicatorsCountTextBlock, 3, 1);

panel.AddChild(GetTextBlock("cBots #"), 4, 0);

_botsCountTextBlock = GetTextBlock();

panel.AddChild(_botsCountTextBlock, 4, 1);

panel.AddChild(GetTextBlock("Plugins #"), 5, 0);

_pluginsCountTextBlock = GetTextBlock();

panel.AddChild(_pluginsCountTextBlock, 5, 1);

AddChild(panel);

Populate();

_algoRegistry.AlgoTypeInstalled += _ => Populate();
_algoRegistry.AlgoTypeDeleted += _ => Populate();
}

private void Populate()
{
_algosCountTextBlock.Text = _algoRegistry.Count.ToString();
_botsCountTextBlock.Text = _algoRegistry.Count(type => type.AlgoKind == AlgoKind.Robot).ToString();
_customIndicatorsCountTextBlock.Text = _algoRegistry.Count(type => type.AlgoKind == AlgoKind.CustomIndicator).ToString();
_standardIndicatorsCountTextBlock.Text = _algoRegistry.Count(type => type.AlgoKind == AlgoKind.StandardIndicator).ToString();
_pluginsCountTextBlock.Text = _algoRegistry.Count(type => type.AlgoKind == AlgoKind.Plugin).ToString();
}

private TextBlock GetTextBlock(string text = null) => new()
{
Margin = 3,
FontSize = 20,
FontWeight = FontWeight.Bold,
FontFamily = FontFamily,
Text = text
};
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
using System.Linq;
using cAlgo.API;

namespace cAlgo.Plugins;

public class AlgoTypeInfoControl: CustomControl
{
private const string FontFamily = "Calibri"

private readonly AlgoRegistry _algoRegistry;
private readonly ComboBox _algoTypesComboBox;
private readonly TextBlock _algoTypeKindTextBlock;
private readonly TextBlock _algoTypeParametersTextBlock;
private readonly TextBlock _algoTypeOutputsTextBlock;

public AlgoTypeInfoControl(AlgoRegistry algoRegistry)
{
_algoRegistry = algoRegistry;

var panel = new Grid(5, 2){BackgroundColor = Color.Gray};

var titleTextBlock = GetTextBlock("Algo Type Info");

titleTextBlock.HorizontalAlignment = HorizontalAlignment.Center;

panel.AddChild(titleTextBlock, 0, 0, 1, 2);

panel.AddChild(GetTextBlock("Types"), 1, 0);

_algoTypesComboBox = new ComboBox
{
Margin = 3,
FontSize = 20,
FontWeight = FontWeight.Bold,
FontFamily = FontFamily,
Padding = 2
};

panel.AddChild(_algoTypesComboBox, 1, 1);

panel.AddChild(GetTextBlock("Kind"), 2, 0);

_algoTypeKindTextBlock = GetTextBlock();

panel.AddChild(_algoTypeKindTextBlock, 2, 1);

panel.AddChild(GetTextBlock("Parameters"), 3, 0);

_algoTypeParametersTextBlock = GetTextBlock();

panel.AddChild(_algoTypeParametersTextBlock, 3, 1);

panel.AddChild(GetTextBlock("Outputs"), 4, 0);

_algoTypeOutputsTextBlock = GetTextBlock();

panel.AddChild(_algoTypeOutputsTextBlock, 4, 1);

AddChild(panel);

_algoTypesComboBox.SelectedItemChanged += _ => OnAlgoTypesComboBoxSelectedItemChanged();

PopulateTypes();

_algoRegistry.AlgoTypeInstalled += _ => PopulateTypes();
_algoRegistry.AlgoTypeDeleted += _ => PopulateTypes();
}

private void OnAlgoTypesComboBoxSelectedItemChanged()
{
if (_algoRegistry.Get(_algoTypesComboBox.SelectedItem) is not{} algoType)
{
_algoTypeKindTextBlock.Text = null;
_algoTypeParametersTextBlock.Text = null;
_algoTypeOutputsTextBlock.Text = null;

return;
}

_algoTypeKindTextBlock.Text = algoType.AlgoKind.ToString();
_algoTypeParametersTextBlock.Text = algoType switch
{
IndicatorType indicatorType => string.Join(", ", indicatorType.Parameters.Select(p => p.Name)),
RobotType robotType => string.Join(", ", robotType.Parameters.Select(p => p.Name)),
_ => null
};
_algoTypeOutputsTextBlock.Text = algoType switch
{
IndicatorType indicatorType => string.Join(", ", indicatorType.Outputs.Select(p => p.Name)),
_ => null
};
}

private void PopulateTypes()
{
foreach (var algoType in _algoRegistry)
{
_algoTypesComboBox.AddItem(algoType.Name);
}

_algoTypesComboBox.SelectedItem = _algoRegistry.FirstOrDefault()?.Name;

OnAlgoTypesComboBoxSelectedItemChanged();
}

private TextBlock GetTextBlock(string text = null) => new()
{
Margin = 3,
FontSize = 20,
FontWeight = FontWeight.Bold,
FontFamily = FontFamily,
Text = text
};
}
Loading