MT4ServerAPI.h 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  1. //+------------------------------------------------------------------+
  2. //| MetaTrader Server Interface |
  3. //| Copyright 2001-2015, MetaQuotes Software Corp. |
  4. //| http://www.metaquotes.net |
  5. //+------------------------------------------------------------------+
  6. //| DO NOT EDIT THIS FILE! |
  7. //+------------------------------------------------------------------+
  8. #pragma once
  9. #define ServerApiVersion 5
  10. //+------------------------------------------------------------------+
  11. //| Memory allocation macro |
  12. //+------------------------------------------------------------------+
  13. #define HEAP_ALLOC(size) HeapAlloc(GetProcessHeap(),0,size)
  14. #define HEAP_FREE(mem) HeapFree(GetProcessHeap(),0,mem)
  15. //+------------------------------------------------------------------+
  16. //| Structures |
  17. //+------------------------------------------------------------------+
  18. //| Information about plugin |
  19. //+------------------------------------------------------------------+
  20. struct PluginInfo
  21. {
  22. char name[128]; // plugin name
  23. unsigned int version; // plugin version
  24. char copyright[128]; // plugin copyright
  25. int reserved[32]; // reserved
  26. };
  27. //+------------------------------------------------------------------+
  28. //| Plugin configuration structure |
  29. //+------------------------------------------------------------------+
  30. struct PluginCfg
  31. {
  32. char name[32];
  33. char value[128];
  34. int reserved[16];
  35. };
  36. //+------------------------------------------------------------------+
  37. //| Server config structures |
  38. //+------------------------------------------------------------------+
  39. //| Access configuration |
  40. //+------------------------------------------------------------------+
  41. struct ConAccess
  42. {
  43. int action; // type of action (FW_BLOCK,FW_PERMIT)
  44. unsigned long from,to; // from, to addresses
  45. char comment[64]; // comment
  46. int reserved[17]; // reserved
  47. };
  48. //---
  49. enum { FW_BLOCK, FW_PERMIT, FW_WHITELIST };
  50. //+------------------------------------------------------------------+
  51. //| Common configuration |
  52. //+------------------------------------------------------------------+
  53. struct ConCommon
  54. {
  55. char owner[128]; // servers owner (include version & build)
  56. char name[32]; // server name
  57. ULONG address; // IP address assigned to the server
  58. int port; // port
  59. DWORD timeout; // sockets timeout
  60. int enable_demo; // enable demo DEMO_DISABLED, DEMO_PROLONG, DEMO_FIXED
  61. int timeofdemo; // demo-account living time (days since last connect)
  62. int daylightcorrection; // allow daylight correction
  63. char internal[60]; // reserved
  64. int timezone_real; // time zone with day light mode
  65. int timezone; // time zone 0-GMT;-1=GMT-1;1=GMT+1;
  66. char timesync[64]; // time synchronization server address
  67. //---
  68. int minclient; // minimal authorized client version
  69. int minapi; // minimal authorized client version
  70. DWORD feeder_timeout; // data feed switch timeout
  71. int keepemails; // internal mail keep period
  72. int endhour,endminute; // end of day time-hour & minute
  73. //---
  74. int optimization_time; // optimization start time (minutes)
  75. int optimization_lasttime; // optimization last time
  76. int optimization_counter; // internal variable
  77. int optimization_unused[8];// reserved for future use
  78. //---
  79. int antiflood; // enable antiflood control
  80. int floodcontrol; // max. antiflood connections
  81. //---
  82. int liveupdate_mode; // LiveUpdate mode LIVE_UPDATE_NO,LIVE_UPDATE_ALL,LIVE_UPDATE_NO_SERVER
  83. //---
  84. int lastorder; // last order's ticket (read only)
  85. int lastlogin; // last account's number (read only)
  86. int lostlogin; // lost commission's login (read only)
  87. //---
  88. int rollovers_mode; // rollover mode (ROLLOVER_NORMAL,ROLLOVER_REOPEN_BY_CLOSE_PRICE,ROLLOVER_REOPEN_BY_BID)
  89. //---
  90. char path_database[256]; // path to databases
  91. char path_history[256]; // path to history bases
  92. char path_log[256]; // path to log
  93. //--- overnigths
  94. time_t overnight_last_day; // day of last overnight
  95. time_t overnight_last_time; // time of last overnight
  96. time_t overnight_prev_time; // time of previous overnight
  97. //--- month reports
  98. time_t overmonth_last_month; // time of last report
  99. //--- performance base
  100. char adapters[256]; // network adapters list (read-only)
  101. ULONG bind_adresses[8]; // array of available IP addresses
  102. short server_version; // server version (filled by server)
  103. short server_build; // server build (filled by server)
  104. ULONG web_adresses[8]; // array of IP addresses available for Web services
  105. int statement_mode; // statements generation mode STATEMENT_END_DAY, STATEMENT_START_DAY
  106. int monthly_state_mode; // monthly generation enumeration MONTHLY_STATEMENT_END_MONTH, MONTHLY_STATEMENT_START_MONTH
  107. int keepticks; // ticks keep period
  108. int statement_weekend; // generate statements at weekends
  109. time_t last_activate; // last activation datetime
  110. time_t stop_last; // last stop datetime
  111. int stop_delay; // last stop delay
  112. int stop_reason; // last stop reason STOP_REASON_NONE, STOP_REASON_RESTART, STOP_REASON_SHUTDOWN, STOP_REASON_LIVEUPDATE
  113. char account_url[128]; // account allocation URL
  114. int reserved[16];
  115. };
  116. //+------------------------------------------------------------------+
  117. //| Time config |
  118. //+------------------------------------------------------------------+
  119. struct ConTime
  120. {
  121. int days[7][24]; // server's accessebility(7 days-24 hours, 0-denied, 1-allowed)
  122. int dayscontrol; // internal variable
  123. int reserved[3]; // reserved
  124. };
  125. //+------------------------------------------------------------------+
  126. //| Backup configuration |
  127. //+------------------------------------------------------------------+
  128. struct ConBackup
  129. {
  130. //---
  131. char fullbackup_path[256]; // path to backup
  132. int fullbackup_period; // full backup's period-BACKUP_1HOUR, BACKUP_4HOURS, BACKUP_1DAY
  133. int fullbackup_store; // full backup's store time-BU_STORE_1MONTH, BU_STORE_3MONTHS, BU_STORE_6MONTHS,BU_STORE_1YEAR
  134. time_t fullbackup_lasttime; // full backup's last execution time
  135. short fullbackup_shift; // full backup timeshift (minutes)
  136. //---
  137. char external_path[256]; // path to external processing directory
  138. //---
  139. int archive_period; // period of archive backup-ARC_BACKUP_5MIN, ARC_BACKUP_15MIN, ARC_BACKUP_30MIN, ARC_BACKUP_1HOUR
  140. int archive_store; // archive backup's store time-ARC_STORE_1WEEK, ARC_STORE_2WEEKS, ARC_STORE_1MONTH, ARC_STORE_3MONTH, ARC_STORE_6MONTH
  141. time_t archive_lasttime; // archive backup's last execution time
  142. //---
  143. char export_securities[512];// comma separated list of exported securities
  144. char export_path[256]; // path to export script
  145. int export_period; // export period-enumeration EXPORT_1MIN, EXPORT_5MIN, EXPORT_15MIN, EXPORT_30MIN,EXPORT_1HOUR
  146. time_t export_lasttime; // export's last execution time
  147. //--- watch dog
  148. int watch_role; // server role WATCH_STAND_ALONE, WATCH_MASTER, WATCH_SLAVE
  149. char watch_password[16]; // watch dog password
  150. char watch_opposite[24]; // opposite server address
  151. unsigned long watch_ip; // opposite server IP
  152. //---
  153. char archive_shift; // shift of archive backup time (in minutes)
  154. //---
  155. char watch_state; // watch dog state WS_DISCONNECTED, WS_SYNCHRONIZING, WS_SYNCHRONIZED
  156. char watch_failover; // watch dog failover mode
  157. unsigned char watch_timeout; // watch dog timeout
  158. int watch_login; // watch dog login
  159. time_t watch_timestamp; // watch dog timestamp
  160. };
  161. //--- full backup execution periods: 1 hour, 4 hours, 1 day
  162. enum { BACKUP_1HOUR, BACKUP_4HOURS, BACKUP_1DAY };
  163. //--- arc. backup execution periods: 5 min, 15 min, 30 min, 1 hour
  164. enum { ARC_BACKUP_DISABLED, ARC_BACKUP_5MIN, ARC_BACKUP_15MIN, ARC_BACKUP_30MIN, ARC_BACKUP_1HOUR };
  165. //--- arc. backup store period: 1 month,3 months, 6 months,1 year
  166. enum { ARC_STORE_1DAY, ARC_STORE_3DAYS, ARC_STORE_1WEEK, ARC_STORE_2WEEKS, ARC_STORE_1MONTH, ARC_STORE_3MONTH, ARC_STORE_6MONTH };
  167. //--- export execution period: 1 min, 5 min, 15 min, 30 min, 1 hour
  168. enum { EXPORT_1MIN, EXPORT_5MIN, EXPORT_15MIN, EXPORT_30MIN,EXPORT_1HOUR };
  169. //--- rollover mode
  170. enum { ROLLOVER_NORMAL, ROLLOVER_REOPEN_BY_CLOSE_PRICE, ROLLOVER_REOPEN_BY_BID };
  171. //--- statement generate mode
  172. enum { STATEMENT_END_DAY, STATEMENT_START_DAY };
  173. //--- server role
  174. enum { WATCH_STAND_ALONE, WATCH_MASTER, WATCH_SLAVE };
  175. //--- live update modes
  176. enum { LIVE_UPDATE_NO, LIVE_UPDATE_RELEASE, LIVE_UPDATE_NO_SERVER, LIVE_UPDATE_BETA };
  177. //--- demo modes
  178. enum { DEMO_DISABLED, DEMO_PROLONG, DEMO_FIXED };
  179. //--- monthly statement mode
  180. enum { MONTHLY_STATEMENT_END_MONTH, MONTHLY_STATEMENT_START_MONTH };
  181. //--- watchdog state
  182. enum { WS_DISCONNECTED, WS_SYNCHRONIZING, WS_SYNCHRONIZED };
  183. //--- watchdog failover mode
  184. enum { FAILOVER_OFF, FAILOVER_MOST, FAILOVER_FULL };
  185. //--- server stop reason
  186. enum { STOP_REASON_NONE, STOP_REASON_RESTART, STOP_REASON_SHUTDOWN, STOP_REASON_LIVEUPDATE };
  187. //+------------------------------------------------------------------+
  188. //| Datafeed configuration |
  189. //+------------------------------------------------------------------+
  190. struct ConFeeder
  191. {
  192. char name[64]; // name
  193. char file[256]; // datafeed filename
  194. char server[64]; // server address
  195. char login[32]; // datafeed login
  196. char pass[32]; // datafeed password
  197. char keywords[256]; // keywords (news filtration)
  198. int enable; // enable feeder
  199. int mode; // datafeed mode-enumeration FEED_QUOTES, FEED_NEWS, FEED_QUOTESNEWS
  200. int timeout; // max. freeze time (default ~120 sec.)
  201. int timeout_reconnect; // reconnect timeout before attemps_sleep connect attempts (default ~ 5 sec)
  202. int timeout_sleep; // reconnect timeout after attemps_sleep connect attempts (default ~ 60 sec)
  203. int attemps_sleep; // reconnect count (see timeout_reconnect & timeout_sleep)
  204. int news_langid; // news language id
  205. int unused[33]; // reserved
  206. };
  207. //--- datafeed modes-receive quotes, receive news, receive quotes and news
  208. enum { FEED_QUOTES=0, FEED_NEWS=1, FEED_QUOTESNEWS=2 };
  209. //+------------------------------------------------------------------+
  210. //| Security group configuration for client group |
  211. //+------------------------------------------------------------------+
  212. #define MAX_SEC_GROUPS (32)
  213. #define MAX_SEC_GROPS_MARGIN (128)
  214. //---
  215. struct ConGroupSec
  216. {
  217. int show,trade; // enable show and trade for this group of securites
  218. int execution; // dealing mode-EXECUTION_MANUAL,EXECUTION_AUTO,EXECUTION_ACTIVITY
  219. //--- comission settings
  220. double comm_base; // standart commission
  221. int comm_type; // commission type-COMM_TYPE_MONEY,COMM_TYPE_PIPS,COMM_TYPE_PERCENT
  222. int comm_lots; // commission lots mode-COMMISSION_PER_LOT,COMMISSION_PER_DEAL
  223. double comm_agent; // agent commission
  224. int comm_agent_type; // agent commission mode-COMM_TYPE_MONEY, COMM_TYPE_PIPS
  225. //---
  226. int spread_diff; // spread difference in compare with default security spread
  227. //---
  228. int lot_min,lot_max; // allowed minimal and maximal lot values
  229. int lot_step; // allowed step value (10 lot-1000, 1 lot-100, 0.1 lot-10)
  230. int ie_deviation; // maximum price deviation in Instant Execution mode
  231. int confirmation; // use confirmation in Request mode
  232. int trade_rights; // clients trade rights-bit mask see TRADE_DENY_NONE,TRADE_DENY_CLOSEBY,TRADE_DENY_MUCLOSEBY
  233. int ie_quick_mode; //
  234. int autocloseout_mode; // auto close-out modes see CLOSE_OUT_NONE,CLOSE_OUT_HIHI, CLOSE_OUT_LOLO, CLOSE_OUT_HILO, CLOSE_OUT_LOHI,CLOSE_OUT_LOHI,CLOSE_OUT_FIFO,CLOSE_OUT_LIFO,CLOSE_OUT_INTRDAY_FIFO
  235. double comm_tax; // commission taxes
  236. int comm_agent_lots; // agent commission lots mode-COMMISSION_PER_LOT,COMMISSION_PER_DEAL
  237. int freemargin_mode; // free margin check mode
  238. //--- ðåçåðâ
  239. int reserved[3];
  240. };
  241. //+------------------------------------------------------------------+
  242. //| Special securities configurations |
  243. //+------------------------------------------------------------------+
  244. struct ConGroupMargin
  245. {
  246. char symbol[12]; // security
  247. double swap_long,swap_short; // swap size for long and short positions
  248. double margin_divider; // margin divider
  249. int reserved[7];
  250. };
  251. //--- dealing mode
  252. enum { EXECUTION_MANUAL, EXECUTION_AUTO, EXECUTION_ACTIVITY };
  253. //--- commission type
  254. enum { COMM_TYPE_MONEY, COMM_TYPE_PIPS, COMM_TYPE_PERCENT };
  255. //--- comission lots mode
  256. enum { COMMISSION_PER_LOT, COMMISSION_PER_DEAL };
  257. //--- clients trade rights
  258. enum { TRADE_DENY_NONE=0, TRADE_DENY_CLOSEBY=1, TRADE_DENY_MUCLOSEBY=2 };
  259. //--- auto close-out modes
  260. enum { CLOSE_OUT_NONE, CLOSE_OUT_HIHI, CLOSE_OUT_LOLO, CLOSE_OUT_HILO, CLOSE_OUT_LOHI, CLOSE_OUT_FIFO, CLOSE_OUT_LIFO, CLOSE_OUT_INTRDAY_FIFO };
  261. //+------------------------------------------------------------------+
  262. //| Client group configuration |
  263. //+------------------------------------------------------------------+
  264. struct ConGroup
  265. {
  266. //--- common settings
  267. char group[16]; // group name
  268. int enable; // enable group
  269. int timeout; // trade confirmation timeout (seconds)
  270. int otp_mode; // one-time password mode
  271. //--- statements
  272. char company[128]; // company name
  273. char signature[128]; // statements signature
  274. char support_page[128]; // company support page
  275. char smtp_server[64]; // statements SMTP server
  276. char smtp_login[32]; // statements SMTP login
  277. char smtp_password[32]; // statements SMTP password
  278. char support_email[64]; // support email
  279. char templates[32]; // path to directory with custom templates
  280. int copies; // copy statements on support email
  281. int reports; // enable statements
  282. //--- default settings
  283. int default_leverage; // default leverage (user don't specify leverage himself)
  284. double default_deposit; // default deposit (user don't specify balance himself)
  285. //--- securities
  286. int maxsecurities; // maximum simultaneous securities
  287. ConGroupSec secgroups[MAX_SEC_GROUPS]; // security group settings
  288. ConGroupMargin secmargins[MAX_SEC_GROPS_MARGIN]; // special securities settings
  289. int secmargins_total; // count of special securities settings
  290. //--- margin & interest
  291. char currency[12]; // deposit currency
  292. double credit; // virtual credit
  293. int margin_call; // margin call level (percents)
  294. int margin_mode; // margin mode-MARGIN_DONT_USE,MARGIN_USE_ALL,MARGIN_USE_PROFIT,MARGIN_USE_LOSS
  295. int margin_stopout; // stop out level
  296. double interestrate; // annual interest rate (percents)
  297. int use_swap; // use rollovers & interestrate
  298. //--- rights
  299. int news; // news mode
  300. int rights; // rights bit mask-ALLOW_FLAG_EMAIL
  301. int check_ie_prices; // check by stream prices on IE
  302. int maxpositions; // open positions limit (0 - unlimited)
  303. int close_reopen; // partial close mode (if !=0 original position will be fully closed and remain position will be fully reopened)
  304. int hedge_prohibited; // hedge prohibition flag
  305. int close_fifo; // fifo rule
  306. int hedge_largeleg; // calculate hedged margin using larger leg
  307. int unused_rights[2]; // reserverd
  308. char securities_hash[16]; // internal data
  309. //---
  310. int margin_type; // stop out calculation mode { MARGIN_TYPE_PERCENT, MARGIN_TYPE_CURRENCY }
  311. //--- archive parameters
  312. int archive_period;
  313. int archive_max_balance;
  314. //--- stopout mode
  315. int stopout_skip_hedged;
  316. int archive_pending_period; // pendings clean period
  317. //--- allowed news languages
  318. UINT news_languages[8]; // LANGID array
  319. UINT news_languages_total; // news languages total
  320. //--- reserved
  321. int reserved[17];
  322. };
  323. //--- margin mode
  324. enum { MARGIN_MODE_DONT_USE,MARGIN_MODE_USE_ALL,MARGIN_MODE_USE_PROFIT,MARGIN_MODE_USE_LOSS };
  325. //--- stop out calculation mode
  326. enum { MARGIN_TYPE_PERCENT, MARGIN_TYPE_CURRENCY };
  327. //--- news mode-no news, only topics, full news (topic+body)
  328. enum { NEWS_NO, NEWS_TOPICS, NEWS_FULL };
  329. //--- group rights
  330. enum
  331. {
  332. ALLOW_FLAG_EMAIL =1,
  333. ALLOW_FLAG_TRAILING =2,
  334. ALLOW_FLAG_ADVISOR =4,
  335. ALLOW_FLAG_EXPIRATION =8,
  336. ALLOW_FLAG_SIGNALS_ALL =16,
  337. ALLOW_FLAG_SIGNALS_OWN =32,
  338. ALLOW_FLAG_RISK_WARNING =64,
  339. ALLOW_FLAG_FORCED_OTP_USAGE=128,
  340. };
  341. //--- group one-time password mode
  342. enum
  343. {
  344. OTP_MODE_DISABLED =0,
  345. OTP_MODE_TOTP_SHA256 =1,
  346. };
  347. //+------------------------------------------------------------------+
  348. //| Hollidays configuration |
  349. //+------------------------------------------------------------------+
  350. struct ConHoliday
  351. {
  352. int year; // year
  353. int month; // month
  354. int day; // day
  355. int from,to; // work time-from & to (minutes)
  356. char symbol[32]; // security name or symbol's group name or "All"
  357. char description[128]; // description
  358. int enable; // enable
  359. int reserved[13]; // reserved
  360. ConHoliday *next; // internal data
  361. };
  362. //+------------------------------------------------------------------+
  363. //| LiveUpdate configuration |
  364. //+------------------------------------------------------------------+
  365. #define LIVE_FILES_MAX 64
  366. //---
  367. struct LiveInfoFile
  368. {
  369. char file[256]; // file name
  370. int size; // file size
  371. char hash[36]; // file hash
  372. int reserved[10]; // reserved
  373. };
  374. //---
  375. struct ConLiveUpdate
  376. {
  377. char company[128]; // company
  378. char path[256]; // path to LiveUpdate
  379. int version; // version
  380. int build; // build
  381. int maxconnect; // max. simultaneous connections
  382. int connections; // current connections (read only)
  383. int type; // type LIVE_UPDATE_CLIENT, LIVE_UPDATE_MANAGER, LIVE_UPDATE_ADMIN
  384. int enable; // enable
  385. int totalfiles; // total files count
  386. LiveInfoFile files[LIVE_FILES_MAX]; // files' configurations
  387. int reserved[16]; // reserved
  388. ConLiveUpdate *next; // internal data
  389. };
  390. //--- LiveUpdate type
  391. enum { LIVE_UPDATE_CLIENT, LIVE_UPDATE_MANAGER, LIVE_UPDATE_ADMIN, LIVE_UPDATE_DATACENTER,
  392. LIVE_UPDATE_CLIENT_PPC2002, LIVE_UPDATE_CLIENT_PPC2003, LIVE_UPDATE_MULTI, LIVE_UPDATE_WD,
  393. LIVE_UPDATE_CLIENT_PHONE, LIVE_UPDATE_LAST };
  394. //+------------------------------------------------------------------+
  395. //| Manager rights for security groups |
  396. //+------------------------------------------------------------------+
  397. struct ConManagerSec
  398. {
  399. int internal; // internal data
  400. int enable; // enable
  401. int minimum_lots; // min. lots
  402. int maximum_lots; // max. lots
  403. int unused[16]; // reserved
  404. };
  405. //+------------------------------------------------------------------+
  406. //| Manager configuration |
  407. //+------------------------------------------------------------------+
  408. struct ConManager
  409. {
  410. int login; // login
  411. //--- rights
  412. int manager; // right to add & change client records
  413. int money; // right to balance & credit management
  414. int online; // right to see online users
  415. int riskman; // right to use analyzer
  416. int broker; // right to deal
  417. int admin; // right to server administration
  418. int logs; // right to see logs
  419. int reports; // right to see reports
  420. int trades; // right to add/modify/delete trades
  421. int market_watch; // right to change spread, spread balance, stop levels, execution mode and send quotes
  422. int email; // right to send internal mail
  423. int user_details; // right to see clients private data-name,country,address,phone,email etc.
  424. int see_trades; // right to see the trading acitivity
  425. int news; // right to send news
  426. int plugins; // right to control server plugins
  427. int server_reports; // right to receive server reports
  428. int techsupport; // right to access to technical support page
  429. int market; // right to access server applications market
  430. int notifications; // right to push notifications
  431. int unused[9];
  432. //--- IP filtration
  433. int ipfilter; // enable IP control
  434. unsigned long ip_from,ip_to; // range of allowed IPs
  435. //---
  436. char mailbox[64]; // name of mailbof for internal mail
  437. char groups[1024]; // comma separated list of managed groups (allowed '*' wildcard)
  438. ConManagerSec secgroups[MAX_SEC_GROUPS]; // manager rights for security groups
  439. DWORD exp_time; // internal data
  440. char name[32]; // manager name (filled from the corresponding UserRecord)
  441. int info_depth; // depth of avalaible information
  442. //---
  443. int reserved[22];
  444. };
  445. //+------------------------------------------------------------------+
  446. //| Security configurations |
  447. //+------------------------------------------------------------------+
  448. //+------------------------------------------------------------------+
  449. //| Security sessions configurations |
  450. //+------------------------------------------------------------------+
  451. struct ConSession
  452. {
  453. short open_hour,open_min; // session open time: hour & minute
  454. short close_hour,close_min; // session close time: hour & minute
  455. int open,close; // internal data
  456. short align[7]; // internal data
  457. };
  458. //---
  459. struct ConSessions
  460. {
  461. //---
  462. ConSession quote[3]; // quote sessions
  463. ConSession trade[3]; // trade sessions
  464. //---
  465. int quote_overnight; // internal data
  466. int trade_overnight; // internal data
  467. int reserved[2]; // reserved
  468. };
  469. //+------------------------------------------------------------------+
  470. //| Security config |
  471. //+------------------------------------------------------------------+
  472. #define MAX_SYMBOLS 1024
  473. //---
  474. struct ConSymbol
  475. {
  476. //--- common settings
  477. char symbol[12]; // name
  478. char description[64]; // description
  479. char source[12]; // synonym
  480. char currency[12]; // currency
  481. int type; // security group (see ConSymbolGroup)
  482. int digits; // security precision
  483. int trade; // trade mode
  484. //--- external settings
  485. COLORREF background_color; // background color
  486. int count; // symbols index
  487. int count_original; // symbols index in market watch
  488. int external_unused[7];
  489. //--- sessions
  490. int realtime; // allow real time quotes
  491. time_t starting; // trades starting date (UNIX time)
  492. time_t expiration; // trades end date (UNIX time)
  493. ConSessions sessions[7]; // quote & trade sessions
  494. //--- profits
  495. int profit_mode; // profit calculation mode
  496. int profit_reserved; // reserved
  497. //--- filtration
  498. int filter; // filter value
  499. int filter_counter; // filtration parameter
  500. double filter_limit; // max. permissible deviation from last quote (percents)
  501. int filter_smoothing; // smoothing
  502. float filter_reserved; // reserved
  503. int logging; // enable to log quotes
  504. //--- spread & swaps
  505. int spread; // spread
  506. int spread_balance; // spread balance
  507. int exemode; // execution mode
  508. int swap_enable; // enable swaps
  509. int swap_type; // swap type
  510. double swap_long,swap_short; // swaps values for long & short postions
  511. int swap_rollover3days; // triple rollover day 0-Sunday,1-Monday,2-Tuesday...
  512. double contract_size; // contract size
  513. double tick_value; // one tick value
  514. double tick_size; // one tick size
  515. int stops_level; // stops deviation value
  516. int gtc_pendings; // GTC mode ORDERS_DAILY, ORDERS_GTC, ORDERS_DAILY_NO_STOPS
  517. //--- margin calculation
  518. int margin_mode; // margin calculation mode
  519. double margin_initial; // initial margin
  520. double margin_maintenance; // margin maintenance
  521. double margin_hedged; // hedged margin
  522. double margin_divider; // margin divider
  523. //--- calclulated variables (internal data)
  524. double point; // point size-(1/(10^digits)
  525. double multiply; // multiply 10^digits
  526. double bid_tickvalue; // tickvalue for bid
  527. double ask_tickvalue; // tickvalue for ask
  528. //---
  529. int long_only; // allow only BUY positions
  530. int instant_max_volume; // max. volume for Instant Execution
  531. //---
  532. char margin_currency[12]; // currency of margin requirments
  533. int freeze_level; // modification freeze level (from market price)
  534. int margin_hedged_strong; // lock open checking mode
  535. time_t value_date; // value date for this security
  536. int quotes_delay; // quotes delay
  537. int swap_openprice; // use open price at swaps calculation in SWAP_BY_INTEREST mode
  538. int swap_variation_margin; // charge variation margin on rollover
  539. //---
  540. int unused[21]; // reserved
  541. };
  542. //+------------------------------------------------------------------+
  543. //| Symbols enumeration |
  544. //+------------------------------------------------------------------+
  545. //--- symbol execution mode
  546. enum { EXE_REQUEST,EXE_INSTANT,EXE_MARKET };
  547. //--- trade mode
  548. enum { TRADE_NO,TRADE_CLOSE,TRADE_FULL };
  549. //--- swap type
  550. enum { SWAP_BY_POINTS,SWAP_BY_DOLLARS, SWAP_BY_INTEREST, SWAP_BY_MARGIN_CURRENCY };
  551. //--- profit calculation mode
  552. enum { PROFIT_CALC_FOREX,PROFIT_CALC_CFD,PROFIT_CALC_FUTURES };
  553. //--- margin calculation mode
  554. enum { MARGIN_CALC_FOREX,MARGIN_CALC_CFD,MARGIN_CALC_FUTURES,MARGIN_CALC_CFDINDEX,MARGIN_CALC_CFDLEVERAGE };
  555. //--- GTC mode
  556. enum { ORDERS_DAILY, ORDERS_GTC, ORDERS_DAILY_NO_STOPS };
  557. //+------------------------------------------------------------------+
  558. //| Symbol groups |
  559. //+------------------------------------------------------------------+
  560. struct ConSymbolGroup
  561. {
  562. char name[16]; // group name
  563. char description[64]; // group description
  564. };
  565. //+------------------------------------------------------------------+
  566. //| Gateway configuration |
  567. //+------------------------------------------------------------------+
  568. //+------------------------------------------------------------------+
  569. //| Gateway account configuration |
  570. //+------------------------------------------------------------------+
  571. struct ConGatewayAccount
  572. {
  573. int enable; // enable flag 0 - disabled, 1 - enabled
  574. char name[64]; // public name
  575. int id; // internal id
  576. int type; // type (obsolete)
  577. int login; // STP MT4 login
  578. char address[64]; // MT4 server address
  579. char password[64]; // STP MT4 password
  580. int notify_logins[8]; // list of logins for internal email notification
  581. int flags; // flag fields
  582. int reserved[23]; // reserved
  583. };
  584. //--- gateway account flags
  585. enum EnGatewayAccountFlags { GATEWAY_FLAG_NONE=0, GATEWAY_FLAG_QUOTES=1 };
  586. //+------------------------------------------------------------------+
  587. //| Gateway markup configuration |
  588. //+------------------------------------------------------------------+
  589. struct ConGatewayMarkup
  590. {
  591. int enable; // enable flag 0 - disabled, 1 - enabled
  592. char source[128]; // source symbol\symbols mask\symbols group name
  593. char symbol[12]; // local symbol name
  594. char account_name[64]; // account name (obsolete)
  595. int account_id; // account internal id (obsolete)
  596. int bid_markup; // bid markup in pips
  597. int ask_markup; // ask markup in pips
  598. int reserved[16]; // reserved
  599. };
  600. //+------------------------------------------------------------------+
  601. //| Gateway rules configuration |
  602. //+------------------------------------------------------------------+
  603. struct ConGatewayRule
  604. {
  605. int enable; // enable flag 0 - disabled, 1 - enabled
  606. char name[64]; // public name
  607. char request_symbol[128]; // symbol\symbols mask\symbols group name
  608. char request_group[128]; // group name or group mask
  609. int request_reserved[32]; // reserved
  610. char exe_account_name[64]; // account name
  611. int exe_account_id; // account internal id
  612. int exe_max_deviation; // max. devation
  613. int exe_max_profit_slippage; // max profit slippage in pips
  614. int exe_max_profit_slippage_lots; // max profit slippage volume in lots
  615. int exe_max_losing_slippage; // max losing slippage in pips
  616. int exe_max_losing_slippage_lots; // max losing slippage volume in lots
  617. int exe_account_pos; // account current position
  618. int exe_volume_percent; // coverage percentage
  619. int exe_flags; // execution flags
  620. int exe_reserved[25]; // reserved
  621. };
  622. //+------------------------------------------------------------------+
  623. //| Gateway rules flags |
  624. //+------------------------------------------------------------------+
  625. enum EnGatewayRuleFlags
  626. {
  627. GATEWAY_RULE_FLAG_NONE =0, // none
  628. GATEWAY_RULE_FLAG_DEALER=1 // process dealer's trades
  629. };
  630. //+------------------------------------------------------------------+
  631. //| Feeder quote structure |
  632. //+------------------------------------------------------------------+
  633. #pragma pack(push,1)
  634. struct FeedTick
  635. {
  636. char symbol[16]; // security
  637. time_t ctm; // time (UNIX time)
  638. char bank[32]; // source bank
  639. double bid,ask; // bid/ask
  640. int feeder; // feeder index
  641. char reverved[8]; // reserved
  642. };
  643. //+------------------------------------------------------------------+
  644. //| Tick source constants for FeedTick::feeder |
  645. //+------------------------------------------------------------------+
  646. enum EnTickSources
  647. {
  648. TICK_SRC_DEALER_AUTO =-1, // tick placed as result of request confirmation with in_stream flag
  649. TICK_SRC_DEALER_MANUAL=-2, // tick placed manually by dealer
  650. TICK_SRC_GATEWAY =-128 // base value for gateway ticks
  651. // gateway index calculated like abs(TICK_SRC_GATEWAY-FeedTick::feeder)
  652. };
  653. //+------------------------------------------------------------------+
  654. //| Feeder data quote |
  655. //+------------------------------------------------------------------+
  656. struct FeedData
  657. {
  658. //--- quotes data
  659. FeedTick ticks[32]; // quotes array
  660. int ticks_count; // quotes count
  661. //--- news data
  662. char news_time[32]; // news time description
  663. char subject[256]; // news subject
  664. char category[64]; // news category
  665. char keywords[256]; // news keywords
  666. char *body; // news body
  667. int body_len; // news body len
  668. int body_maxlen; // max. body len
  669. //--- ðåçóëüòàòû îïåðàöèé
  670. int result; // work result
  671. char result_string[256]; // error description
  672. int feeder; // datafeed index
  673. int mode; // internal data
  674. int langid; // news LANGID
  675. char reserved[64]; // reserved
  676. };
  677. //+------------------------------------------------------------------+
  678. //| Extended news structure |
  679. //+------------------------------------------------------------------+
  680. #pragma pack(push,1)
  681. struct FeedNews
  682. {
  683. //--- constants
  684. enum constants
  685. {
  686. MAX_NEWS_BODY_LEN=15*1024*1024 // max. body len
  687. };
  688. //--- news topic flags
  689. enum EnNewsFlags
  690. {
  691. FLAG_PRIORITY =1, // priority flag
  692. FLAG_CALENDAR =2, // calendar item flag
  693. FLAG_MIME =4, // MIME news content
  694. FLAG_ALLOW_DEMO =8 // allow body for demo accounts
  695. };
  696. UINT language; // news language (WinAPI LANGID)
  697. wchar_t subject[256]; // news subject
  698. wchar_t category[256]; // news category
  699. UINT flags; // EnNewsFlags
  700. wchar_t *body; // body
  701. UINT body_len; // body length
  702. UINT languages_list[32]; // list of languages available for news
  703. INT64 datetime; // news time
  704. UINT reserved[30]; // reserved
  705. };
  706. #pragma pack(pop)
  707. //+------------------------------------------------------------------+
  708. //| Log record structure |
  709. //+------------------------------------------------------------------+
  710. struct LogInfo
  711. {
  712. int code; // error code-CmdOK,CmdTrade,CmdLogin,CmdWarn,CmdErr,CmdAtt
  713. char ip[64]; // IP address
  714. char msg[512]; // error description
  715. tm ctm; // time
  716. int unused[2]; // reserved
  717. };
  718. //---
  719. #pragma pack(pop)
  720. //--- error code
  721. enum { CmdOK,CmdTrade,CmdLogin,CmdWarn,CmdErr,CmdAtt };
  722. //+------------------------------------------------------------------+
  723. //| Log request record structure |
  724. //+------------------------------------------------------------------+
  725. struct LogRequest
  726. {
  727. char mode; // request mode
  728. time_t from; // from time
  729. time_t to; // to time
  730. char filter[64]; // filter
  731. };
  732. //--- log request type
  733. enum EnLogType { LOG_TYPE_STANDARD, LOG_TYPE_LOGINS, LOG_TYPE_TRADES, LOG_TYPE_ERRORS, LOG_TYPE_FULL };
  734. //+------------------------------------------------------------------+
  735. //| Perfomance database record |
  736. //+------------------------------------------------------------------+
  737. #pragma pack(push,1)
  738. struct PerformanceInfo
  739. {
  740. time_t ctm; // time
  741. short users; // connections count
  742. short cpu; // cpu usage
  743. int freemem; // free memory
  744. int network; // network usage byte per.sec.
  745. int sockets; // reserved
  746. };
  747. #pragma pack(pop)
  748. //+------------------------------------------------------------------+
  749. //| Client full description |
  750. //+------------------------------------------------------------------+
  751. struct UserRecord
  752. {
  753. //--- common settings
  754. int login; // login
  755. char group[16]; // group
  756. char password[16]; // password
  757. //--- access flags
  758. int enable; // enable
  759. int enable_change_password; // allow to change password
  760. int enable_read_only; // allow to open/positions (TRUE-may not trade)
  761. int enable_otp; // allow to use one-time password
  762. int enable_reserved[2]; // for future use
  763. //---
  764. char password_investor[16]; // read-only mode password
  765. char password_phone[32]; // phone password
  766. char name[128]; // name
  767. char country[32]; // country
  768. char city[32]; // city
  769. char state[32]; // state
  770. char zipcode[16]; // zipcode
  771. char address[96]; // address
  772. char lead_source[32]; // lead source
  773. char phone[32]; // phone
  774. char email[48]; // email
  775. char comment[64]; // comment
  776. char id[32]; // SSN (IRD)
  777. char status[16]; // status
  778. time_t regdate; // registration date
  779. time_t lastdate; // last coonection time
  780. //--- trade settings
  781. int leverage; // leverage
  782. int agent_account; // agent account
  783. time_t timestamp; // timestamp
  784. int last_ip; // last visit ip
  785. //--- òîðãîâûå äàííûå
  786. double balance; // balance
  787. double prevmonthbalance; // previous month balance
  788. double prevbalance; // previous day balance
  789. double credit; // credit
  790. double interestrate; // accumulated interest rate
  791. double taxes; // taxes
  792. double prevmonthequity; // previous month equity
  793. double prevequity; // previous day equity
  794. double reserved2[2]; // for future use
  795. //---
  796. char otp_secret[32]; // one-time password secret
  797. char secure_reserved[240]; // secure data reserved
  798. int send_reports; // enable send reports by email
  799. unsigned int mqid; // MQ client identificator
  800. COLORREF user_color; // color got to client (used by MT Manager)
  801. //---
  802. char unused[40]; // for future use
  803. char api_data[16]; // for APIs usage
  804. };
  805. //+------------------------------------------------------------------+
  806. //| Client short description |
  807. //+------------------------------------------------------------------+
  808. struct UserInfo
  809. {
  810. //--- common settings
  811. int login; // login
  812. char group[16]; // group
  813. char password[16]; // password
  814. char name[128]; // name
  815. char ip[16]; // IP address
  816. //--- access flags
  817. int enable; // enable
  818. int enable_change_password; // allow to change password
  819. int enable_read_only; // allow to open/positions (TRUE-may not trade)
  820. int flags; // internal data
  821. //--- trade parameters
  822. int leverage; // leverage
  823. int agent_account; // agent account
  824. //--- trade data
  825. double balance; // balance
  826. double credit; // credit
  827. double prevbalance; // previous day balance
  828. ConGroup grp; // client group
  829. };
  830. //+------------------------------------------------------------------+
  831. //| Rate history record |
  832. //+------------------------------------------------------------------+
  833. #pragma pack(push,1)
  834. struct RateInfo
  835. {
  836. time_t ctm; // time (UNIX)
  837. int open; // open price: 11987 => 119.87 (2 digits), 11987 => 1.1987 (4 digits)
  838. int high,low,close; // prices shift in points: open=11987 => open is 119.87; high=5 => open is 119.92
  839. double vol; // volume
  840. };
  841. #pragma pack(pop)
  842. //+------------------------------------------------------------------+
  843. //| Tick structure |
  844. //+------------------------------------------------------------------+
  845. struct TickAPI
  846. {
  847. time_t ctm; // time
  848. double bid,ask; // normalized bid & ask
  849. };
  850. //+------------------------------------------------------------------+
  851. //| Internal mail record |
  852. //+------------------------------------------------------------------+
  853. struct MailBoxHeader
  854. {
  855. time_t time; // receive time
  856. int sender; // sender login
  857. char from[64]; // sender description
  858. int to; // addressee login
  859. char subject[128]; // subject
  860. int read; // read flag
  861. char *body; // body
  862. int bodylen; // body len
  863. unsigned short min_build,max_build; // build limitations
  864. int reserved[1]; // reserved
  865. };
  866. //+------------------------------------------------------------------+
  867. //| Trade transaction structures |
  868. //+------------------------------------------------------------------+
  869. #pragma pack(push,1)
  870. struct TradeTransInfo
  871. {
  872. UCHAR type; // trade transaction
  873. char flags; // flags
  874. short cmd; // trade command
  875. int order,orderby; // order ticket,"order by" ticket
  876. char symbol[12]; // security
  877. int volume; // volume
  878. double price; // prices
  879. double sl,tp; // stop loss & take profit
  880. int ie_deviation; // deviation on Instant Execution
  881. char comment[32]; // comment
  882. time_t expiration; // expiration time (server time in UNIX format)
  883. int crc; // CRC
  884. };
  885. #pragma pack(pop)
  886. //--- trade transactions type
  887. enum
  888. {
  889. //---
  890. TT_PRICES_GET, // prices request
  891. TT_PRICES_REQUOTE, // prices requote (for internal usage)
  892. //--- client activity
  893. TT_ORDER_IE_OPEN=64, // open position at Instant Execution
  894. TT_ORDER_REQ_OPEN, // open position at Request Execution
  895. TT_ORDER_MK_OPEN, // open position at Market Execution
  896. TT_ORDER_PENDING_OPEN, // open pending order
  897. //---
  898. TT_ORDER_IE_CLOSE, // close position at Instant Execution
  899. TT_ORDER_REQ_CLOSE, // close position at Request Execution
  900. TT_ORDER_MK_CLOSE, // close position at Market Execution
  901. //---
  902. TT_ORDER_MODIFY, // modify position or pending order
  903. TT_ORDER_DELETE, // delete pending order
  904. TT_ORDER_CLOSE_BY, // close hedged positions
  905. TT_ORDER_CLOSE_ALL, // close all hedged positions for same security
  906. //--- manager activity
  907. TT_BR_ORDER_OPEN, // open order (by manager)
  908. TT_BR_ORDER_CLOSE, // close order (by manager)
  909. TT_BR_ORDER_DELETE, // delete ANY open position
  910. TT_BR_ORDER_CLOSE_BY, // close hedged positions (by manager)
  911. TT_BR_ORDER_CLOSE_ALL, // close all hedged positions for same security (by manager)
  912. TT_BR_ORDER_MODIFY, // modify position or pending order (by manager)
  913. TT_BR_ORDER_ACTIVATE, // activate pending order (by manager)
  914. TT_BR_ORDER_COMMENT, // comment order (by manager)
  915. TT_BR_BALANCE // change balance & credit (by manager)
  916. };
  917. //--- trade request flags
  918. enum EnReqFlags
  919. {
  920. TT_FLAG_NONE =0x00000000, // flags none
  921. TT_FLAG_SIGNAL =0x00000001, // placed by signal
  922. TT_FLAG_EXPERT =0x00000002, // placed by expert
  923. TT_FLAG_GATEWAY=0x00000004, // placed by gateway
  924. TT_FLAG_MOBILE =0x00000008, // placed by mobile terminal
  925. TT_FLAG_WEB =0x00000010, // placed by web terminal
  926. TT_FLAG_API =0x00000020, // placed by api
  927. };
  928. //--- trade commands
  929. enum { OP_BUY=0,OP_SELL,OP_BUY_LIMIT,OP_SELL_LIMIT,OP_BUY_STOP,OP_SELL_STOP,OP_BALANCE,OP_CREDIT };
  930. //+------------------------------------------------------------------+
  931. //| Request queue record |
  932. //+------------------------------------------------------------------+
  933. struct RequestInfo
  934. {
  935. //--- common info
  936. int id; // request id
  937. int status; // request status DC_EMPTY,DC_REQUEST,DC_LOCKED,DC_ANSWERED,DC_RESETED,DC_CANCELED
  938. DWORD time; // request time
  939. int manager; // login of manager who takes this request
  940. //--- client info
  941. int login; // client login
  942. char group[16]; // client group
  943. double balance; // client balance
  944. double credit; // client credit
  945. //--- processed trade transaction
  946. double prices[2]; // prices
  947. TradeTransInfo trade; // trade transaction
  948. int gw_volume; // gateway order volume
  949. int gw_order; // gateway order ticket
  950. short gw_price; // gateway order price deviation (pips) from request price
  951. short reserved;
  952. //--- internal data
  953. RequestInfo *prev,*next; // internal data
  954. };
  955. //--- request status
  956. enum { DC_EMPTY,DC_REQUEST,DC_LOCKED,DC_ANSWERED,DC_RESETED,DC_CANCELED };
  957. //+------------------------------------------------------------------+
  958. //| Trade record |
  959. //+------------------------------------------------------------------+
  960. #pragma pack(push,1)
  961. struct TradeRecord
  962. {
  963. int order; // order ticket
  964. int login; // owner's login
  965. char symbol[12]; // security
  966. int digits; // security precision
  967. int cmd; // trade command
  968. int volume; // volume
  969. time_t open_time; // open time
  970. int state; // trade record state
  971. double open_price; // open price
  972. double sl,tp; // stop loss & take profit
  973. time_t close_time; // close time
  974. int gw_volume; // gateway order volume
  975. time_t expiration; // pending order's expiration time
  976. char reason; // trade reason
  977. char conv_reserv[3]; // reserved fields
  978. double conv_rates[2]; // convertation rates from profit currency to group deposit currency
  979. // (first element-for open time, second element-for close time)
  980. double commission; // commission
  981. double commission_agent; // agent commission
  982. double storage; // order swaps
  983. double close_price; // close price
  984. double profit; // profit
  985. double taxes; // taxes value
  986. int magic; // special value used by client experts
  987. char comment[32]; // comment
  988. int gw_order; // gateway order ticket
  989. int activation; // used by MT Manager
  990. short gw_open_price; // gateway order price deviation (pips) from order open price
  991. short gw_close_price; // gateway order price deviation (pips) from order close price
  992. double margin_rate; // margin cinvertation rate (rate of convertation from margin currency to deposit one)
  993. time_t timestamp; // timestamp
  994. int api_data[4]; // for api usage
  995. TradeRecord *next; // internal data
  996. };
  997. #pragma pack(pop)
  998. //+------------------------------------------------------------------+
  999. //| Margin status structure |
  1000. //+------------------------------------------------------------------+
  1001. struct MarginLevel
  1002. {
  1003. int login; // login
  1004. int leverage; // leverage
  1005. int updated; // internal data
  1006. double balance; // balance+credit value
  1007. double margin; // margin requirments
  1008. double equity; // equity
  1009. };
  1010. //+------------------------------------------------------------------+
  1011. //| Overnight calculation data |
  1012. //+------------------------------------------------------------------+
  1013. struct OverNightData
  1014. {
  1015. ConSymbol symbol; // symbol
  1016. double point; // internal data
  1017. TradeRecord **trades; // internal data
  1018. int trades_total; // internal data
  1019. int trades_max; // internal data
  1020. };
  1021. //+------------------------------------------------------------------+
  1022. //| Daily report structure |
  1023. //+------------------------------------------------------------------+
  1024. struct DailyReport
  1025. {
  1026. int login; // login
  1027. time_t ctm; // daily report time
  1028. char group[16]; // user group
  1029. char bank[64]; // bank info (from UserRecord::Comment)
  1030. double balance_prev; // balance for previous day
  1031. double balance; // balance to the end for this day
  1032. double deposit; // sum of balance operations for this day
  1033. double credit; // sum of credit operations for this day
  1034. double profit_closed; // profit of the today closed positions (including swaps & commissions)
  1035. double profit; // floating profit/loss
  1036. double equity; // equity
  1037. double margin; // margin
  1038. double margin_free; // free margin
  1039. //--- internal data
  1040. int next;
  1041. int reserved[3];
  1042. };
  1043. //+------------------------------------------------------------------+
  1044. //| Client statement summary |
  1045. //+------------------------------------------------------------------+
  1046. struct StateReport
  1047. {
  1048. //--- closed positions info
  1049. double deposit; // Deposit/Withdrawal result
  1050. double credit; // Credit In/Out result
  1051. double closed_profit; // closed positions total profit
  1052. double closed_commission; // closed positions total commission
  1053. double closed_swap; // closed positions total swap
  1054. double closed_taxes; // closed positions total taxes
  1055. //--- open positions info
  1056. double profit; // profit
  1057. double commission; // commission
  1058. double swap; // swap
  1059. double equity; // Equity
  1060. double taxes; // taxes
  1061. double margin; // margin
  1062. double margin_free; // free margin
  1063. };
  1064. //+------------------------------------------------------------------+
  1065. //| Clients group info for statement |
  1066. //+------------------------------------------------------------------+
  1067. struct GroupState
  1068. {
  1069. ConGroup group;
  1070. UserRecord *users;
  1071. int users_total;
  1072. TradeRecord *trades;
  1073. int trades_total;
  1074. MarginLevel *margins;
  1075. int margins_total;
  1076. };
  1077. //+------------------------------------------------------------------+
  1078. //| Server access class |
  1079. //+------------------------------------------------------------------+
  1080. struct CServerInterface
  1081. {
  1082. virtual int __stdcall Version(void);
  1083. //--- common functions
  1084. virtual time_t __stdcall TradeTime(void);
  1085. //--- firewall config access
  1086. virtual int __stdcall AccessAdd(const int pos,const ConAccess *acc);
  1087. virtual int __stdcall AccessDelete(const int pos);
  1088. virtual int __stdcall AccessNext(const int pos,ConAccess *acc);
  1089. virtual int __stdcall AccessShift(const int pos,const int shift);
  1090. //--- common config access
  1091. virtual void __stdcall CommonGet(ConCommon *info);
  1092. virtual void __stdcall CommonSet(const ConCommon *info);
  1093. //--- time config access
  1094. virtual void __stdcall TimeGet(ConTime *info);
  1095. virtual void __stdcall TimeSet(const ConTime *info);
  1096. //--- backup config access
  1097. virtual void __stdcall BackupGet(ConBackup *info);
  1098. virtual int __stdcall BackupSet(const ConBackup *info);
  1099. //--- feeders config access
  1100. virtual int __stdcall FeedersAdd(const ConFeeder *feeder);
  1101. virtual int __stdcall FeedersDelete(const int pos);
  1102. virtual int __stdcall FeedersNext(const int pos,ConFeeder *feeder);
  1103. virtual int __stdcall FeedersGet(LPCSTR name,ConFeeder *feeder);
  1104. virtual int __stdcall FeedersShift(const int pos,const int shift);
  1105. virtual int __stdcall FeedersEnable(LPCSTR name,const int mode);
  1106. //--- groups config access
  1107. virtual int __stdcall GroupsAdd(ConGroup *group);
  1108. virtual int __stdcall GroupsDelete(const int pos);
  1109. virtual int __stdcall GroupsNext(const int pos,ConGroup *group);
  1110. virtual int __stdcall GroupsGet(LPCSTR name,ConGroup *group);
  1111. virtual int __stdcall GroupsShift(const int pos,const int shift);
  1112. //--- holidays config access
  1113. virtual int __stdcall HolidaysAdd(const int pos,ConHoliday *day);
  1114. virtual int __stdcall HolidaysDelete(const int pos);
  1115. virtual int __stdcall HolidaysNext(const int pos,ConHoliday *day);
  1116. virtual int __stdcall HolidaysShift(const int pos,const int shift);
  1117. //--- live update config access
  1118. virtual int __stdcall LiveUpdateAdd(ConLiveUpdate *live);
  1119. virtual int __stdcall LiveUpdateDelete(const int pos);
  1120. virtual int __stdcall LiveUpdateNext(const int pos,ConLiveUpdate *live);
  1121. virtual int __stdcall LiveUpdateGet(LPCSTR server,const int type,ConLiveUpdate *live);
  1122. //--- managers config access
  1123. virtual int __stdcall ManagersAdd(ConManager *man);
  1124. virtual int __stdcall ManagersDelete(const int pos);
  1125. virtual int __stdcall ManagersNext(const int pos,ConManager *manager);
  1126. virtual int __stdcall ManagersGet(const int login,ConManager *manager);
  1127. virtual int __stdcall ManagersShift(const int pos,const int shift);
  1128. virtual int __stdcall ManagersIsDemo(LPCSTR group,LPCSTR sec,const int volume);
  1129. //--- symbols config access
  1130. virtual int __stdcall SymbolsAdd(ConSymbol *sec);
  1131. virtual int __stdcall SymbolsDelete(const int pos);
  1132. virtual int __stdcall SymbolsNext(const int pos, ConSymbol *sec);
  1133. virtual int __stdcall SymbolsGet(LPCSTR symbol,ConSymbol *security);
  1134. virtual int __stdcall SymbolsShift(const int pos,const int shift);
  1135. virtual int __stdcall SymbolsGroupsGet(const int index, ConSymbolGroup* group);
  1136. virtual int __stdcall SymbolsGroupsSet(const int index, ConSymbolGroup* group);
  1137. //--- log access
  1138. virtual void __stdcall LogsOut(const int code,LPCSTR ip,LPCSTR msg);
  1139. //--- client base access-you should use HEAP_FREE on resulted arrays
  1140. virtual int __stdcall ClientsTotal(void);
  1141. virtual int __stdcall ClientsAddUser(UserRecord *inf);
  1142. virtual int __stdcall ClientsDeleteUser(const int login);
  1143. virtual int __stdcall ClientsUserInfo(const int login,UserRecord *inf);
  1144. virtual int __stdcall ClientsUserUpdate(const UserRecord *inf);
  1145. virtual int __stdcall ClientsCheckPass(const int login,LPCSTR password,const int investor);
  1146. virtual int __stdcall ClientsChangePass(const int login,LPCSTR password,const int change_investor,const int drop_key);
  1147. virtual int __stdcall ClientsChangeBalance(const int login,const ConGroup *grp,const double value,LPCSTR comment);
  1148. virtual int __stdcall ClientsChangeCredit(const int login,const ConGroup *grp,const double value,const time_t date,LPCSTR comment);
  1149. virtual UserRecord* __stdcall ClientsAllUsers(int *totalusers);
  1150. virtual UserRecord* __stdcall ClientsGroupsUsers(int *totalusers,LPCSTR groups);
  1151. //--- request base access
  1152. virtual int __stdcall RequestsAdd(RequestInfo *request,const int isdemo,int *request_id);
  1153. virtual int __stdcall RequestsGet(int *key,RequestInfo *req,const int maxreq);
  1154. virtual int __stdcall RequestsFindObsolete(const int login,LPCSTR symbol,const int volume,double *prices,DWORD *ctm,int *manager);
  1155. virtual int __stdcall RequestsPrices(const int id,const UserInfo *us,double *prices,const int in_stream);
  1156. virtual int __stdcall RequestsConfirm(const int id,const UserInfo *us,double *prices);
  1157. virtual int __stdcall RequestsRequote(const int id,const UserInfo *us,double *prices,const int in_stream);
  1158. virtual int __stdcall RequestsReset(const int id,const UserInfo *us,const char flag);
  1159. //--- orders base access-you should use HEAP_FREE on resulted arrays
  1160. virtual int __stdcall OrdersAdd(const TradeRecord *start,UserInfo* user,const ConSymbol *symb);
  1161. virtual int __stdcall OrdersUpdate(TradeRecord *order,UserInfo* user,const int mode);
  1162. //---
  1163. virtual int __stdcall OrdersGet(const int ticket,TradeRecord *order);
  1164. virtual TradeRecord*__stdcall OrdersGet(const time_t from,const time_t to,const int *logins,const int count,int* total);
  1165. virtual TradeRecord*__stdcall OrdersGetOpen(const UserInfo* user,int* total);
  1166. virtual TradeRecord*__stdcall OrdersGetClosed(const time_t from,const time_t to,const int *logins,const int count,int* total);
  1167. //--- trade info access
  1168. virtual int __stdcall TradesCalcProfit(LPCSTR group,TradeRecord *tpi);
  1169. virtual int __stdcall TradesMarginInfo(UserInfo *user,double *margin,double *freemargin,double *equity);
  1170. //--- history center access-you should use HEAP_FREE on resulted arrays
  1171. virtual void __stdcall HistoryAddTick(FeedData *tick);
  1172. virtual int __stdcall HistoryLastTicks(LPCSTR symbol,TickAPI *ticks,const int ticks_max);
  1173. virtual int __stdcall HistoryPrices(LPCSTR symbol,double *prices,time_t *ctm,int *dir);
  1174. virtual int __stdcall HistoryPricesGroup(LPCSTR symbol,const ConGroup *grp,double *prices);
  1175. virtual int __stdcall HistoryPricesGroup(RequestInfo *request,double *prices);
  1176. virtual int __stdcall HistoryUpdateObsolete(LPCSTR symbol,const int period,void *rt,const int total,const int updatemode);
  1177. virtual void* __stdcall HistoryQuotesObsolete(LPCSTR symbol,const int period,int *count);
  1178. virtual void __stdcall HistorySync(void);
  1179. //--- mail&news base access
  1180. virtual int __stdcall MailSend(MailBoxHeader *mail,int *logins,const int total);
  1181. virtual int __stdcall NewsSend(FeedData *feeddata);
  1182. //--- main server access
  1183. virtual void __stdcall ServerRestart(void);
  1184. //--- daily base access-you should use HEAP_FREE on resulted arrays!
  1185. virtual DailyReport* __stdcall DailyGet(LPCSTR group,const time_t from,const time_t to,int* logins,const int logins_total,int *daily_total);
  1186. //--- select & free request from request queue
  1187. virtual int __stdcall RequestsLock(const int id,const int manager);
  1188. virtual int __stdcall RequestsFree(const int id,const int manager);
  1189. //--- check available margin
  1190. virtual double __stdcall TradesMarginCheck(const UserInfo *user,const TradeTransInfo *trade,double *profit,double *freemargin,double *prev_margin);
  1191. //--- high level order operations
  1192. virtual int __stdcall OrdersOpen(const TradeTransInfo *trans,UserInfo *user);
  1193. virtual int __stdcall OrdersClose(const TradeTransInfo *trans,UserInfo *user);
  1194. virtual int __stdcall OrdersCloseBy(const TradeTransInfo *trans,UserInfo *user);
  1195. //--- additional trade functions
  1196. virtual double __stdcall TradesCalcRates(LPCSTR group,LPCSTR from,LPCSTR to);
  1197. virtual double __stdcall TradesCalcConvertation(LPCSTR group,const int margin_mode,const double price,const ConSymbol *symbol);
  1198. virtual double __stdcall TradesCommissionAgent(TradeRecord *trade,const ConSymbol *symbol,const UserInfo *user);
  1199. virtual void __stdcall TradesCommission(TradeRecord *trade,LPCSTR group,const ConSymbol *symbol);
  1200. virtual int __stdcall TradesFindLogin(const int order);
  1201. //--- special checks
  1202. virtual int __stdcall TradesCheckSessions(const ConSymbol *symbol,const time_t ctm);
  1203. virtual int __stdcall TradesCheckStops(const TradeTransInfo *trans,const ConSymbol *symbol,const ConGroup *group,const TradeRecord *trade);
  1204. virtual int __stdcall TradesCheckFreezed(const ConSymbol *symbol,const ConGroup *group,const TradeRecord *trade);
  1205. virtual int __stdcall TradesCheckSecurity(const ConSymbol *symbol,const ConGroup *group);
  1206. virtual int __stdcall TradesCheckVolume(const TradeTransInfo *trans,const ConSymbol *symbol,const ConGroup *group,const int check_min);
  1207. virtual int __stdcall TradesCheckTickSize(const double price,const ConSymbol *symbol);
  1208. //--- extension
  1209. virtual int __stdcall RequestsFind(const int login,LPCSTR symbol,const int volume,const UCHAR type,const UCHAR cmd,double *prices,DWORD *ctm,int *manager);
  1210. virtual int __stdcall HistoryUpdate(LPCSTR symbol,const int period,RateInfo *rt,const int total,const int updatemode);
  1211. virtual RateInfo* __stdcall HistoryQuotes(LPCSTR symbol,const int period,int *count);
  1212. //--- tick database access
  1213. virtual TickAPI* __stdcall HistoryTicksGet(LPCSTR symbol,const time_t from,const time_t to,const char ticks_flags,int* total);
  1214. //--- request server logs
  1215. virtual char* __stdcall LogsRequest(const LogRequest *request,int *size);
  1216. //--- check account's balance
  1217. virtual int __stdcall ClientsCheckBalance(const int login,int fix_flag,double* difference);
  1218. //--- request base access
  1219. virtual int __stdcall RequestsConfirmPrice(const int id,const UserInfo *us,double price,double *prices);
  1220. //--- check plugin license
  1221. virtual int __stdcall LicenseCheck(LPCSTR license_name);
  1222. //--- gateway account config access
  1223. virtual int __stdcall GatewayAccountsAdd(ConGatewayAccount *cfg);
  1224. virtual int __stdcall GatewayAccountsDelete(const int pos);
  1225. virtual int __stdcall GatewayAccountsNext(const int pos, ConGatewayAccount *cfg);
  1226. virtual int __stdcall GatewayAccountsShift(const int pos,const int shift);
  1227. //--- gateway account config markups
  1228. virtual int __stdcall GatewayMarkupsAdd(ConGatewayMarkup *cfg);
  1229. virtual int __stdcall GatewayMarkupsDelete(const int pos);
  1230. virtual int __stdcall GatewayMarkupsNext(const int pos, ConGatewayMarkup *cfg);
  1231. virtual int __stdcall GatewayMarkupsShift(const int pos,const int shift);
  1232. //--- gateway account config rules
  1233. virtual int __stdcall GatewayRulesAdd(ConGatewayRule *cfg);
  1234. virtual int __stdcall GatewayRulesDelete(const int pos);
  1235. virtual int __stdcall GatewayRulesNext(const int pos, ConGatewayRule *cfg);
  1236. virtual int __stdcall GatewayRulesShift(const int pos,const int shift);
  1237. //--- notifications
  1238. virtual int __stdcall NotificationsSend(LPCWSTR metaquotes_ids,LPCWSTR message);
  1239. virtual int __stdcall NotificationsSend(const int* logins,const UINT logins_total,LPCWSTR message);
  1240. //--- request base - delete request from queue by ID
  1241. virtual int __stdcall RequestsDelete(const int id);
  1242. //--- trade info access with userinfo request
  1243. virtual int __stdcall TradesMarginGet(const int login,UserInfo* user,double *margin,double *freemargin,double *equity);
  1244. };
  1245. //+------------------------------------------------------------------+
  1246. //| Function parameters enumerations |
  1247. //+------------------------------------------------------------------+
  1248. //--- login types
  1249. enum
  1250. {
  1251. LOGIN_FLAG_CLIENT =0,
  1252. LOGIN_FLAG_MOBILE =1,
  1253. LOGIN_FLAG_MULTI =2,
  1254. LOGIN_FLAG_DC =3,
  1255. LOGIN_FLAG_ADMIN =4,
  1256. LOGIN_FLAG_MANAGER =5,
  1257. LOGIN_FLAG_MANAPI =6,
  1258. LOGIN_FLAG_WD =7,
  1259. LOGIN_FLAG_PHONE =8,
  1260. LOGIN_FLAG_WEB =9,
  1261. LOGIN_FLAG_IPHONE =10,
  1262. LOGIN_FLAG_ANDROID =11
  1263. };
  1264. //--- avaible history periods enumeration
  1265. enum { PERIOD_M1=1,PERIOD_M5=5,PERIOD_M15=15,PERIOD_M30=30,PERIOD_H1=60,PERIOD_H4=240,PERIOD_D1=1440,PERIOD_W1=10080,PERIOD_MN1=43200 };
  1266. //--- history updating modes
  1267. enum { HB_ADD,HB_UPDATE,HB_INSERT,HB_DELETE };
  1268. //--- trade add modes
  1269. enum { OPEN_NEW, OPEN_CLOSE, OPEN_RESTORE, OPEN_API, OPEN_ROLLOVER };
  1270. //--- trade update modes
  1271. enum { UPDATE_NORMAL, UPDATE_ACTIVATE, UPDATE_CLOSE, UPDATE_DELETE };
  1272. //--- trade record state
  1273. enum { TS_OPEN_NORMAL, TS_OPEN_REMAND, TS_OPEN_RESTORED, TS_CLOSED_NORMAL, TS_CLOSED_PART, TS_CLOSED_BY, TS_DELETED };
  1274. //--- trade record reasons
  1275. enum { TR_REASON_CLIENT, TR_REASON_EXPERT, TR_REASON_DEALER,TR_REASON_SIGNAL, TR_REASON_GATEWAY, TR_REASON_MOBILE, TR_REASON_WEB, TR_REASON_API };
  1276. //--- ticks record flags
  1277. enum { TICK_FLAG_RAW=1, TICK_FLAG_NORMAL=2 };
  1278. //+------------------------------------------------------------------+
  1279. //| MT Server API Hook Functions |
  1280. //+------------------------------------------------------------------+
  1281. //+------------------------------------------------------------------+
  1282. //| Plugin information |
  1283. //+------------------------------------------------------------------+
  1284. void APIENTRY MtSrvAbout(PluginInfo* info);
  1285. int APIENTRY MtSrvStartup(CServerInterface *server);
  1286. void APIENTRY MtSrvCleanup(void);
  1287. //+------------------------------------------------------------------+
  1288. //| Plugin configuration |
  1289. //+------------------------------------------------------------------+
  1290. int APIENTRY MtSrvPluginCfgSet(const PluginCfg *values,const int total);
  1291. int APIENTRY MtSrvPluginCfgNext(const int index,PluginCfg *value);
  1292. int APIENTRY MtSrvPluginCfgTotal();
  1293. //+------------------------------------------------------------------+
  1294. //| Auxiliary Server Hook Functions |
  1295. //+------------------------------------------------------------------+
  1296. void APIENTRY MtSrvLog(const LogInfo *info);
  1297. void APIENTRY MtSrvScheduler(const time_t curtime);
  1298. void APIENTRY MtSrvPerformance(const PerformanceInfo *inf);
  1299. void APIENTRY MtSrvService(const DWORD curtime);
  1300. //+------------------------------------------------------------------+
  1301. //| Client base Hook Functions |
  1302. //+------------------------------------------------------------------+
  1303. int APIENTRY MtSrvUserConnect(const unsigned long ip,LPCSTR ipstring);
  1304. int APIENTRY MtSrvUserLogin(const UserInfo *info);
  1305. void APIENTRY MtSrvUserLogout(const UserInfo *info,const UCHAR type);
  1306. int APIENTRY MtSrvUserLoginExt(const UserInfo *info,const UCHAR type);
  1307. int APIENTRY MtSrvUserDemo(UserRecord *info);
  1308. int APIENTRY MtSrvUserCommand(const UserInfo *info,ULONG ip,const unsigned char command);
  1309. int APIENTRY MtSrvUserChangePass(const UserInfo *info,LPCSTR password,const int change_investor);
  1310. int APIENTRY MtSrvUserChangePassExt(const UserInfo *info,LPCSTR password,const int change_investor);
  1311. void APIENTRY MtSrvUserAdd(const UserRecord *info);
  1312. void APIENTRY MtSrvUserUpdate(const UserRecord *info);
  1313. void APIENTRY MtSrvUserDelete(const UserRecord *info);
  1314. int APIENTRY MtSrvUserArchive(const UserRecord *info,const ConGroup *group);
  1315. void APIENTRY MtSrvUserCompactDemo(const UserRecord *info);
  1316. void APIENTRY MtSrvUserCompactArchive(const UserRecord *info);
  1317. void APIENTRY MtSrvUserRestore(const UserRecord *info);
  1318. int APIENTRY MtSrvUserInterestDaily(UserRecord *user,const ConGroup *group,const double freemargin);
  1319. int APIENTRY MtSrvUserInterestMonth(UserRecord *user,const ConGroup *group);
  1320. void APIENTRY MtSrvUserFixBalance(const UserRecord *user,const double prev_balance,const double new_balance);
  1321. //+------------------------------------------------------------------+
  1322. //| Datafeed Hook Functions |
  1323. //+------------------------------------------------------------------+
  1324. void APIENTRY MtSrvFeederData(const ConFeeder *feed,FeedData *inf);
  1325. int APIENTRY MtSrvFeederStart(const ConFeeder *feed);
  1326. int APIENTRY MtSrvFeederCheck(const ConFeeder *feed,const DWORD curtime,const DWORD lasttime);
  1327. void APIENTRY MtSrvFeederStop(const ConFeeder *feed);
  1328. //+------------------------------------------------------------------+
  1329. //| Configuration Hook Functions |
  1330. //+------------------------------------------------------------------+
  1331. int APIENTRY MtSrvGroupsAdd(const ConGroup *group);
  1332. int APIENTRY MtSrvGroupsDelete(const ConGroup *group);
  1333. int APIENTRY MtSrvSymbolsAdd(const ConSymbol *symb);
  1334. int APIENTRY MtSrvSymbolsDelete(const ConSymbol *symb);
  1335. int APIENTRY MtSrvManagersAdd(const ConManager *man);
  1336. int APIENTRY MtSrvManagersDelete(const ConManager *man);
  1337. //+------------------------------------------------------------------+
  1338. //| Trade activitiy Hook Functions |
  1339. //+------------------------------------------------------------------+
  1340. int APIENTRY MtSrvTradeRequestFilter(RequestInfo *request,const int isdemo);
  1341. void APIENTRY MtSrvTradeRequestApply(RequestInfo *request,const int isdemo);
  1342. void APIENTRY MtSrvTradeRequestRestore(RequestInfo *request);
  1343. int APIENTRY MtSrvTradeTransaction(TradeTransInfo* trans,const UserInfo *user,int *request_id);
  1344. int APIENTRY MtSrvTradeCheckIE(TradeTransInfo* trans,const UserInfo *user,const ConSymbol *symbol,double *prices);
  1345. int APIENTRY MtSrvTradeStopsFilter(const ConGroup *group,const ConSymbol *symbol,const TradeRecord *trade);
  1346. int APIENTRY MtSrvTradeStopsApply(const UserInfo *user,const ConGroup *group,const ConSymbol *symbol,TradeRecord *trade,const int isTP);
  1347. int APIENTRY MtSrvTradePendingsFilter(const ConGroup *group,const ConSymbol *symbol,const TradeRecord *trade);
  1348. int APIENTRY MtSrvTradePendingsApply(const UserInfo *user,const ConGroup *group,const ConSymbol *symbol,const TradeRecord *pending,TradeRecord *trade);
  1349. int APIENTRY MtSrvTradeStopoutsFilter(const ConGroup *group,const ConSymbol *symbol,const int login,const double equity,const double margin);
  1350. int APIENTRY MtSrvTradeStopoutsApply(const UserInfo *user,const ConGroup *group,const ConSymbol *symbol,TradeRecord *stopout);
  1351. void APIENTRY MtSrvTradesAdd(TradeRecord *trade,const UserInfo *user,const ConSymbol *symb);
  1352. void APIENTRY MtSrvTradesAddExt(TradeRecord *trade,const UserInfo *user,const ConSymbol *symb,const int mode);
  1353. void APIENTRY MtSrvTradesAddRequest(TradeRecord *trade,const RequestInfo* request,const UserInfo *user,const ConSymbol *symb,const int mode);
  1354. void APIENTRY MtSrvTradesUpdate(TradeRecord *trade,UserInfo *user,const int mode);
  1355. void APIENTRY MtSrvTradesRestore(const TradeRecord *trade);
  1356. void APIENTRY MtSrvTradesCloseBy(TradeRecord *ftrade,TradeRecord *strade,TradeRecord *remaind,ConSymbol *sec,UserInfo *user);
  1357. //+------------------------------------------------------------------+
  1358. //| Commissions & rollover calculation Hook Functions |
  1359. //+------------------------------------------------------------------+
  1360. void APIENTRY MtSrvTradeCommission(TradeRecord *trade,const ConSymbol *sec,const ConGroup *grp);
  1361. int APIENTRY MtSrvTradeCommissionAgent(TradeRecord *trade,const ConSymbol *sec,const UserInfo* user);
  1362. int APIENTRY MtSrvTradeRollover(TradeRecord *trade,const double value,const OverNightData *data);
  1363. //+------------------------------------------------------------------+
  1364. //| Statements generation Hook Functions |
  1365. //+------------------------------------------------------------------+
  1366. void APIENTRY MtSrvStatementsBaseAll(const int month_state,const GroupState *groups,const int groups_total,const DailyReport *reports,const int reports_total);
  1367. void APIENTRY MtSrvStatementsUser(const int month_state,const UserRecord *user,const ConGroup *group,TradeRecord *first_trade,TradeRecord *last_trade,StateReport *state);
  1368. void APIENTRY MtSrvStatementsRollovers(const int month_state,const time_t ctm,const tm *ttm);
  1369. //+------------------------------------------------------------------+
  1370. //| Dealer activity Hook Functions |
  1371. //+------------------------------------------------------------------+
  1372. int APIENTRY MtSrvDealerConnect(const ConManager *manager);
  1373. void APIENTRY MtSrvDealerDisconnect(const ConManager *manager);
  1374. int APIENTRY MtSrvDealerGet(const ConManager *manager,const RequestInfo *request);
  1375. int APIENTRY MtSrvDealerPrice(const int id,const UserInfo *us,double *prices,const int in_stream);
  1376. int APIENTRY MtSrvDealerConfirm(const int id,const UserInfo *us,double *prices);
  1377. int APIENTRY MtSrvDealerRequote(const int id,const UserInfo *us,double *prices,const int in_stream);
  1378. int APIENTRY MtSrvDealerReset(const int id,const UserInfo *us,const char flag);
  1379. int APIENTRY MtSrvDealerClientReject(const int id,const UserInfo *us);
  1380. //+------------------------------------------------------------------+
  1381. //| Chart history, ticks filtration |
  1382. //+------------------------------------------------------------------+
  1383. int APIENTRY MtSrvHistoryTickFilter(const ConSymbol *symbol,FeedTick *inf);
  1384. void APIENTRY MtSrvHistoryTickApply(const ConSymbol *symbol,FeedTick *inf);
  1385. int APIENTRY MtSrvHistoryCheck(const ConSymbol *symbol,RateInfo *rates,int *total);
  1386. //+------------------------------------------------------------------+
  1387. //| Internal mail & News Hook Functions |
  1388. //+------------------------------------------------------------------+
  1389. int APIENTRY MtSrvNewsCheck(FeedData *inf);
  1390. int APIENTRY MtSrvNewsCheckNew(const int feeder,FeedNews *inf);
  1391. int APIENTRY MtSrvMailCheck(MailBoxHeader *mail,int *logins,const int total);
  1392. //+------------------------------------------------------------------+
  1393. //| Protocol extension Hook functions |
  1394. //+------------------------------------------------------------------+
  1395. int APIENTRY MtSrvTelnet(const ULONG ip,char *buf,const int maxlen);
  1396. char* APIENTRY MtSrvTelnetExt(const ULONG ip,char *buf,int* data_len);
  1397. int APIENTRY MtSrvManagerProtocol(const ULONG ip,const UserInfo *us,const unsigned char *in_data,const int in_size,unsigned char **out_data,int *out_size);
  1398. //+------------------------------------------------------------------+
  1399. //| Result codes |
  1400. //+------------------------------------------------------------------+
  1401. enum
  1402. {
  1403. //--- common errors
  1404. RET_OK =0, // all OK
  1405. RET_OK_NONE, // all OK-no operation
  1406. RET_ERROR, // general error
  1407. RET_INVALID_DATA, // invalid data
  1408. RET_TECH_PROBLEM, // server technical problem
  1409. RET_OLD_VERSION, // old client terminal
  1410. RET_NO_CONNECT, // no connection
  1411. RET_NOT_ENOUGH_RIGHTS, // no enough rights
  1412. RET_TOO_FREQUENT, // too frequently access to server
  1413. RET_MALFUNCTION, // mulfunctional operation
  1414. RET_GENERATE_KEY, // need key generation
  1415. RET_SECURITY_SESSION, // securied session authorization
  1416. //--- account status
  1417. RET_ACCOUNT_DISABLED =64, // account blocked
  1418. RET_BAD_ACCOUNT_INFO, // bad account info
  1419. RET_PUBLIC_KEY_MISSING, // need public key
  1420. //--- trade
  1421. RET_TRADE_TIMEOUT =128, // trade transatcion timeou expired
  1422. RET_TRADE_BAD_PRICES, // order has wrong prices
  1423. RET_TRADE_BAD_STOPS, // wrong stops level
  1424. RET_TRADE_BAD_VOLUME, // wrong lot size
  1425. RET_TRADE_MARKET_CLOSED, // market closed
  1426. RET_TRADE_DISABLE, // trade disabled
  1427. RET_TRADE_NO_MONEY, // no enough money for order execution
  1428. RET_TRADE_PRICE_CHANGED, // price changed
  1429. RET_TRADE_OFFQUOTES, // no quotes
  1430. RET_TRADE_BROKER_BUSY, // broker is busy
  1431. RET_TRADE_REQUOTE, // requote
  1432. RET_TRADE_ORDER_LOCKED, // order is proceed by dealer and cannot be changed
  1433. RET_TRADE_LONG_ONLY, // allowed only BUY orders
  1434. RET_TRADE_TOO_MANY_REQ, // too many requests from one client
  1435. //--- order status notification
  1436. RET_TRADE_ACCEPTED, // trade request accepted by server and placed in request queue
  1437. RET_TRADE_PROCESS, // trade request accepted by dealerd
  1438. RET_TRADE_USER_CANCEL, // trade request canceled by client
  1439. //---
  1440. RET_TRADE_MODIFY_DENIED, // modification denied because order too close to market
  1441. RET_TRADE_CONTEXT_BUSY, // trade context busy (for client terminal only)
  1442. RET_TRADE_EXPIRATION_DENIED, // expiration specifieng is denied
  1443. RET_TRADE_TOO_MANY_ORDERS, // too many orders
  1444. RET_TRADE_HEDGE_PROHIBITED, // hedge is prohibited
  1445. RET_TRADE_PROHIBITED_BY_FIFO // prohibited by fifo rule
  1446. };
  1447. //+------------------------------------------------------------------+