forked from vdemydiuk/mtapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FastMtServer.h
executable file
·84 lines (66 loc) · 2.5 KB
/
FastMtServer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// FastMtServer.h
#pragma once
using namespace MetaTraderApi;
public class FastMtServer
{
public:
static FastMtServer& const Instance()
{
static FastMtServer theSingleInstance;
return theSingleInstance;
}
public void Init(string user, int accountId, int connectionAttemt);
public void Start(string symbol, double bid, double ask);
public void Stop();
public void SendQuote(string symbol, double bid, double ask);
private:
FastMtServer(){}
FastMtServer(OnlyOne& root){}
public void Init(string user, int accountId, int connectionAttemt)
{
Logger.Instance.Write("FastMtQuoteServer::Init");
if (_mtServer == null)
{
var initServerName = user + accountId.ToString();
_mtServer = new QuoteServer(initServerName, connectionAttemt);
_mtServer.ConnectionStatusUpdated +=new ConnectionStatusEventHandler(_mtServer_ConnectionStatusUpdated);
}
}
public void Start(string symbol, double bid, double ask)
{
Logger.Instance.Write("FastMtQuoteServer::Start");
_startSymbol = symbol;
_startBid = bid;
_startAsk = ask;
_mtServer.Start();
}
public void Stop()
{
Logger.Instance.Write("FastMtQuoteServer::Init");
_mtServer.Stop();
}
public void SendQuote(string symbol, double bid, double ask)
{
Logger.Instance.Write("FastMtQuoteServer::SendQuote");
_mtServer.SendNewQuote(symbol, bid, ask);
}
void _mtServer_ConnectionStatusUpdated(object sender, ConnectionStatusType connectionStatus)
{
Logger.Instance.Write("FastMtQuoteServer::_mtServer_ConnectionStatusUpdated: status = " + connectionStatus.ToString());
if (connectionStatus == ConnectionStatusType.Connected && _mtServer != null)
{
try
{
SendQuote(_startSymbol, _startBid, _startAsk);
}
catch (Exception ex)
{
Logger.Instance.Write("FastMtQuoteServer::_mtServer_ConnectionStatusUpdated: Error = " + ex.Message);
}
}
}
private QuoteServer _mtServer;
private string _startSymbol = string.Empty;
private double _startBid;
private double _startAsk;
}