hikyuu2/hikyuu_cpp/hikyuu/data_driver/BaseInfoDriver.h

168 lines
4.1 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* BaseInfoDriver.h
*
* Created on: 2012-8-14
* Author: fasiondog
*/
#pragma once
2015-01-07 01:26:14 +08:00
#ifndef BASEINFODRIVER_H_
#define BASEINFODRIVER_H_
#include <unordered_set>
#include "../utilities/Parameter.h"
2015-01-07 01:26:14 +08:00
#include "../MarketInfo.h"
#include "../StockTypeInfo.h"
#include "../Stock.h"
2021-01-28 00:43:53 +08:00
#include "../utilities/db_connect/SQLStatementBase.h"
2015-01-07 01:26:14 +08:00
namespace hku {
2021-01-28 00:43:53 +08:00
struct StockInfo {
StockInfo()
: type(Null<uint32_t>()),
valid(0),
startDate(0),
endDate(0),
precision(1),
tick(0.0),
tickValue(0.0),
minTradeNumber(0.0),
maxTradeNumber(0.0) {}
static const char* getSelectSQL() {
return "select c.market, a.code, a.name, a.type, a.valid, a.startDate, a.endDate, b.tick, "
"b.tickValue, b.precision, b.minTradeNumber, b.maxTradeNumber from stock a, "
"StockTypeInfo b, market c where a.type = b.id and a.marketid = c.marketid";
}
void load(const SQLStatementPtr& st) {
st->getColumn(0, market, code, name, type, valid, startDate, endDate, tick, tickValue,
precision, minTradeNumber, maxTradeNumber);
}
string market;
string code;
string name;
uint32_t type;
uint32_t valid;
uint64_t startDate;
uint64_t endDate;
uint32_t precision;
double tick;
double tickValue;
double minTradeNumber;
double maxTradeNumber;
};
2015-01-07 01:26:14 +08:00
/**
*
2020-06-26 21:39:53 +08:00
* @ingroup DataDriver
2015-01-07 01:26:14 +08:00
*/
class HKU_API BaseInfoDriver {
PARAMETER_SUPPORT
2015-01-07 01:26:14 +08:00
public:
2016-04-03 00:08:31 +08:00
typedef unordered_map<string, MarketInfo> MarketInfoMap;
typedef unordered_map<uint32_t, StockTypeInfo> StockTypeInfoMap;
2016-04-03 00:08:31 +08:00
2020-06-26 21:39:53 +08:00
/**
*
* @param name
*/
BaseInfoDriver(const string& name);
2019-11-10 23:31:41 +08:00
virtual ~BaseInfoDriver() {}
2015-01-07 01:26:14 +08:00
2020-06-26 21:39:53 +08:00
/** 获取驱动名称 */
const string& name() const;
/**
*
* @param params
* @return
*/
bool init(const Parameter& params);
2021-01-28 00:43:53 +08:00
/**
*
* @return
*/
virtual bool _init() = 0;
/**
*
*/
virtual vector<StockInfo> getAllStockInfo() = 0;
/**
*
* @param market
* @param code
*/
virtual StockInfo getStockInfo(string market, const string& code) = 0;
/**
* [start, end)
* @param market
* @param code
* @param start
* @param end
*/
virtual StockWeightList getStockWeightList(const string& market, const string& code,
Datetime start, Datetime end);
/**
*
* @param market
* @param code
*/
virtual Parameter getFinanceInfo(const string& market, const string& code);
/**
* MarketInfo
* @param market
* @return Null<MarketInfo>()
*/
2021-01-27 00:37:59 +08:00
virtual MarketInfo getMarketInfo(const string& market) = 0;
/**
2021-01-27 00:37:59 +08:00
*
*/
2021-01-27 00:37:59 +08:00
virtual vector<MarketInfo> getAllMarketInfo() = 0;
/**
2021-01-27 00:37:59 +08:00
*
*/
2021-01-27 00:37:59 +08:00
virtual vector<StockTypeInfo> getAllStockTypeInfo() = 0;
2015-01-07 01:26:14 +08:00
/**
2021-01-27 00:37:59 +08:00
*
* @param type
* @return Null<StockTypeInf>()
2015-01-07 01:26:14 +08:00
*/
2021-01-27 00:37:59 +08:00
virtual StockTypeInfo getStockTypeInfo(uint32_t type) = 0;
2015-01-07 01:26:14 +08:00
/**
*
*/
virtual std::unordered_set<Datetime> getAllHolidays() = 0;
private:
bool checkType();
2015-01-07 01:26:14 +08:00
protected:
string m_name;
2015-01-07 01:26:14 +08:00
};
typedef shared_ptr<BaseInfoDriver> BaseInfoDriverPtr;
2019-11-10 23:31:41 +08:00
HKU_API std::ostream& operator<<(std::ostream&, const BaseInfoDriver&);
HKU_API std::ostream& operator<<(std::ostream&, const BaseInfoDriverPtr&);
inline const string& BaseInfoDriver::name() const {
return m_name;
}
2015-01-07 01:26:14 +08:00
} /* namespace hku */
#endif /* BASEINFODRIVER_H_ */