-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathAdapters.h
45 lines (38 loc) · 1.76 KB
/
Adapters.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
/************************************************************************
* Copyright(c) 2013, One Unified. All rights reserved. *
* email: [email protected] *
* *
* 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. *
************************************************************************/
// Started 2013/10/01
#pragma once
#include "TimeSeries.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
template<typename TS> // TS -> TimeSeries
class PriceAdapter: public Prices {
public:
PriceAdapter( TS& ts ) : m_ts( ts ) {
m_ts.OnAppend.Add( MakeDelegate( this, &PriceAdapter::HandleUpdate ) );
}
~PriceAdapter( void ) {
m_ts.OnAppend.Remove( MakeDelegate( this, &PriceAdapter::HandleUpdate ) );
}
protected:
private:
TS& m_ts;
void HandleUpdate( const typename TS::datum_t& datum ) {
Prices::Append( Price( datum.DateTime(), GetPrice( datum ) ) );
}
double GetPrice( const Quote& quote ) const { return quote.Midpoint(); };
double GetPrice( const Trade& trade ) const { return trade.Price(); };
};
} // namespace tf
} // namespace ou