168 lines
4.7 KiB
C++
168 lines
4.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:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param session the session
|
|
*/
|
|
ACTIV_ONE_API ExchangeInfo(OneApi::Session &session);
|
|
|
|
/**
|
|
* @brief Is the UTC offset valid?
|
|
*
|
|
* This is required for the the UTC conversion functions to be used.
|
|
*
|
|
* @return whether the UTC offset is valid
|
|
*/
|
|
ACTIV_ONE_API bool IsUtcOffsetValid() const;
|
|
|
|
/**
|
|
* @brief Convert the provided date and time from the exchange timezone to UTC.
|
|
*
|
|
* Assumes the date and time are stored in the exchange timezone.
|
|
*
|
|
* @param date the date to convert.
|
|
* @param time the time to convert.
|
|
* @param utcDateTime to receive the result of the conversion.
|
|
*
|
|
* @return STATUS_CODE_SUCCESS
|
|
* @return ...
|
|
*/
|
|
ACTIV_ONE_API StatusCode ConvertDateTimeToUtc(const Date &date, const Time &time, DateTime &utcDateTime) const;
|
|
|
|
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.
|
|
|
|
int64_t m_utcOffset; ///< The exchange's offset in seconds compared to UTC.
|
|
int64_t m_dstOffset; ///< The exchange's DST offset in seconds.
|
|
DateTime m_dstStartDateTime; ///< The start date time of the exchange's DST period.
|
|
DateTime m_dstEndDateTime; ///< The end date time of the exchange's DST period.
|
|
|
|
private:
|
|
#if (!defined ACTIV_LITE_FRAMEWORK)
|
|
OneApi::Session & m_session;
|
|
#endif
|
|
};
|
|
|
|
/**
|
|
* @brief Exchange info helper class.
|
|
*
|
|
* This helper will provide a snapshot of the current state of exchange information.
|
|
*/
|
|
class ExchangeInfoHelper : private OneApi::IQueryHandler, 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:
|
|
// IQueryHandler interface.
|
|
virtual void OnQueryAdd(const OneApi::QueryAddMessage &message, const OneApi::Context &context) ACTIV_OVERRIDE;
|
|
virtual void OnQueryStatus(const OneApi::QueryStatusMessage &message, const OneApi::Context &context) ACTIV_OVERRIDE;
|
|
|
|
// ISnapshotHandler interface.
|
|
virtual void OnSnapshot(const OneApi::SnapshotMessage &message, const OneApi::Context &context) ACTIV_OVERRIDE;
|
|
virtual void OnSnapshotFailure(const OneApi::SnapshotFailureMessage &message, const OneApi::Context &context) ACTIV_OVERRIDE;
|
|
|
|
void ApplyFlv(ExchangeInfo &exchangeInfo);
|
|
void CheckAndUpdateState();
|
|
|
|
static CxxYZ::vector<Date> GetDateListFromString(const String &dateString);
|
|
|
|
OneApi::ScopedHandle m_queryHandle;
|
|
State m_state;
|
|
OneApi::FieldListValidator m_fieldListValidator;
|
|
|
|
typedef CxxYZ::unordered_map<String, OneApi::ScopedHandle> ScopedHandleMap;
|
|
ScopedHandleMap m_snapshotHandleMap;
|
|
|
|
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)
|