-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathBarFactory.h
72 lines (58 loc) · 2.81 KB
/
BarFactory.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
/************************************************************************
* Copyright(c) 2009, 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. *
************************************************************************/
#pragma once
#include "DatedDatum.h"
#include <OUCommon/FastDelegate.h>
using namespace fastdelegate;
namespace ou { // One Unified
namespace tf { // TradeFrame
class BarFactory {
public:
typedef unsigned long duration_t; // seconds
typedef Bar::volume_t volume_t;
typedef Bar::price_t price_t;
BarFactory( duration_t nSeconds = 60);
virtual ~BarFactory();
void Add( const ptime &, price_t, volume_t);
void Add( const Trade &trade ) { Add( trade.DateTime(), trade.Price(), trade.Volume() ); };
Bar getCurrentBar() const { return m_bar; };
void SetBarWidth( duration_t seconds ) { m_nBarWidthSeconds = seconds; };
duration_t GetBarWidth() const { return m_nBarWidthSeconds; };
typedef FastDelegate1<const Bar&> OnNewBarStartedHandler; // turn this into a phoenix lambda function?
void SetOnNewBarStarted( OnNewBarStartedHandler function ) {
OnNewBarStarted = function;
}
typedef FastDelegate1<const Bar&> OnBarUpdatedHandler; // turn this into a phoenix lambda function?
void SetOnBarUpdated( OnBarUpdatedHandler function ) { // called at most once a second
OnBarUpdated = function;
}
typedef FastDelegate1<const Bar&> OnBarCompleteHandler; // turn this into a phoenix lambda function?
void SetOnBarComplete( OnBarCompleteHandler function ) {
OnBarComplete = function;
}
protected:
duration_t m_nBarWidthSeconds;
duration_t m_nBarWidthSecondsBy2; // shift bar over half a bar for chartdir
duration_t m_curInterval; // current bar interval
ptime m_dtBarStart;
ptime m_dtLastIntermediateEmission; // changes emitted no less than 1 second apart
boost::posix_time::time_duration m_1Sec;
Bar m_bar;
OnNewBarStartedHandler OnNewBarStarted;
OnBarUpdatedHandler OnBarUpdated;
OnBarCompleteHandler OnBarComplete;
private:
};
} // namespace tf
} // namespace ou