-
Notifications
You must be signed in to change notification settings - Fork 156
/
Symbol.h
133 lines (98 loc) · 5.18 KB
/
Symbol.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/************************************************************************
* Copyright(c) 2009, One Unified. All rights reserved. *
* *
* This file is provided as is WITHOUT ANY WARRANTY *
* without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* This software may not be used nor distributed without proper license *
* agreement. *
* *
* See the file LICENSE.txt for redistribution information. *
************************************************************************/
#pragma once
#include <string>
#include <boost/asio/io_context.hpp>
#include <boost/asio/io_context_strand.hpp>
#include <boost/shared_ptr.hpp>
#include <OUCommon/Delegate.h>
#include <TFTimeSeries/DatedDatum.h>
#include "Instrument.h"
// change the Add/Remove...Handlers from virtual to CRTP?
// probably not,
namespace ou { // One Unified
namespace tf { // TradeFrame
class SymbolBase {
public:
using pInstrument_t = Instrument::pInstrument_t;
using pInstrument_cref = Instrument::pInstrument_cref;
using idSymbol_t = Instrument::idInstrument_t;
// may need to use provider specific name in alternate instrument name in Instrument
// class should only be constructed with valid instrument, which already has general name as well as provider specific names
SymbolBase( pInstrument_t pInstrument ); // instrument supplied name
SymbolBase( pInstrument_t pInstrument, const std::string& sName ); // provider specific name
virtual ~SymbolBase();
const idSymbol_t& GetId() const { return m_id; }; // used for mapping and indexing
pInstrument_t GetInstrument() { return m_pInstrument; };
using quote_t = const Quote&;
using quotehandler_t = ou::Delegate<quote_t>::OnDispatchHandler;
using trade_t = const Trade&;
using tradehandler_t = ou::Delegate<trade_t>::OnDispatchHandler;
using depthbymm_t = const DepthByMM&;
using depthbymmhandler_t = ou::Delegate<depthbymm_t>::OnDispatchHandler;
using depthbyorder_t = const DepthByOrder&;
using depthbyorderhandler_t = ou::Delegate<depthbyorder_t>::OnDispatchHandler;
using greek_t = const Greek&;
using greekhandler_t = ou::Delegate<greek_t>::OnDispatchHandler;
// these handlers are typically updated through the provider, rather than through client code
void AddOnOpenHandler( tradehandler_t );
void RemoveOnOpenHandler( tradehandler_t );
size_t GetOpenHandlerCount() const { return m_OnOpen.Size(); };
bool AddQuoteHandler( quotehandler_t );
bool RemoveQuoteHandler( quotehandler_t );
size_t GetQuoteHandlerCount() const { return m_OnQuote.Size(); };
bool AddTradeHandler( tradehandler_t );
bool RemoveTradeHandler( tradehandler_t );
size_t GetTradeHandlerCount() const { return m_OnTrade.Size(); };
bool AddDepthByMMHandler( depthbymmhandler_t );
bool RemoveDepthByMMHandler( depthbymmhandler_t );
size_t GetDepthByMMHandlerCount() const { return m_OnDepthByMM.Size(); };
bool AddDepthByOrderHandler( depthbyorderhandler_t );
bool RemoveDepthByOrderHandler( depthbyorderhandler_t );
size_t GetDepthByOrderHandlerCount() const { return m_OnDepthByOrder.Size(); };
bool AddGreekHandler( greekhandler_t );
bool RemoveGreekHandler( greekhandler_t );
size_t GetGreekHandlerCount() const { return m_OnGreek.Size(); };
// these are typically used by the provider only
bool OpenWatchNeeded() const { return !m_OnOpen.IsEmpty(); };
bool QuoteWatchNeeded() const { return !m_OnQuote.IsEmpty(); };
bool TradeWatchNeeded() const { return !m_OnTrade.IsEmpty(); };
bool DepthByMMWatchNeeded() const { return !m_OnDepthByMM.IsEmpty(); };
bool DepthByOrderWatchNeeded() const { return !m_OnDepthByOrder.IsEmpty(); };
bool GreekWatchNeeded() const { return !m_OnGreek.IsEmpty(); };
void SetContext( boost::asio::io_context& );
protected:
idSymbol_t m_id; // may be overwritten with provider specific override
pInstrument_t m_pInstrument; // composition rather than inheritance as same instrument refers to different market data and order providers
ou::Delegate<trade_t> m_OnOpen; // first value upon market opening
ou::Delegate<quote_t> m_OnQuote;
ou::Delegate<trade_t> m_OnTrade;
ou::Delegate<depthbymm_t> m_OnDepthByMM;
ou::Delegate<depthbyorder_t> m_OnDepthByOrder;
ou::Delegate<greek_t> m_OnGreek;
bool m_bStrand;
std::unique_ptr<boost::asio::io_context::strand> m_pStrand;
private:
};
template <typename S> // S for Provider specific CRTP Symbol type
class Symbol: public SymbolBase {
public:
using pSymbol_t = boost::shared_ptr<S>;
Symbol( pInstrument_t pInstrument ) : SymbolBase( pInstrument ) {};
Symbol( pInstrument_t pInstrument, const std::string& sName ) : SymbolBase( pInstrument, sName ) {};
virtual ~Symbol() {};
protected:
private:
};
} // namespace tf
} // namespace ou