-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileStore.cpp
More file actions
86 lines (80 loc) · 2.33 KB
/
Copy pathFileStore.cpp
File metadata and controls
86 lines (80 loc) · 2.33 KB
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
#include "FileStore.h"
#include <iostream>
#include "ThostFtdcUserApiStruct.h"
FileStore::FileStore(const std::string& path)
: base_path_(path)
{
std::cout << "Base Save Path " << path << std::endl;
}
FileStore::~FileStore()
{
std::cout << "~FileStore " << std::endl;
SaveAllFiles();
}
void FileStore::OnData(CThostFtdcDepthMarketDataField* data)
{
const std::string instrumet = data->InstrumentID;
auto iter = store_files_.find(instrumet);
if (iter != store_files_.end())
{
(*iter->second)
<< data->TradingDay << ','
<< data->InstrumentID << ','
<< data->ExchangeID << ','
<< data->ExchangeInstID << ','
<< data->LastPrice << ','
<< data->PreSettlementPrice << ','
<< data->PreClosePrice << ','
<< data->PreOpenInterest << ','
<< data->OpenPrice << ','
<< data->HighestPrice << ','
<< data->LowestPrice << ','
<< data->Volume << ','
<< data->Turnover << ','
<< data->OpenInterest << ','
<< data->ClosePrice << ','
<< data->SettlementPrice << ','
<< data->UpperLimitPrice << ','
<< data->LowerLimitPrice << ','
<< data->PreDelta << ','
<< data->CurrDelta << ','
<< data->UpdateTime << ','
<< data->UpdateMillisec << ','
<< data->BidPrice1 << ','
<< data->BidVolume1 << ','
<< data->AskPrice1 << ','
<< data->AskVolume1 << ','
<< data->AveragePrice << ','
<< data->ActionDay << std::endl;
}
else
{
std::cout << __FUNCTION__ << " file not exist for " << instrumet << std::endl;
}
}
void FileStore::ResetFiles(const std::string& day,
const std::set<std::string>& instruments)
{
std::cout << __FUNCTION__ << " Start" << std::endl;
SaveAllFiles();
store_files_.clear();
day_ = day;
for (auto each : instruments)
{
auto filepath = base_path_ + '_' + each + '_' + day_ + ".csv";
std::cout << __FUNCTION__ << " Create File " << filepath << std::endl;
auto filestream = std::make_shared<std::fstream>(filepath, std::ios_base::out | std::ios_base::app);
store_files_[each] = filestream;
}
std::cout << __FUNCTION__ << " End" << std::endl;
}
void FileStore::SaveAllFiles()
{
std::cout << "SaveAllFiles Base Path "<< base_path_ << " Day "<< day_ <<std::endl;
for (auto each : store_files_)
{
std::cout << each.first << std::endl;
each.second->close();
}
std::cout <<" SaveAllFiles end" << std::endl;
}