mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-15 03:38:09 +00:00
Issue #284: MtApi5/MQL5 - added function GetSymbols
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using MtClient;
|
using MtClient;
|
||||||
using MtApi5.MtProtocol;
|
using MtApi5.MtProtocol;
|
||||||
using MtApi5.MtProtocol.ICustomRequest;
|
using MtApi5.MtProtocol.ICustomRequest;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
namespace MtApi5
|
namespace MtApi5
|
||||||
{
|
{
|
||||||
@@ -188,6 +189,15 @@ namespace MtApi5
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
///Load symbols
|
||||||
|
///</summary>
|
||||||
|
public List<string>? GetSymbols(bool selected)
|
||||||
|
{
|
||||||
|
Dictionary<string, object> cmdParams = new() { { "Selected", selected } };
|
||||||
|
return SendCommand<List<string>>(ExecutorHandle, Mt5CommandType.GetSymbols, cmdParams);
|
||||||
|
}
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
///Checks if the Expert Advisor runs in the testing mode..
|
///Checks if the Expert Advisor runs in the testing mode..
|
||||||
///</summary>
|
///</summary>
|
||||||
|
|||||||
@@ -259,6 +259,7 @@ namespace MtApi5.MtProtocol
|
|||||||
OrderSendAsync = 302,
|
OrderSendAsync = 302,
|
||||||
OrderCheck = 303,
|
OrderCheck = 303,
|
||||||
Buy = 304,
|
Buy = 304,
|
||||||
Sell = 305
|
Sell = 305,
|
||||||
|
GetSymbols = 306
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -473,22 +473,34 @@
|
|||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
<TabItem Header="Market Info">
|
<TabItem Header="Market Info">
|
||||||
<WrapPanel VerticalAlignment="Top" Margin="5">
|
<Grid>
|
||||||
<Button Command="{Binding SymbolsTotalCommand}" Content="SymbolsTotal" Margin="2"/>
|
<Grid.RowDefinitions>
|
||||||
<Button Command="{Binding SymbolNameCommand}" Content="SymbolName" Margin="2"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<Button Command="{Binding SymbolSelectCommand}" Content="SymbolSelect" Margin="2"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<Button Command="{Binding SymbolIsSynchronizedCommand}" Content="SymbolIsSynchronized" Margin="2"/>
|
<RowDefinition Height="*"/>
|
||||||
<Button Command="{Binding SymbolInfoDoubleCommand}" Content="SymbolInfoDouble" Margin="2"/>
|
</Grid.RowDefinitions>
|
||||||
<Button Command="{Binding SymbolInfoIntegerCommand}" Content="SymbolInfoInteger" Margin="2"/>
|
<WrapPanel Grid.Row="0" VerticalAlignment="Top" Margin="5">
|
||||||
<Button Command="{Binding SymbolInfoStringCommand}" Content="SymbolInfoString" Margin="2"/>
|
<Button Command="{Binding SymbolsTotalCommand}" Content="SymbolsTotal" Margin="2"/>
|
||||||
<Button Command="{Binding SymbolInfoString2Command}" Content="SymbolInfoString-2" Margin="2"/>
|
<Button Command="{Binding SymbolNameCommand}" Content="SymbolName" Margin="2"/>
|
||||||
<Button Command="{Binding SymbolInfoTickCommand}" Content="SymbolInfoTick" Margin="2"/>
|
<Button Command="{Binding SymbolSelectCommand}" Content="SymbolSelect" Margin="2"/>
|
||||||
<Button Command="{Binding SymbolInfoSessionQuoteCommand}" Content="SymbolInfoSessionQuote" Margin="2"/>
|
<Button Command="{Binding SymbolIsSynchronizedCommand}" Content="SymbolIsSynchronized" Margin="2"/>
|
||||||
<Button Command="{Binding SymbolInfoSessionTradeCommand}" Content="SymbolInfoSessionTrade" Margin="2"/>
|
<Button Command="{Binding SymbolInfoDoubleCommand}" Content="SymbolInfoDouble" Margin="2"/>
|
||||||
<Button Command="{Binding MarketBookAddCommand}" Content="MarketBookAdd" Margin="2"/>
|
<Button Command="{Binding SymbolInfoIntegerCommand}" Content="SymbolInfoInteger" Margin="2"/>
|
||||||
<Button Command="{Binding MarketBookReleaseCommand}" Content="MarketBookRelease" Margin="2"/>
|
<Button Command="{Binding SymbolInfoStringCommand}" Content="SymbolInfoString" Margin="2"/>
|
||||||
<Button Command="{Binding MarketBookGetCommand}" Content="MarketBookGet" Margin="2"/>
|
<Button Command="{Binding SymbolInfoString2Command}" Content="SymbolInfoString-2" Margin="2"/>
|
||||||
</WrapPanel>
|
<Button Command="{Binding SymbolInfoTickCommand}" Content="SymbolInfoTick" Margin="2"/>
|
||||||
|
<Button Command="{Binding SymbolInfoSessionQuoteCommand}" Content="SymbolInfoSessionQuote" Margin="2"/>
|
||||||
|
<Button Command="{Binding SymbolInfoSessionTradeCommand}" Content="SymbolInfoSessionTrade" Margin="2"/>
|
||||||
|
<Button Command="{Binding MarketBookAddCommand}" Content="MarketBookAdd" Margin="2"/>
|
||||||
|
<Button Command="{Binding MarketBookReleaseCommand}" Content="MarketBookRelease" Margin="2"/>
|
||||||
|
<Button Command="{Binding MarketBookGetCommand}" Content="MarketBookGet" Margin="2"/>
|
||||||
|
</WrapPanel>
|
||||||
|
<StackPanel Grid.Row="1" Orientation="Horizontal">
|
||||||
|
<Button Content="GetSymbols" Command="{Binding GetSymbolsCommand}" Width="100" Margin="2"/>
|
||||||
|
<CheckBox Content="Selected" IsChecked="{Binding GetSymbolsSelected}" Margin="5" />
|
||||||
|
</StackPanel>
|
||||||
|
<ListBox Grid.Row="2" ItemsSource="{Binding Symbols}" Height="Auto" Width="200" HorizontalAlignment="Left"/>
|
||||||
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
<TabItem Header="CTrade (Positions)">
|
<TabItem Header="CTrade (Positions)">
|
||||||
|
|||||||
@@ -160,6 +160,8 @@ namespace MtApi5TestClient
|
|||||||
public DelegateCommand GlobalVariablesTotalCommand { get; private set; }
|
public DelegateCommand GlobalVariablesTotalCommand { get; private set; }
|
||||||
|
|
||||||
public DelegateCommand UnlockTicksCommand { get; private set; }
|
public DelegateCommand UnlockTicksCommand { get; private set; }
|
||||||
|
|
||||||
|
public DelegateCommand GetSymbolsCommand { get; private set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
@@ -314,6 +316,19 @@ namespace MtApi5TestClient
|
|||||||
OnPropertyChanged("PositionTicketValue");
|
OnPropertyChanged("PositionTicketValue");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool GetSymbolsSelected { get; set; } = false;
|
||||||
|
|
||||||
|
private List<string> _symbols;
|
||||||
|
public List<string> Symbols
|
||||||
|
{
|
||||||
|
get { return _symbols; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_symbols = value;
|
||||||
|
OnPropertyChanged("Symbols");
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
@@ -475,6 +490,8 @@ namespace MtApi5TestClient
|
|||||||
GlobalVariablesTotalCommand = new DelegateCommand(ExecuteGlobalVariablesTotal);
|
GlobalVariablesTotalCommand = new DelegateCommand(ExecuteGlobalVariablesTotal);
|
||||||
|
|
||||||
UnlockTicksCommand = new DelegateCommand(ExecuteUnlockTicks);
|
UnlockTicksCommand = new DelegateCommand(ExecuteUnlockTicks);
|
||||||
|
|
||||||
|
GetSymbolsCommand = new DelegateCommand(ExecuteGetSymbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanExecuteConnect(object o)
|
private bool CanExecuteConnect(object o)
|
||||||
@@ -1726,6 +1743,19 @@ namespace MtApi5TestClient
|
|||||||
_mtApiClient.UnlockTicks();
|
_mtApiClient.UnlockTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void ExecuteGetSymbols(object o)
|
||||||
|
{
|
||||||
|
var result = await Execute(() => _mtApiClient.GetSymbols(GetSymbolsSelected));
|
||||||
|
if (result == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AddLog($"ChartScreenShot: {result.Count} count of symbols");
|
||||||
|
RunOnUiThread(() =>
|
||||||
|
{
|
||||||
|
Symbols = result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static void RunOnUiThread(Action action)
|
private static void RunOnUiThread(Action action)
|
||||||
{
|
{
|
||||||
Application.Current?.Dispatcher.Invoke(action);
|
Application.Current?.Dispatcher.Invoke(action);
|
||||||
|
|||||||
Binary file not shown.
+24
-1
@@ -1,7 +1,7 @@
|
|||||||
#property copyright "Vyacheslav Demidyuk"
|
#property copyright "Vyacheslav Demidyuk"
|
||||||
#property link ""
|
#property link ""
|
||||||
|
|
||||||
#property version "2.0"
|
#property version "2.1"
|
||||||
#property description "MtApi (MT5) connection expert"
|
#property description "MtApi (MT5) connection expert"
|
||||||
|
|
||||||
#include <json.mqh>
|
#include <json.mqh>
|
||||||
@@ -380,6 +380,7 @@ int preinit()
|
|||||||
ADD_EXECUTOR(303, OrderCheck);
|
ADD_EXECUTOR(303, OrderCheck);
|
||||||
ADD_EXECUTOR(304, Buy);
|
ADD_EXECUTOR(304, Buy);
|
||||||
ADD_EXECUTOR(305, Sell);
|
ADD_EXECUTOR(305, Sell);
|
||||||
|
ADD_EXECUTOR(306, GetSymbols);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -3450,6 +3451,28 @@ string Execute_Sell()
|
|||||||
return CreateSuccessResponse(result_value_jo);
|
return CreateSuccessResponse(result_value_jo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string Execute_GetSymbols()
|
||||||
|
{
|
||||||
|
GET_JSON_PAYLOAD(jo);
|
||||||
|
GET_BOOL_JSON_VALUE(jo, "Selected", selected);
|
||||||
|
|
||||||
|
const int symbolsCount = SymbolsTotal(selected);
|
||||||
|
JSONArray* jaSymbols = new JSONArray();
|
||||||
|
int idx = 0;
|
||||||
|
for(int idxSymbol = 0; idxSymbol < symbolsCount; idxSymbol++)
|
||||||
|
{
|
||||||
|
string symbol = SymbolName(idxSymbol, selected);
|
||||||
|
string firstChar = StringSubstr(symbol, 0, 1);
|
||||||
|
if(firstChar != "#" && StringLen(symbol) == 6)
|
||||||
|
{
|
||||||
|
jaSymbols.put(idx, new JSONString(symbol));
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return CreateSuccessResponse(jaSymbols);
|
||||||
|
}
|
||||||
|
|
||||||
int PositionCloseAll()
|
int PositionCloseAll()
|
||||||
{
|
{
|
||||||
CTrade trade;
|
CTrade trade;
|
||||||
|
|||||||
Reference in New Issue
Block a user