MT5APITick.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //+------------------------------------------------------------------+
  2. //| MetaTrader 5 API |
  3. //| Copyright 2000-2019, MetaQuotes Software Corp. |
  4. //| http://www.metaquotes.net |
  5. //+------------------------------------------------------------------+
  6. #pragma once
  7. //+------------------------------------------------------------------+
  8. //| Feeder constants |
  9. //+------------------------------------------------------------------+
  10. enum EnMTFeederConstants
  11. {
  12. MT_FEEDER_DEALER =-1, // feeder index for dealer ticks
  13. MT_FEEDER_OFFSET =64 // index offset for datafeed ticks
  14. };
  15. //+------------------------------------------------------------------+
  16. //| Tick full description structure |
  17. //+------------------------------------------------------------------+
  18. #pragma pack(push,1)
  19. struct MTTick
  20. {
  21. //--- tick flags
  22. enum EnTickFlags
  23. {
  24. TICK_FLAG_BUY =1, // tick created due buy operation
  25. TICK_FLAG_SELL =2, // tick created due sell operation
  26. //--- enumeration borders
  27. TICK_FLAG_NONE =0, // none
  28. TICK_FLAG_ALL =TICK_FLAG_BUY|TICK_FLAG_SELL // all flags
  29. };
  30. wchar_t symbol[32]; // symbol
  31. wchar_t bank[32]; // tick source ticker
  32. INT64 datetime; // datetime in seconds since 01/01/1970
  33. //--- basic price data
  34. double bid; // bid price
  35. double ask; // ask price
  36. double last; // last price
  37. UINT64 volume; // last trade volume
  38. //--- additional data
  39. INT64 datetime_msc; // datetime in milliseconds since 01/01/1970
  40. UINT64 flags; // flags
  41. UINT64 volume_ext; // last trade volume with extended accuracy
  42. //--- reserved data
  43. UINT reserved[26]; // reserved
  44. };
  45. #pragma pack(pop)
  46. //+------------------------------------------------------------------+
  47. //| Tick short description structure |
  48. //+------------------------------------------------------------------+
  49. #pragma pack(push,1)
  50. struct MTTickShort
  51. {
  52. //--- tick flags
  53. enum EnTickShortFlags
  54. {
  55. TICK_SHORT_FLAG_RAW =0x00000001, // raw tick
  56. TICK_SHORT_FLAG_BID =0x00000002, // tick changes bid price value
  57. TICK_SHORT_FLAG_ASK =0x00000004, // tick changes ask price value
  58. TICK_SHORT_FLAG_LAST =0x00000008, // tick changes last price value
  59. TICK_SHORT_FLAG_VOLUME=0x00000010, // tick changes volume value
  60. TICK_SHORT_FLAG_BUY =0x00000020, // tick created due buy operation
  61. TICK_SHORT_FLAG_SELL =0x00000040, // tick created due sell operation
  62. //--- enumeration borders
  63. TICK_SHORT_FLAG_NONE =0x00000000, // none
  64. };
  65. INT64 datetime; // last update datetime in seconds since 01/01/1970
  66. double bid; // bid price
  67. double ask; // ask price
  68. double last; // last price
  69. UINT64 volume; // last trade volume
  70. INT64 datetime_msc; // datetime in milliseconds since 01/01/1970
  71. UINT64 flags; // flags
  72. UINT64 volume_ext; // last trade volume with extended volume
  73. UINT reserved[26]; // reserved
  74. };
  75. #pragma pack(pop)
  76. //+------------------------------------------------------------------+
  77. //| Tick short structure |
  78. //+------------------------------------------------------------------+
  79. #pragma pack(push,1)
  80. struct MTTickRate
  81. {
  82. //--- tick flags
  83. enum EnTickShortFlags
  84. {
  85. TICK_SHORT_FLAG_RAW =0x00000001, // raw tick
  86. TICK_SHORT_FLAG_BID =0x00000002, // tick changes bid price value
  87. TICK_SHORT_FLAG_ASK =0x00000004, // tick changes ask price value
  88. TICK_SHORT_FLAG_LAST =0x00000008, // tick changes last price value
  89. TICK_SHORT_FLAG_VOLUME=0x00000010, // tick changes volume value
  90. TICK_SHORT_FLAG_BUY =0x00000020, // tick created due buy operation
  91. TICK_SHORT_FLAG_SELL =0x00000040, // tick created due sell operation
  92. //--- enumeration borders
  93. TICK_SHORT_FLAG_NONE =0x00000000, // none
  94. };
  95. INT64 datetime_msc; // datetime in milliseconds since 01/01/1970
  96. double bid; // bid price
  97. double ask; // ask price
  98. double last; // last price
  99. UINT64 flags; // flags
  100. UINT64 volume_ext; // last trade volume with extended volume
  101. INT64 reserved[2];
  102. };
  103. #pragma pack(pop)
  104. //+------------------------------------------------------------------+
  105. //| Tick statistic description structure |
  106. //+------------------------------------------------------------------+
  107. #pragma pack(push,1)
  108. struct MTTickStat
  109. {
  110. wchar_t symbol[32]; // symbol
  111. INT64 datetime; // last update datetime in seconds since 01/01/1970
  112. //--- bid
  113. double bid_high; // bid high
  114. double bid_low; // bid low
  115. //--- ask
  116. double ask_high; // ask high
  117. double ask_low; // ask low
  118. //--- last
  119. double last_high; // last high
  120. double last_low; // last low
  121. //--- trade volume
  122. UINT64 vol_high; // last high
  123. UINT64 vol_low; // last low
  124. //--- trade session statistics
  125. UINT64 trade_deals; // total deals in current session
  126. UINT64 trade_volume; // total deals volume in current session
  127. UINT64 trade_turnover; // total turnover in current session
  128. UINT64 trade_interest; // open interest in current session
  129. UINT64 trade_buy_orders; // total buy orders
  130. UINT64 trade_buy_volume; // total buy orders volume
  131. UINT64 trade_sell_orders; // total sell orders
  132. UINT64 trade_sell_volume; // total sell orders volume
  133. UINT64 trade_volume_ext; // total deals volume in current session with extended accuracy
  134. UINT64 trade_buy_volume_ext; // total buy orders volume with extended accuracy
  135. UINT64 trade_sell_volume_ext; // total sell orders volume with extended accuracy
  136. UINT64 vol_high_ext; // last high with extended accuracy
  137. UINT64 vol_low_ext; // last low with extended accuracy
  138. int trade_reserved[20]; // reserved
  139. //--- datetime
  140. INT64 datetime_msc; // last update datetime in milliseconds since 01/01/1970
  141. //--- price session statistics
  142. double price_open; // session open price
  143. double price_close; // session close price
  144. double price_aw; // average weighted price
  145. double price_change; // price change percentage
  146. double price_volatility; // price volatility
  147. double price_theoretical; // theoretical price
  148. double price_greeks_delta; // option\warrant delta
  149. double price_greeks_theta; // option\warrant theta
  150. double price_greeks_gamma; // option\warrant gamma
  151. double price_greeks_vega; // option\warrant vega
  152. double price_greeks_rho; // option\warrant rho
  153. double price_greeks_omega; // option\warrant omega
  154. double price_sensitivity; // option\warrant sensitivity
  155. int price_reserved[14]; // reserved
  156. };
  157. #pragma pack(pop)
  158. //+------------------------------------------------------------------+
  159. //| Tick events notification interface |
  160. //+------------------------------------------------------------------+
  161. class IMTTickSink
  162. {
  163. public:
  164. //--- tick events
  165. virtual void OnTick(LPCWSTR /*symbol*/,const MTTickShort& /*tick*/) { }
  166. virtual void OnTickStat(const MTTickStat& /*tick*/) { }
  167. //--- tick hooks
  168. virtual MTAPIRES HookTick(const int /*feeder*/,MTTick& /*tick*/) { return(MT_RET_OK); }
  169. virtual MTAPIRES HookTickStat(const int /*feeder*/,MTTickStat& /*tstat*/) { return(MT_RET_OK); }
  170. //--- extended tick events
  171. virtual void OnTick(const int /*feeder*/,const MTTick& /*tick*/) { }
  172. virtual void OnTickStat(const int /*feeder*/,const MTTickStat& /*tstat*/) { }
  173. };
  174. //+------------------------------------------------------------------+