-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathInstrumentInformation.cpp
61 lines (50 loc) · 3.18 KB
/
InstrumentInformation.cpp
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
/************************************************************************
* 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. *
************************************************************************/
#include "stdafx.h"
#include "InstrumentInformation.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
CInstrumentInformation::CInstrumentInformation( const std::string& sDbFileName )
: CCommonDatabaseFunctions<CInstrumentInformation>( sDbFileName, "InstrumentInformation" ) {
}
CInstrumentInformation::~CInstrumentInformation(void) {
}
void CInstrumentInformation::Save(const std::string &sSymbol, const std::string &sCompanyName,
float fltPriceEarnings, float fltEarningsPerShare,
float fltDividend, boost::posix_time::ptime dtLastDividend,
float fltPctInstitutional, float fltSharesOutstanding,
float fltAssets, float fltLiabilities,
float fltLongTermDebt, boost::posix_time::ptime dtBalanceSheet,
char nFormatCode, char nPrecision, int nSIC,
char nSecurityType, char nListedMarket) {
structKey key( sSymbol.size(), sSymbol.c_str() );
structValues values( fltPriceEarnings, fltDividend, dtLastDividend, fltEarningsPerShare,
fltPctInstitutional, fltAssets, fltLiabilities, dtBalanceSheet, fltLongTermDebt,
fltSharesOutstanding, nFormatCode, nPrecision, nSIC, nSecurityType, nListedMarket, sCompanyName );
Dbt k( (void*) &key, sizeof( structKey ) - nMaxSymbolNameSize + key.nKeySize );
Dbt v( (void*) &values, sizeof( structValues ) - nMaxCompanyNameSize + values.nCompanyNameSize );
int ret = m_pdb->put( 0, &k, &v, 0 );
if ( 0 != ret ) throw std::runtime_error( "CInstrumentInformation::Save put had error" );
}
// use Dbt v concept from CInstrumentFile::CreateInstrumentFromIQFeed
void CInstrumentInformation::Retrieve(const std::string &sSymbol) {
structKey key( sSymbol.size(), sSymbol.c_str() );
Dbt k( (void*) &key, sizeof( structKey ) - nMaxSymbolNameSize + key.nKeySize );
Dbt v;
int ret = m_pdb->get( 0, &k, &v, 0 );
if ( DB_NOTFOUND == ret ) throw std::out_of_range( "CInstrumentInformation::Retrieve key not found" );
if ( 0 != ret ) throw std::runtime_error( "CInstrumentInformation::Retrieve get had error" );
m_pValues = (structValues *) v.get_data();
}
} // namespace tf
} // namespace ou