mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-22 07:08:16 +00:00
Issue #284: MtApi4/MQL4 - added function GetSymbols
This commit is contained in:
@@ -502,6 +502,12 @@ namespace MtApi
|
||||
Dictionary<string, object> cmdParams = new() { { "Pool", (int)pool} };
|
||||
return SendCommand<List<MtOrder>>(ExecutorHandle, MtCommandType.GetOrders, cmdParams);
|
||||
}
|
||||
|
||||
public List<string>? GetSymbols(bool selected)
|
||||
{
|
||||
Dictionary<string, object> cmdParams = new() { { "Selected", selected } };
|
||||
return SendCommand<List<string>>(ExecutorHandle, MtCommandType.GetSymbols, cmdParams);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Checkup
|
||||
|
||||
@@ -287,6 +287,7 @@
|
||||
SymbolInfoTick = 288,
|
||||
SymbolInfoDouble = 289,
|
||||
|
||||
GetQuote = 290
|
||||
GetQuote = 290,
|
||||
GetSymbols = 291
|
||||
}
|
||||
}
|
||||
|
||||
+1860
-1724
File diff suppressed because it is too large
Load Diff
@@ -8,44 +8,12 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace TestApiClientUI
|
||||
{
|
||||
class MtLogger : IMtLogger
|
||||
{
|
||||
public void Debug(object message)
|
||||
{
|
||||
Write("DEBUG", message);
|
||||
}
|
||||
|
||||
public void Error(object message)
|
||||
{
|
||||
Write("ERROR", message);
|
||||
}
|
||||
|
||||
public void Fatal(object message)
|
||||
{
|
||||
Write("FATAL", message);
|
||||
}
|
||||
|
||||
public void Info(object message)
|
||||
{
|
||||
Write("INFO", message);
|
||||
}
|
||||
|
||||
public void Warn(object message)
|
||||
{
|
||||
Write("WARN", message);
|
||||
}
|
||||
private void Write(string level, object message)
|
||||
{
|
||||
Console.WriteLine($"[{Environment.CurrentManagedThreadId}] [{level}] {message}");
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly List<Action> _groupOrderCommands = [];
|
||||
private readonly MtApiClient _apiClient = new (new MtLogger());
|
||||
private readonly MtApiClient _apiClient = new(new MtLogger());
|
||||
private readonly TimerTradeMonitor _timerTradeMonitor;
|
||||
private readonly TimeframeTradeMonitor _timeframeTradeMonitor;
|
||||
|
||||
@@ -742,7 +710,7 @@ namespace TestApiClientUI
|
||||
|
||||
var symbol = textBoxOrderSymbol.Text;
|
||||
|
||||
var cmd = (TradeOperation) comboBoxOrderCommand.SelectedIndex;
|
||||
var cmd = (TradeOperation)comboBoxOrderCommand.SelectedIndex;
|
||||
|
||||
double volume;
|
||||
double.TryParse(textBoxOrderVolume.Text, out volume);
|
||||
@@ -750,7 +718,7 @@ namespace TestApiClientUI
|
||||
double price;
|
||||
double.TryParse(textBoxOrderPrice.Text, out price);
|
||||
|
||||
var slippage = (int) numericOrderSlippage.Value;
|
||||
var slippage = (int)numericOrderSlippage.Value;
|
||||
|
||||
double stoploss;
|
||||
double.TryParse(textBoxOrderStoploss.Text, out stoploss);
|
||||
@@ -805,8 +773,8 @@ namespace TestApiClientUI
|
||||
private async void button16_Click(object sender, EventArgs e)
|
||||
{
|
||||
var ticket = int.Parse(textBoxIndexTicket.Text);
|
||||
var selectMode = (OrderSelectMode) comboBox1.SelectedIndex;
|
||||
var selectSource = (OrderSelectSource) comboBox2.SelectedIndex;
|
||||
var selectMode = (OrderSelectMode)comboBox1.SelectedIndex;
|
||||
var selectSource = (OrderSelectSource)comboBox2.SelectedIndex;
|
||||
|
||||
var order = await Execute(() => _apiClient.GetOrder(ticket, selectMode, selectSource));
|
||||
|
||||
@@ -1544,5 +1512,19 @@ namespace TestApiClientUI
|
||||
PrintLog($"iBarShift result1 = {result1}, time = {time1}");
|
||||
PrintLog($"iBarShift result2 = {result2}, time = {time2}");
|
||||
}
|
||||
|
||||
private async void button74_Click(object sender, EventArgs e)
|
||||
{
|
||||
listBoxAllSymbols.Items.Clear();
|
||||
|
||||
var result = await Execute(() => _apiClient.GetSymbols(checkBox3.Checked));
|
||||
if (result != null)
|
||||
{
|
||||
foreach (string? r in result)
|
||||
listBoxAllSymbols.Items.Add(r);
|
||||
}
|
||||
int count = result != null ? result.Count : 0;
|
||||
PrintLog($"GetSymbols: {count}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
using MtApi;
|
||||
|
||||
namespace TestApiClientUI
|
||||
{
|
||||
class MtLogger : IMtLogger
|
||||
{
|
||||
public void Debug(object message)
|
||||
{
|
||||
Write("DEBUG", message);
|
||||
}
|
||||
|
||||
public void Error(object message)
|
||||
{
|
||||
Write("ERROR", message);
|
||||
}
|
||||
|
||||
public void Fatal(object message)
|
||||
{
|
||||
Write("FATAL", message);
|
||||
}
|
||||
|
||||
public void Info(object message)
|
||||
{
|
||||
Write("INFO", message);
|
||||
}
|
||||
|
||||
public void Warn(object message)
|
||||
{
|
||||
Write("WARN", message);
|
||||
}
|
||||
private void Write(string level, object message)
|
||||
{
|
||||
Console.WriteLine($"[{Environment.CurrentManagedThreadId}] [{level}] {message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1330,6 +1330,9 @@ int ExecuteCommand()
|
||||
case 290: //GetQuote
|
||||
response = Execute_GetQuote();
|
||||
break;
|
||||
case 291: //GetSymbols
|
||||
response = Execute_GetSymbols();
|
||||
break;
|
||||
|
||||
default:
|
||||
Print("WARNING: Unknown command type = ", command_type);
|
||||
@@ -4187,3 +4190,25 @@ string Execute_GetQuote()
|
||||
MtQuote quote(Symbol(), tick);
|
||||
return CreateSuccessResponse(quote.CreateJson());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user