00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023 #pragma once
00024
00025 #include "RobotHelperInterfaces.h"
00026
00027 #include <corelib/md_carrier.h>
00028
00029 namespace RT
00030 {
00031
00032
00033 enum TAHistDataType
00034 {
00035 dt_open = 0,
00036 dt_high,
00037 dt_low,
00038 dt_close,
00039 dt_median,
00040 dt_typical,
00041 dt_weighted,
00042 dt_volume,
00043 dt_time,
00044 dt_last_trade,
00045 dt_max
00046 };
00052 struct OHLC
00053 {
00054 public:
00055 double open_;
00056 double high_;
00057 double low_;
00058 double close_;
00059 __int64 volume_;
00060 int timestamp_;
00061 };
00062
00063
00064
00070 class IMarketDataConsumer
00071 {
00072 public:
00074 virtual void onMarketData (RTInstrument&) = 0;
00076 virtual void onMarketData (const inside_market_notification_t&, const std::string &)= 0;
00078 virtual void onMarketData (const market_depth_notification_t&, const std::string &)= 0;
00080 virtual void onMarketData (const implied_market_depth_notification_t&, const std::string &)= 0;
00082 virtual void onMarketData (const outright_market_depth_notification_t&, const std::string &)= 0;
00084 virtual void onMarketData (const market_state_notification_t&, const std::string &)= 0;
00086 virtual void onMarketData (const last_trade_carrier_t&, const std::string &)= 0;
00088 virtual void onMarketData (const rfq_notification_t&, const std::string &)= 0;
00090 virtual void onMarketData (const ohlc_carrier_t&, const std::string &)= 0;
00091
00093 virtual void on_md_handler_connected () = 0;
00095 virtual void on_md_handler_disconnected () = 0;
00097 virtual void on_md_source_state_changed (const char* src_name) = 0;
00098 };
00099
00100 struct IMDSourceState;
00102 typedef std::map<std::string, IMDSourceState*> MDSourceStateMap;
00104 typedef std::multimap<std::string,RTInstrument> InstrumentList;
00110 class IMarketDataHelper
00111 {
00112 public:
00113
00115 virtual int request_instr_description ( const std::string &class_name, const std::string& exch = "")=0;
00116
00118 virtual int subscribe_inside_market ( const std::string & symbol, const std::string& exch = "")=0;
00120 virtual int subscribe_last_trade ( const std::string & symbol, const std::string& exch = "")=0;
00122 virtual int subscribe_market_depth ( const std::string & symbol, const std::string& exch = "")=0;
00124 virtual int subscribe_implied_market_depth ( const std::string & symbol, const std::string& exch = "")=0;
00126 virtual int subscribe_outright_market_depth ( const std::string & symbol, const std::string& exch = "")=0;
00128 virtual int subscribe_market_state ( const std::string & symbol, const std::string& exch = "")=0;
00129 virtual int subscribe_exchange_state ( const std::string & symbol, const std::string& exch = "")=0;
00131 virtual int subscribe_rfq ( const std::string & symbol, const std::string& exch = "")=0;
00133 virtual int subscribe_real_time_ohlc ( const std::string & symbol, ohlc_interv_t interv_type, const std::string& exch = "")=0;
00134
00136 virtual void unsubscribe_inside_market (const int subscr_id, const std::string &instr_name)=0;
00138 virtual void unsubscribe_last_trade (const int subscr_id, const std::string &instr_name)=0;
00140 virtual void unsubscribe_market_depth (const int subscr_id, const std::string &instr_name)=0;
00142 virtual void unsubscribe_implied_market_depth(const int subscr_id, const std::string &instr_name)=0;
00144 virtual void unsubscribe_outright_market_depth(const int subscr_id, const std::string &instr_name)=0;
00146 virtual void unsubscribe_market_state (const int subscr_id, const std::string &instr_name)=0;
00148 virtual void unsubscribe_exchange_state (const int subscr_id, const std::string &exchange_name)=0;
00150 virtual void unsubscribe_rfq (const int subscr_id, const std::string &instr_name)=0;
00152 virtual void unsubscribe_real_time_ohlc (const int subscr_id, const std::string &class_name)=0;
00153
00155 virtual InstrumentList& instruments () = 0;
00156
00157
00158 virtual bool is_valid()=0;
00159
00160
00170 virtual int getHistData(DataSource& out_data, const std::string& symbol,
00171 const TAHistDataType data_type, int& out_bar_count,
00172 int period, int offset, int interval = 1, hmd_interval_t interval_type = it_daily,
00173 bool need_subscribe = false ) = 0;
00174
00186 virtual int getHistData(DataSource& outHigh, DataSource& outLow, DataSource& outClose, DataSource& outVolume,
00187 const std::string& symbol, int& out_bar_count,
00188 int period, int offset, int interval = 1, hmd_interval_t interval_type = it_daily,
00189 bool need_subscribe = false ) = 0;
00190
00200 virtual int getHistData(DataSource& outHigh, DataSource& outLow, DataSource& outClose,
00201 const std::string& symbol, int& out_bar_count,
00202 int period, int offset, int interval = 1, hmd_interval_t interval_type = it_daily,
00203 bool need_subscribe = false ) = 0;
00204
00213 virtual int getHistData(DataSource& outHigh, DataSource& outLow,
00214 const std::string& symbol, int& out_bar_count,
00215 int period, int offset, int interval = 1, hmd_interval_t interval_type = it_daily,
00216 bool need_subscribe = false ) = 0;
00217
00225 virtual int getHistData(OHLC out_data[],
00226 const std::string& symbol, int& out_bar_count,
00227 int period, int offset, int interval = 1, hmd_interval_t interval_type = it_daily,
00228 bool need_subscribe = false ) = 0;
00229
00231 virtual MDSourceStateMap* md_source_stats_map() = 0;
00232
00233 void robotrader(IMarketDataConsumer* robotrader)
00234 {robotrader_= robotrader;}
00235 IMarketDataConsumer* robotrader()
00236 {return robotrader_;}
00237
00238 private:
00239 IMarketDataConsumer* robotrader_;
00240 };
00241
00242
00249 struct IMDSourceState
00250 {
00252 virtual const char* name() = 0;
00254 virtual const char* display_name() = 0;
00255
00257 virtual bool is_available() = 0;
00258
00260 virtual double round_trip_latency() = 0;
00262 virtual double min_latency() = 0;
00264 virtual double max_latency() = 0;
00266 virtual double mean_latency() = 0;
00268 virtual double rolling_mean_latency() = 0;
00269
00271 virtual int total_bytes_received() = 0;
00272 };
00273
00274 }