129 lines
3.7 KiB
C++
129 lines
3.7 KiB
C++
/**
|
|
* @file include/ActivOneApi/MarketData/ExchangeInfoHelper.h
|
|
*
|
|
* @brief Header for the ExchangeInfoHelper class.
|
|
*/
|
|
|
|
#if (!defined ACTIV_ONE_API_EXCHANGE_INFO_HELPER_H)
|
|
#define ACTIV_ONE_API_EXCHANGE_INFO_HELPER_H
|
|
|
|
#include "ActivOneApi/External.h"
|
|
|
|
#include "ActivOneApi/OneApi.h"
|
|
|
|
#include "ActivMiddleware/CxxYZ/set.h"
|
|
#include "ActivMiddleware/CxxYZ/unordered_map.h"
|
|
|
|
//! namespace Activ
|
|
namespace Activ
|
|
{
|
|
|
|
//! MarketData namespace.
|
|
namespace MarketData
|
|
{
|
|
|
|
//! Exchange Info.
|
|
class ExchangeInfo
|
|
{
|
|
public:
|
|
String m_symbol; ///< E.g. "Q".
|
|
String m_name; ///< E.g. "NASDAQ OMX".
|
|
String m_olsonTimeZone; ///< The exchange's timezone in Olson format.
|
|
String m_microsoftTimeZone; ///< The exchange's timezone in Microsoft format.
|
|
String m_timeZone; ///< The exchange's timezone in the format appropriate for this platform.
|
|
CxxYZ::vector<Date> m_holidayDateList; ///< The exchange's holidays.
|
|
};
|
|
|
|
/**
|
|
* @brief Exchange info helper class.
|
|
*
|
|
* This helper will provide a snapshot of the current state of exchange information.
|
|
*/
|
|
class ExchangeInfoHelper : private OneApi::ITopicQueryHandler, private OneApi::ISnapshotHandler
|
|
{
|
|
public:
|
|
//! State.
|
|
enum State
|
|
{
|
|
STATE_INIT,
|
|
STATE_SYNCHRONIZING,
|
|
STATE_OK,
|
|
STATE_ERROR
|
|
};
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param session
|
|
*/
|
|
ACTIV_ONE_API ExchangeInfoHelper(OneApi::Session &session);
|
|
|
|
/**
|
|
* @brief Get ExchangeInfo for a symbol's exchange.
|
|
*
|
|
* @param symbol a symbol (with exchange code) or an exchange code, e.g. "MSFT.Q" or just "Q".
|
|
*
|
|
* @return The ExchangeInfo.
|
|
*
|
|
* @throw Exception if unable to get the exchange info from the Gateway or the exchange could not be determined for
|
|
* the provided symbol. The info is cached so every call to this function does not result in an upstream request.
|
|
*/
|
|
ACTIV_ONE_API const ExchangeInfo &GetExchangeInfo(const String &symbol) const;
|
|
|
|
/**
|
|
* @brief Get state.
|
|
*
|
|
* @return The current state of the helper.
|
|
*/
|
|
State GetState() const;
|
|
|
|
/**
|
|
* @brief State to string.
|
|
*
|
|
* @param state
|
|
*
|
|
* @return the string representation of @a state.
|
|
*/
|
|
ACTIV_ONE_API static String StateToString(const State state);
|
|
|
|
private:
|
|
// ITopicQueryHandler interface.
|
|
virtual void OnTopicQueryStart(const OneApi::Context &context) ACTIV_OVERRIDE;
|
|
virtual void OnTopicQueryAdd(OneApi::Topic &topic, const OneApi::Context &context) ACTIV_OVERRIDE;
|
|
virtual void OnTopicQueryComplete(const OneApi::Context &context) ACTIV_OVERRIDE;
|
|
virtual void OnTopicQueryError(const StatusCode statusCode, const OneApi::Context &context) ACTIV_OVERRIDE;
|
|
virtual void OnTopicQueryFailure(const StatusCode statusCode, const OneApi::Context &context) ACTIV_OVERRIDE;
|
|
|
|
// ISnapshotHandler interface.
|
|
virtual void OnSnapshot(const OneApi::SnapshotMessage &snapshotMessage, const OneApi::Context &context) ACTIV_OVERRIDE;
|
|
virtual void OnSnapshotFailure(const OneApi::SnapshotFailureMessage &snapshotFailureMessage,
|
|
const OneApi::Context &context) ACTIV_OVERRIDE;
|
|
|
|
void ApplyFlv(ExchangeInfo &exchangeInfo);
|
|
void CheckAndUpdateState();
|
|
|
|
static CxxYZ::vector<Date> GetDateListFromString(const String &dateString);
|
|
|
|
OneApi::ScopedHandle m_topicQueryHandle;
|
|
State m_state;
|
|
OneApi::FieldListValidator m_fieldListValidator;
|
|
|
|
typedef CxxYZ::unordered_map<String, ExchangeInfo> ExchangeInfoMap;
|
|
ExchangeInfoMap m_exchangeInfoMap;
|
|
|
|
size_t m_snapshotsReceived;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline ExchangeInfoHelper::State ExchangeInfoHelper::GetState() const
|
|
{
|
|
return m_state;
|
|
}
|
|
|
|
} // namespace MarketData
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_ONE_API_EXCHANGE_INFO_HELPER_H)
|