mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-12 18:28:07 +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} };
|
Dictionary<string, object> cmdParams = new() { { "Pool", (int)pool} };
|
||||||
return SendCommand<List<MtOrder>>(ExecutorHandle, MtCommandType.GetOrders, cmdParams);
|
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
|
#endregion
|
||||||
|
|
||||||
#region Checkup
|
#region Checkup
|
||||||
|
|||||||
@@ -287,6 +287,7 @@
|
|||||||
SymbolInfoTick = 288,
|
SymbolInfoTick = 288,
|
||||||
SymbolInfoDouble = 289,
|
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
|
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
|
public partial class Form1 : Form
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
private readonly List<Action> _groupOrderCommands = [];
|
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 TimerTradeMonitor _timerTradeMonitor;
|
||||||
private readonly TimeframeTradeMonitor _timeframeTradeMonitor;
|
private readonly TimeframeTradeMonitor _timeframeTradeMonitor;
|
||||||
|
|
||||||
@@ -742,7 +710,7 @@ namespace TestApiClientUI
|
|||||||
|
|
||||||
var symbol = textBoxOrderSymbol.Text;
|
var symbol = textBoxOrderSymbol.Text;
|
||||||
|
|
||||||
var cmd = (TradeOperation) comboBoxOrderCommand.SelectedIndex;
|
var cmd = (TradeOperation)comboBoxOrderCommand.SelectedIndex;
|
||||||
|
|
||||||
double volume;
|
double volume;
|
||||||
double.TryParse(textBoxOrderVolume.Text, out volume);
|
double.TryParse(textBoxOrderVolume.Text, out volume);
|
||||||
@@ -750,7 +718,7 @@ namespace TestApiClientUI
|
|||||||
double price;
|
double price;
|
||||||
double.TryParse(textBoxOrderPrice.Text, out price);
|
double.TryParse(textBoxOrderPrice.Text, out price);
|
||||||
|
|
||||||
var slippage = (int) numericOrderSlippage.Value;
|
var slippage = (int)numericOrderSlippage.Value;
|
||||||
|
|
||||||
double stoploss;
|
double stoploss;
|
||||||
double.TryParse(textBoxOrderStoploss.Text, out stoploss);
|
double.TryParse(textBoxOrderStoploss.Text, out stoploss);
|
||||||
@@ -805,8 +773,8 @@ namespace TestApiClientUI
|
|||||||
private async void button16_Click(object sender, EventArgs e)
|
private async void button16_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var ticket = int.Parse(textBoxIndexTicket.Text);
|
var ticket = int.Parse(textBoxIndexTicket.Text);
|
||||||
var selectMode = (OrderSelectMode) comboBox1.SelectedIndex;
|
var selectMode = (OrderSelectMode)comboBox1.SelectedIndex;
|
||||||
var selectSource = (OrderSelectSource) comboBox2.SelectedIndex;
|
var selectSource = (OrderSelectSource)comboBox2.SelectedIndex;
|
||||||
|
|
||||||
var order = await Execute(() => _apiClient.GetOrder(ticket, selectMode, selectSource));
|
var order = await Execute(() => _apiClient.GetOrder(ticket, selectMode, selectSource));
|
||||||
|
|
||||||
@@ -1544,5 +1512,19 @@ namespace TestApiClientUI
|
|||||||
PrintLog($"iBarShift result1 = {result1}, time = {time1}");
|
PrintLog($"iBarShift result1 = {result1}, time = {time1}");
|
||||||
PrintLog($"iBarShift result2 = {result2}, time = {time2}");
|
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}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<root>
|
<root>
|
||||||
<!--
|
<!--
|
||||||
Microsoft ResX Schema
|
Microsoft ResX Schema
|
||||||
|
|
||||||
Version 2.0
|
Version 2.0
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
The primary goals of this format is to allow a simple XML format
|
||||||
that is mostly human readable. The generation and parsing of the
|
that is mostly human readable. The generation and parsing of the
|
||||||
various data types are done through the TypeConverter classes
|
various data types are done through the TypeConverter classes
|
||||||
associated with the data types.
|
associated with the data types.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
... ado.net/XML headers & schema ...
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
<resheader name="version">2.0</resheader>
|
<resheader name="version">2.0</resheader>
|
||||||
@@ -26,36 +26,36 @@
|
|||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
<comment>This is a comment</comment>
|
<comment>This is a comment</comment>
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
There are any number of "resheader" rows that contain simple
|
||||||
name/value pairs.
|
name/value pairs.
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
Each data row contains a name, and value. The row also contains a
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
text/value conversion through the TypeConverter architecture.
|
text/value conversion through the TypeConverter architecture.
|
||||||
Classes that don't support this are serialized and stored with the
|
Classes that don't support this are serialized and stored with the
|
||||||
mimetype set.
|
mimetype set.
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
The mimetype is used for serialized objects, and tells the
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
read any of the formats listed below.
|
read any of the formats listed below.
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
value : The object must be serialized with
|
value : The object must be serialized with
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
value : The object must be serialized with
|
value : The object must be serialized with
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
value : The object must be serialized into a byte array
|
value : The object must be serialized into a byte array
|
||||||
: using a System.ComponentModel.TypeConverter
|
: using a System.ComponentModel.TypeConverter
|
||||||
: and then encoded with base64 encoding.
|
: and then encoded with base64 encoding.
|
||||||
-->
|
-->
|
||||||
|
|||||||
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
|
case 290: //GetQuote
|
||||||
response = Execute_GetQuote();
|
response = Execute_GetQuote();
|
||||||
break;
|
break;
|
||||||
|
case 291: //GetSymbols
|
||||||
|
response = Execute_GetSymbols();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Print("WARNING: Unknown command type = ", command_type);
|
Print("WARNING: Unknown command type = ", command_type);
|
||||||
@@ -4187,3 +4190,25 @@ string Execute_GetQuote()
|
|||||||
MtQuote quote(Symbol(), tick);
|
MtQuote quote(Symbol(), tick);
|
||||||
return CreateSuccessResponse(quote.CreateJson());
|
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