Skip to content

C#

.NET 6 or newer; uses HttpClient, System.Text.Json and ClientWebSocket.

All examples assume the EA is running on the same computer with default ports. Order examples are for demo accounts.

using System.Text.Json;
var http = new HttpClient { BaseAddress = new Uri("http://127.0.0.1:81") };
var json = await http.GetStringAsync("/v1/quote?symbol=EURUSD");
using var doc = JsonDocument.Parse(json);
Console.WriteLine($"{doc.RootElement.GetProperty("BID")} / {doc.RootElement.GetProperty("ASK")}");
var res = await http.PostAsync(
"/v1/order?symbol=EURUSD&volume=0.01&type=ORDER_TYPE_BUY&sl=1.1050&tp=1.1200", null);
var body = await res.Content.ReadAsStringAsync();
using var r = JsonDocument.Parse(body);
Console.WriteLine($"RETCODE {r.RootElement.GetProperty("RETCODE")} ORDER {r.RootElement.GetProperty("ORDER")}");
using System.Net.WebSockets;
using System.Text;
await http.PostAsync("/v1/track/prices?symbols=EURUSD", null);
using var ws = new ClientWebSocket();
await ws.ConnectAsync(new Uri("ws://127.0.0.1:81"), CancellationToken.None);
var buf = new byte[65536];
while (ws.State == WebSocketState.Open)
{
var r = await ws.ReceiveAsync(buf, CancellationToken.None);
Console.WriteLine(Encoding.UTF8.GetString(buf, 0, r.Count));
}