MT5APIDeal.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. //+------------------------------------------------------------------+
  2. //| MetaTrader 5 API |
  3. //| Copyright 2000-2019, MetaQuotes Software Corp. |
  4. //| http://www.metaquotes.net |
  5. //+------------------------------------------------------------------+
  6. #pragma once
  7. #include "MT5APIAccount.h"
  8. #include "MT5APIPosition.h"
  9. //+------------------------------------------------------------------+
  10. //| Trade deal interface |
  11. //+------------------------------------------------------------------+
  12. class IMTDeal
  13. {
  14. public:
  15. //--- deal types
  16. enum EnDealAction
  17. {
  18. DEAL_BUY =0, // buy
  19. DEAL_SELL =1, // sell
  20. DEAL_BALANCE =2, // deposit operation
  21. DEAL_CREDIT =3, // credit operation
  22. DEAL_CHARGE =4, // additional charges
  23. DEAL_CORRECTION =5, // correction deals
  24. DEAL_BONUS =6, // bonus
  25. DEAL_COMMISSION =7, // commission
  26. DEAL_COMMISSION_DAILY =8, // daily commission
  27. DEAL_COMMISSION_MONTHLY =9, // monthly commission
  28. DEAL_AGENT_DAILY =10, // daily agent commission
  29. DEAL_AGENT_MONTHLY =11, // monthly agent commission
  30. DEAL_INTERESTRATE =12, // interest rate charges
  31. DEAL_BUY_CANCELED =13, // canceled buy deal
  32. DEAL_SELL_CANCELED =14, // canceled sell deal
  33. DEAL_DIVIDEND =15, // dividend
  34. DEAL_DIVIDEND_FRANKED =16, // franked dividend
  35. DEAL_TAX =17, // taxes
  36. DEAL_AGENT =18, // instant agent commission
  37. DEAL_SO_COMPENSATION =19, // negative balance compensation after stop-out
  38. //--- enumeration borders
  39. DEAL_FIRST =DEAL_BUY,
  40. DEAL_LAST =DEAL_SO_COMPENSATION
  41. };
  42. //--- deal entry direction
  43. enum EnDealEntry
  44. {
  45. ENTRY_IN =0, // in market
  46. ENTRY_OUT =1, // out of market
  47. ENTRY_INOUT =2, // reverse
  48. ENTRY_OUT_BY =3, // closed by hedged position
  49. //--- enumeration borders
  50. ENTRY_FIRST =ENTRY_IN,
  51. ENTRY_LAST =ENTRY_OUT_BY
  52. };
  53. //--- deal creation reasons
  54. enum EnDealReason
  55. {
  56. DEAL_REASON_CLIENT =0, // deal placed manually
  57. DEAL_REASON_EXPERT =1, // deal placed by expert
  58. DEAL_REASON_DEALER =2, // deal placed by dealer
  59. DEAL_REASON_SL =3, // deal placed due SL
  60. DEAL_REASON_TP =4, // deal placed due TP
  61. DEAL_REASON_SO =5, // deal placed due Stop-Out
  62. DEAL_REASON_ROLLOVER =6, // deal placed due rollover
  63. DEAL_REASON_EXTERNAL_CLIENT=7, // deal placed from the external system by client
  64. DEAL_REASON_VMARGIN =8, // deal placed due variation margin
  65. DEAL_REASON_GATEWAY =9, // deal placed by gateway
  66. DEAL_REASON_SIGNAL =10, // deal placed by signal service
  67. DEAL_REASON_SETTLEMENT =11, // deal placed due settlement
  68. DEAL_REASON_TRANSFER =12, // deal placed due position transfer
  69. DEAL_REASON_SYNC =13, // deal placed due position synchronization
  70. DEAL_REASON_EXTERNAL_SERVICE=14, // deal placed from the external system due service issues
  71. DEAL_REASON_MIGRATION =15, // deal placed due migration
  72. DEAL_REASON_MOBILE =16, // deal placed manually by mobile terminal
  73. DEAL_REASON_WEB =17, // deal placed manually by web terminal
  74. DEAL_REASON_SPLIT =18, // deal placed due split
  75. //--- enumeration borders
  76. DEAL_REASON_FIRST =DEAL_REASON_CLIENT,
  77. DEAL_REASON_LAST =DEAL_REASON_SPLIT
  78. };
  79. //--- modification flags
  80. enum EnTradeModifyFlags
  81. {
  82. MODIFY_FLAGS_ADMIN =0x00000001,
  83. MODIFY_FLAGS_MANAGER =0x00000002,
  84. MODIFY_FLAGS_POSITION =0x00000004,
  85. MODIFY_FLAGS_RESTORE =0x00000008,
  86. MODIFY_FLAGS_API_ADMIN =0x00000010,
  87. MODIFY_FLAGS_API_MANAGER =0x00000020,
  88. MODIFY_FLAGS_API_SERVER =0x00000040,
  89. MODIFY_FLAGS_API_GATEWAY =0x00000080,
  90. //--- enumeration borders
  91. MODIFY_FLAGS_NONE =0x00000000,
  92. MODIFY_FLAGS_ALL =MODIFY_FLAGS_ADMIN|MODIFY_FLAGS_MANAGER|MODIFY_FLAGS_POSITION|MODIFY_FLAGS_RESTORE|
  93. MODIFY_FLAGS_API_ADMIN|MODIFY_FLAGS_API_MANAGER|MODIFY_FLAGS_API_SERVER|MODIFY_FLAGS_API_GATEWAY
  94. };
  95. //--- common methods
  96. virtual void Release(void)=0;
  97. virtual MTAPIRES Assign(const IMTDeal* deal)=0;
  98. virtual MTAPIRES Clear(void)=0;
  99. virtual LPCWSTR Print(MTAPISTR& string) const=0;
  100. //--- deal ticket
  101. virtual UINT64 Deal(void) const=0;
  102. //--- deal ticket in external system (exchange, ECN, etc)
  103. virtual LPCWSTR ExternalID(void) const=0;
  104. virtual MTAPIRES ExternalID(LPCWSTR id)=0;
  105. //--- client login
  106. virtual UINT64 Login(void) const=0;
  107. virtual MTAPIRES Login(const UINT64 login)=0;
  108. //--- processed dealer login (0-means auto)
  109. virtual UINT64 Dealer(void) const=0;
  110. virtual MTAPIRES Dealer(const UINT64 dealer)=0;
  111. //--- deal order ticket
  112. virtual UINT64 Order(void) const=0;
  113. virtual MTAPIRES Order(const UINT64 order)=0;
  114. //--- EnDealAction
  115. virtual UINT Action(void) const=0;
  116. virtual MTAPIRES Action(const UINT action)=0;
  117. //--- EnEntryFlags
  118. virtual UINT Entry(void) const=0;
  119. virtual MTAPIRES Entry(const UINT entry)=0;
  120. //--- price digits
  121. virtual UINT Digits(void) const=0;
  122. virtual MTAPIRES Digits(const UINT digits)=0;
  123. //--- currency digits
  124. virtual UINT DigitsCurrency(void) const=0;
  125. virtual MTAPIRES DigitsCurrency(const UINT digits)=0;
  126. //--- symbol contract size
  127. virtual double ContractSize(void) const=0;
  128. virtual MTAPIRES ContractSize(const double contract_size)=0;
  129. //--- deal creation datetime in seconds
  130. virtual INT64 Time(void) const=0;
  131. virtual MTAPIRES Time(const INT64 time)=0;
  132. //--- deal symbol
  133. virtual LPCWSTR Symbol(void) const=0;
  134. virtual MTAPIRES Symbol(LPCWSTR symbol)=0;
  135. //--- deal price
  136. virtual double Price(void) const=0;
  137. virtual MTAPIRES Price(const double price)=0;
  138. //--- deal volume
  139. virtual UINT64 Volume(void) const=0;
  140. virtual MTAPIRES Volume(const UINT64 volume)=0;
  141. //--- deal profit
  142. virtual double Profit(void) const=0;
  143. virtual MTAPIRES Profit(const double profit)=0;
  144. //--- deal collected swaps
  145. virtual double Storage(void) const=0;
  146. virtual MTAPIRES Storage(const double storage)=0;
  147. //--- deal commission
  148. virtual double Commission(void) const=0;
  149. virtual MTAPIRES Commission(const double comm)=0;
  150. //--- obsolete value
  151. virtual double ObsoleteValue(void) const=0;
  152. virtual MTAPIRES ObsoleteValue(const double agent)=0;
  153. //--- profit conversion rate (from symbol profit currency to deposit currency)
  154. virtual double RateProfit(void) const=0;
  155. virtual MTAPIRES RateProfit(const double rate)=0;
  156. //--- margin conversion rate (from symbol margin currency to deposit currency)
  157. virtual double RateMargin(void) const=0;
  158. virtual MTAPIRES RateMargin(const double rate)=0;
  159. //--- expert id (filled by expert advisor)
  160. virtual UINT64 ExpertID(void) const=0;
  161. virtual MTAPIRES ExpertID(const UINT64 id)=0;
  162. //--- position id
  163. virtual UINT64 PositionID(void) const=0;
  164. virtual MTAPIRES PositionID(const UINT64 id)=0;
  165. //--- deal comment
  166. virtual LPCWSTR Comment(void) const=0;
  167. virtual MTAPIRES Comment(LPCWSTR comment)=0;
  168. //--- deal internal data for API usage
  169. virtual MTAPIRES ApiDataSet(const USHORT app_id,const UCHAR id,const INT64 value)=0;
  170. virtual MTAPIRES ApiDataSet(const USHORT app_id,const UCHAR id,const UINT64 value)=0;
  171. virtual MTAPIRES ApiDataSet(const USHORT app_id,const UCHAR id,const double value)=0;
  172. virtual MTAPIRES ApiDataGet(const USHORT app_id,const UCHAR id,INT64& value) const=0;
  173. virtual MTAPIRES ApiDataGet(const USHORT app_id,const UCHAR id,UINT64& value) const=0;
  174. virtual MTAPIRES ApiDataGet(const USHORT app_id,const UCHAR id,double& value) const=0;
  175. virtual MTAPIRES ApiDataClear(const USHORT app_id)=0;
  176. virtual MTAPIRES ApiDataClearAll(void)=0;
  177. //--- deal profit in symbol's profit currency
  178. virtual double ProfitRaw(void) const=0;
  179. virtual MTAPIRES ProfitRaw(const double profit)=0;
  180. //--- closed position price
  181. virtual double PricePosition(void) const=0;
  182. virtual MTAPIRES PricePosition(const double price)=0;
  183. //--- closed volume
  184. virtual UINT64 VolumeClosed(void) const=0;
  185. virtual MTAPIRES VolumeClosed(const UINT64 volume)=0;
  186. //--- tick value
  187. virtual double TickValue(void) const=0;
  188. virtual MTAPIRES TickValue(const double value)=0;
  189. //--- tick size
  190. virtual double TickSize(void) const=0;
  191. virtual MTAPIRES TickSize(const double size)=0;
  192. //--- flags
  193. virtual UINT64 Flags(void) const=0;
  194. virtual MTAPIRES Flags(const UINT64 flags)=0;
  195. //--- deal creation datetime in msc since 1970.01.01
  196. virtual INT64 TimeMsc(void) const=0;
  197. virtual MTAPIRES TimeMsc(const INT64 time)=0;
  198. //--- EnDealReason
  199. virtual UINT Reason(void) const=0;
  200. //--- source gateway name
  201. virtual LPCWSTR Gateway(void) const=0;
  202. //--- deal price on gateway
  203. virtual double PriceGateway(void) const=0;
  204. //--- user record internal data for API usage
  205. virtual MTAPIRES ApiDataUpdate(const UINT pos,const USHORT app_id,const UCHAR id,const INT64 value)=0;
  206. virtual MTAPIRES ApiDataUpdate(const UINT pos,const USHORT app_id,const UCHAR id,const UINT64 value)=0;
  207. virtual MTAPIRES ApiDataUpdate(const UINT pos,const USHORT app_id,const UCHAR id,const double value)=0;
  208. virtual MTAPIRES ApiDataNext(const UINT pos,USHORT& app_id,UCHAR& id,INT64& value) const=0;
  209. virtual MTAPIRES ApiDataNext(const UINT pos,USHORT& app_id,UCHAR& id,UINT64& value) const=0;
  210. virtual MTAPIRES ApiDataNext(const UINT pos,USHORT& app_id,UCHAR& id,double& value) const=0;
  211. //--- deal ticket
  212. virtual MTAPIRES DealSet(const UINT64 deal)=0;
  213. //--- modification flags
  214. virtual UINT ModificationFlags(void) const=0;
  215. //--- EnOrderReason
  216. virtual MTAPIRES ReasonSet(const UINT reason)=0;
  217. //--- source gateway name
  218. virtual MTAPIRES GatewaySet(LPCWSTR gateway)=0;
  219. //--- deal price on gateway
  220. virtual MTAPIRES PriceGatewaySet(double price_gateway)=0;
  221. //--- order SL
  222. virtual double PriceSL(void) const=0;
  223. virtual MTAPIRES PriceSL(const double price)=0;
  224. //--- order TP
  225. virtual double PriceTP(void) const=0;
  226. virtual MTAPIRES PriceTP(const double price)=0;
  227. //--- deal volume with extended accuracy
  228. virtual UINT64 VolumeExt(void) const=0;
  229. virtual MTAPIRES VolumeExt(const UINT64 volume)=0;
  230. //--- closed volume with extended accuracy
  231. virtual UINT64 VolumeClosedExt(void) const=0;
  232. virtual MTAPIRES VolumeClosedExt(const UINT64 volume)=0;
  233. };
  234. //+------------------------------------------------------------------+
  235. //| Deal array interface |
  236. //+------------------------------------------------------------------+
  237. class IMTDealArray
  238. {
  239. public:
  240. //--- common methods
  241. virtual void Release(void)=0;
  242. virtual MTAPIRES Assign(const IMTDealArray* array)=0;
  243. virtual MTAPIRES Clear(void)=0;
  244. //--- add
  245. virtual MTAPIRES Add(IMTDeal* deal)=0;
  246. virtual MTAPIRES AddCopy(const IMTDeal* deal)=0;
  247. virtual MTAPIRES Add(IMTDealArray* array)=0;
  248. virtual MTAPIRES AddCopy(const IMTDealArray* array)=0;
  249. //--- delete & detach
  250. virtual MTAPIRES Delete(const UINT pos)=0;
  251. virtual IMTDeal* Detach(const UINT pos)=0;
  252. //--- update
  253. virtual MTAPIRES Update(const UINT pos,IMTDeal* deal)=0;
  254. virtual MTAPIRES UpdateCopy(const UINT pos,const IMTDeal* deal)=0;
  255. virtual MTAPIRES Shift(const UINT pos,const int shift)=0;
  256. //--- data access
  257. virtual UINT Total(void) const=0;
  258. virtual IMTDeal* Next(const UINT index) const=0;
  259. //--- sorting and search
  260. virtual MTAPIRES Sort(MTSortFunctionPtr sort_function)=0;
  261. virtual int Search(const void *key,MTSortFunctionPtr sort_function) const=0;
  262. virtual int SearchGreatOrEq(const void *key,MTSortFunctionPtr sort_function) const=0;
  263. virtual int SearchGreater(const void *key,MTSortFunctionPtr sort_function) const=0;
  264. virtual int SearchLessOrEq(const void *key,MTSortFunctionPtr sort_function) const=0;
  265. virtual int SearchLess(const void *key,MTSortFunctionPtr sort_function) const=0;
  266. virtual int SearchLeft(const void *key,MTSortFunctionPtr sort_function) const=0;
  267. virtual int SearchRight(const void *key,MTSortFunctionPtr sort_function) const=0;
  268. };
  269. //+------------------------------------------------------------------+
  270. //| Deals events notification interface |
  271. //+------------------------------------------------------------------+
  272. class IMTDealSink
  273. {
  274. public:
  275. virtual void OnDealAdd(const IMTDeal* /*deal*/) { }
  276. virtual void OnDealUpdate(const IMTDeal* /*deal*/) { }
  277. virtual void OnDealDelete(const IMTDeal* /*deal*/) { }
  278. virtual void OnDealClean(const UINT64 /*login*/) { }
  279. virtual void OnDealSync(void) { }
  280. virtual void OnDealPerform(const IMTDeal* /*deal*/,IMTAccount* /*account*/,IMTPosition* /*position*/) { }
  281. };
  282. //+------------------------------------------------------------------+