-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathGridIBPositionDetails_impl.h
171 lines (140 loc) · 6.44 KB
/
GridIBPositionDetails_impl.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/************************************************************************
* Copyright(c) 2015, 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 December 30, 2015, 4:51 PM
#pragma once
#define FUSION_MAX_VECTOR_SIZE 13
#include <map>
#include <boost/fusion/container/vector/vector20.hpp>
#include <boost/fusion/include/vector20.hpp>
#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/fusion/include/for_each.hpp>
#include <boost/fusion/algorithm/iteration/fold.hpp>
#include <boost/fusion/include/fold.hpp>
#include <boost/fusion/sequence/intrinsic/at_c.hpp>
#include <boost/fusion/include/at_c.hpp>
#include <boost/fusion/algorithm/transformation/filter.hpp>
#include <boost/fusion/include/filter.hpp>
#include <boost/serialization/version.hpp>
#include <boost/serialization/split_member.hpp>
#include <wx/grid.h> // needed for the ModelCell_macros
#include <TFVuTrading/ModelCell.h>
#include <TFVuTrading/ModelCell_ops.h>
#include <TFVuTrading/ModelCell_macros.h>
#include "GridIBPositionDetails.h"
// modelled after "PanelPortfolioPosition_impl.h", which needs to be updated for wxGrid?
namespace ou { // One Unified
namespace tf { // TradeFrame
struct GridIBPositionDetails_impl {
//public:
GridIBPositionDetails_impl( GridIBPositionDetails& );
virtual ~GridIBPositionDetails_impl();
//private:
// for columns: wxALIGN_LEFT, wxALIGN_CENTRE or wxALIGN_RIGHT
#define GRID_ARRAY_PARAM_COUNT 5
#define GRID_ARRAY_COL_COUNT 12
#define GRID_ARRAY \
(GRID_ARRAY_COL_COUNT, \
( /* Col 0, 1, 2, 3, 4, */ \
(COL_Symbol1 , "Sym1", wxALIGN_LEFT, 60, ModelCellString ), \
(COL_Symbol2 , "Sym2", wxALIGN_LEFT, 120, ModelCellString ), \
(COL_Expiry , "Expiry", wxALIGN_LEFT, 75, ModelCellString ), \
(COL_Exchange , "Exchng", wxALIGN_LEFT, 70, ModelCellString ), \
(COL_Multiple , "Mltpl", wxALIGN_RIGHT, 50, ModelCellString ), \
(COL_Quan , "Quan", wxALIGN_RIGHT, 60, ModelCellInt ), \
(COL_Price , "Price", wxALIGN_RIGHT, 60, ModelCellDouble ), \
(COL_Value , "Value", wxALIGN_RIGHT, 80, ModelCellDouble ), \
(COL_Cost , "Cost", wxALIGN_RIGHT, 80, ModelCellDouble ), \
(COL_UPNL , "UPNL", wxALIGN_RIGHT, 80, ModelCellDouble ), \
(COL_RPNL , "RPNL", wxALIGN_RIGHT, 80, ModelCellDouble ), \
(COL_Currency , "Crncy", wxALIGN_LEFT, 50, ModelCellString ), \
) \
) \
/**/
enum {
BOOST_PP_REPEAT(GRID_ARRAY_COL_COUNT,GRID_EXTRACT_ENUM_LIST,0)
};
typedef boost::fusion::VECTOR_DEF<
BOOST_PP_REPEAT(GRID_ARRAY_COL_COUNT,COMPOSE_MODEL_CELL,4)
> vModelCells_t;
class PositionDetailRow {
public:
PositionDetailRow( wxGrid& grid, int row ): m_grid( grid ), m_row( row ) { Init(); }
PositionDetailRow( const PositionDetailRow& rhs ): m_grid( rhs.m_grid ), m_row( rhs.m_row ) { Init(); }
~PositionDetailRow( void ) {}
void UpdateGui( void ) {
boost::fusion::for_each( m_vModelCells, ModelCell_ops::UpdateGui( m_grid, m_row ) );
}
void UpdatePositionDetail( const ou::tf::ib::TWS::PositionDetail& pd ) {
boost::fusion::at_c<COL_Symbol1>( m_vModelCells ).SetValue( pd.sSymbol );
boost::fusion::at_c<COL_Symbol2>( m_vModelCells ).SetValue( pd.sLocalSymbol );
boost::fusion::at_c<COL_Expiry>( m_vModelCells ).SetValue( pd.sExpiry );
boost::fusion::at_c<COL_Exchange>( m_vModelCells ).SetValue( pd.sExchange );
boost::fusion::at_c<COL_Multiple>( m_vModelCells ).SetValue( pd.sMultiplier );
boost::fusion::at_c<COL_Quan>( m_vModelCells ).SetValue( pd.position );
boost::fusion::at_c<COL_Price>( m_vModelCells ).SetValue( pd.marketPrice );
boost::fusion::at_c<COL_Value>( m_vModelCells ).SetValue( pd.marketValue );
boost::fusion::at_c<COL_Cost>( m_vModelCells ).SetValue( pd.averageCost );
boost::fusion::at_c<COL_UPNL>( m_vModelCells ).SetValue( pd.unrealizedPNL );
boost::fusion::at_c<COL_RPNL>( m_vModelCells ).SetValue( pd.realizedPNL );
boost::fusion::at_c<COL_Currency>( m_vModelCells ).SetValue( pd.sCurrency );
m_contract = pd.contract;
}
protected:
private:
long m_contract;
wxGrid& m_grid;
int m_row;
vModelCells_t m_vModelCells;
void Init( void ) {
boost::fusion::fold( m_vModelCells, 0, ModelCell_ops::SetCol() );
BOOST_PP_REPEAT(GRID_ARRAY_COL_COUNT,COL_ALIGNMENT,m_row)
}
};
GridIBPositionDetails& m_pad; // passed in on construction
typedef std::map<std::string,PositionDetailRow> mapPositionDetailRow_t;
mapPositionDetailRow_t m_mapPositionDetailRow;
void CreateControls();
void DestroyControls();
void UpdatePositionDetailRow( const ou::tf::ib::TWS::PositionDetail& ad );
void OnClose( wxCloseEvent& event );
template<typename Archive>
void save( Archive& ar, const unsigned int version ) const {
//ar & boost::serialization::base_object<const TreeItemResources>(*this);
int cnt = m_pad.GetNumberCols();
ar & cnt;
for ( int ix = 0; ix < cnt; ix++ ) {
ar & m_pad.GetColSize( ix );
}
}
template<typename Archive>
void load( Archive& ar, const unsigned int version ) {
//ar & boost::serialization::base_object<TreeItemResources>(*this);
int cnt;
ar & cnt;
assert( cnt == m_pad.GetNumberCols() );
int width;
for ( int ix = 0; ix < cnt; ix++ ) {
ar & width;
m_pad.SetColSize( ix, width );
}
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
template<class Archive>
void GridIBPositionDetails::serialize(Archive & ar, const unsigned int file_version){
ar & *m_pimpl;
}
} // namespace tf
} // namespace ou
BOOST_CLASS_VERSION(ou::tf::GridIBPositionDetails_impl, 1)