-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
115 lines (93 loc) · 2.92 KB
/
main.cpp
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "windows.h"
#include <time.h>
#include <iostream>
#include <thread>
#include "utils.h"
#include <map>
#define TIMEOUT 10
FfcMsg master;
int ordersTotal = 0;
time_t lastSession = 0;
int timeRestart = 0;
bool transmitterInit = false;
bool needUpdate = false;
bool noCycle = true;
namespace ffc {
bool ffc_Init(wchar_t* path) {
if (transmitterInit) return false; //Ïîâòîðíàÿ èíèöèàëèçàöèÿ
setMapFile(path);
transmitterInit = true; //Çàùèòà îò äâîéíîãî çàïóñêà
if (AllocConsole()) {
freopen("CONOUT$", "w", stdout);
freopen("conout$", "w", stderr);
SetConsoleOutputCP(CP_UTF8);// GetACP());
SetConsoleCP(CP_UTF8);
std::wcout << "DLL inited.v3.\r\n";
}
if (!zmqInit()) {
std::wcout << "ZMQ init error!\r\n";
zmqDeInit();
return false;
}
loadMap();
master.ordersCount = 0;
master.validation = false;
std::wcout << "initDone \r\n";
return true; //Óäà÷íàÿ èíèöèàëèçàöèÿ
}
//Íà÷àëî öèêëà îáðàáîòêè
void ffc_ordersCount(int num) {
needUpdate = ordersTotal != num; //Åñëè ïðåäûäóùåå êîëè÷åñòâî îðäåðîâ äðóãîå, òî îáíîâëÿåì
//std::wcout << "needUpdate: (ordersTotal != num) " << needUpdate << "\r\n";
master.ordersCount = 0;
ordersTotal = num;
resetFlag();
//std::wcout << "ordersTotal - " << ordersTotal << "\r\n";
}
void ffc_OrderUpdate(int ticket, int magic, wchar_t* symbol, int opType,
double lots, double openPrice, double takeProfit, double stopLoss,
__time64_t expiration, wchar_t* comment) {
int provider = 0;
int mapedTicket = 0;
FfcOrder* order = master.orders + master.ordersCount;
//ïðîâåðêà íà from#, åñëè åñòü òî ïîäìåíÿåì òèêåò, ticket_from - ñòàðûé, çàêðûòûé òèêåò
int ticket_from = getTicket(comment);
if (ticket_from) {
provider = 1;
mapedTicket = getMap(ticket_from, ticket);
} else provider = getProvider(comment);
if (!mapedTicket) mapedTicket = getMap(ticket, 0);
needUpdate = needUpdate || order->ticket != mapedTicket || order->tpprice != takeProfit || order->slprice != stopLoss || order->lots != lots;
//std::wcout << "lots master - " << lots << "\r\n";
order->ticket = mapedTicket; //Íàäî ñäåëàòü ìàïïèíã
order->magic = provider;
order->type = opType;
order->lots = lots;
order->openprice = openPrice;
order->opentime = 0;
order->tpprice = takeProfit;
order->slprice = stopLoss;
order->expiration = expiration;
wcscpy_s(order->symbol, SYMBOL_LENGTH, symbol);
master.ordersCount++;
}
//Êîíåö öèêëà ïåðåäà÷è îòêðûòûõ îðäåðîâ
void ffc_validation(bool flag) {
master.validation = flag;
if (needUpdate || (time(NULL) - lastSession) > TIMEOUT) {
zmqSendOrders(&master);
lastSession = time(NULL);
}
saveMap();
//std::wcout << "Orders validation: " << timeRestart << "\r\n";
}
int ffc_GetTicket() { // âûäàåì òèêåò(ticket_id), î êîòîðîì íàì õîòåëîñü áû óçíàòü
return 0;
}
void ffc_OrderSelectError(int Ticket) {
}
void ffc_DeInit() {
zmqDeInit();
transmitterInit = false;
}
}