-
Notifications
You must be signed in to change notification settings - Fork 163
/
SimulationProvider.h
139 lines (102 loc) · 4.73 KB
/
SimulationProvider.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
134
135
136
137
138
139
/************************************************************************
* Copyright(c) 2009, One Unified. All rights reserved. *
* email: info@oneunified.net *
* *
* 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 <thread>
#include <string>
#include <sstream>
#include <OUCommon/FastDelegate.h>
using namespace fastdelegate;
#include <OUCommon/TimeSource.h>
#include <TFTrading/Order.h>
#include "SimulationSymbol.h"
#include "SimulationInterface.hpp"
namespace ou { // One Unified
namespace tf { // TradeFrame
class MergeDatedDatums;
// simulation provider needs to send an open event on each symbol it does
// will need to be based upon time
// looks like MergeDatedDatums will need an OnOpen event simulated
// 20100821: todo: provide cache mechanism for multiple runs
// first time through, use the minheap,
// subsequent times through, scan a vector
class SimulationProvider
: public sim::SimulationInterface<SimulationProvider,SimulationSymbol>
{
friend sim::SimulationInterface<SimulationProvider,SimulationSymbol>;
public:
using inherited_t = sim::SimulationInterface<SimulationProvider,SimulationSymbol>;
using pSymbol_t = inherited_t::pSymbol_t;
using pOrder_t = Order::pOrder_t;
using pInstrument_t = Instrument::pInstrument_t;
using pInstrument_cref = Instrument::pInstrument_cref;
using pProvider_t = std::shared_ptr<SimulationProvider>;
SimulationProvider();
virtual ~SimulationProvider();
static pProvider_t Factory() {
return std::make_shared<SimulationProvider>();
}
static pProvider_t Cast( pProvider_t pProvider ) {
return std::dynamic_pointer_cast<SimulationProvider>( pProvider );
}
virtual void Connect();
virtual void Disconnect();
void SetHdf5FileName( const std::string& );
const std::string& GetGdf5FileName() const { return m_sHdf5FileName; }
void SetGroupDirectory( const std::string& ); // eg /basket/20080620
const std::string& GetGroupDirectory() const { return m_sGroupDirectory; }
void Run( bool bAsync = true );
void Stop();
using OnSimulationThreadStarted_t = FastDelegate0<>; // Allows Singleton LocalCommonInstances to be set, called within new thread
void SetOnSimulationThreadStarted( OnSimulationThreadStarted_t function ) {
m_OnSimulationThreadStarted = function;
}
using OnSimulationThreadEnded_t = FastDelegate0<>; // Allows Singleton LocalCommonInstances to be reset
void SetOnSimulationThreadEnded( OnSimulationThreadEnded_t function ) {
m_OnSimulationThreadEnded = function;
}
using OnSimulationComplete_t = FastDelegate0<>;
void SetOnSimulationComplete( OnSimulationComplete_t function ) {
m_OnSimulationComplete = function;
}
void EmitStats( std::stringstream& ss );
protected:
std::string m_sHdf5FileName;
std::string m_sGroupDirectory;
ptime m_dtSimStart;
ptime m_dtSimStop;
unsigned long m_nProcessedDatums;
MergeDatedDatums* m_pMerge;
pSymbol_t virtual NewCSymbol( pInstrument_t pInstrument );
void StartQuoteWatch( pSymbol_t pSymbol );
void StopQuoteWatch( pSymbol_t Symbol );
void StartTradeWatch( pSymbol_t pSymbol );
void StopTradeWatch( pSymbol_t pSymbol );
void StartDepthByMMWatch( pSymbol_t pSymbol );
void StopDepthByMMWatch( pSymbol_t pSymbol );
void StartDepthByOrderWatch( pSymbol_t pSymbol );
void StopDepthByOrderWatch( pSymbol_t pSymbol );
void StartGreekWatch( pSymbol_t pSymbol );
void StopGreekWatch( pSymbol_t pSymbol );
OnSimulationThreadStarted_t m_OnSimulationThreadStarted;
OnSimulationThreadEnded_t m_OnSimulationThreadEnded;
OnSimulationComplete_t m_OnSimulationComplete;
void Merge(); // the background thread
void HandleExecution( Order::idOrder_t orderId, const Execution &exec );
void HandleCommission( Order::idOrder_t orderId, double commission );
void HandleCancellation( Order::idOrder_t orderId );
private:
std::thread m_threadMerge;
};
} // namespace tf
} // namespace ou