2015-01-07 01:26:14 +08:00
|
|
|
|
/*
|
|
|
|
|
* BaseInfoDriver.h
|
|
|
|
|
*
|
|
|
|
|
* Created on: 2012-8-14
|
|
|
|
|
* Author: fasiondog
|
|
|
|
|
*/
|
|
|
|
|
|
2019-08-03 21:53:24 +08:00
|
|
|
|
#pragma once
|
2015-01-07 01:26:14 +08:00
|
|
|
|
#ifndef BASEINFODRIVER_H_
|
|
|
|
|
#define BASEINFODRIVER_H_
|
|
|
|
|
|
2021-02-07 00:56:04 +08:00
|
|
|
|
#include <unordered_set>
|
2017-10-09 02:25:02 +08:00
|
|
|
|
#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
|
|
|
|
*/
|
2017-10-09 02:25:02 +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;
|
2020-10-01 22:52:50 +08:00
|
|
|
|
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 驱动名称
|
|
|
|
|
*/
|
2017-10-09 02:25:02 +08:00
|
|
|
|
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
|
|
|
|
/** 获取驱动名称 */
|
2017-10-09 02:25:02 +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;
|
|
|
|
|
|
2021-02-11 18:06:18 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取指定的证券信息
|
|
|
|
|
* @param market 市场简称
|
|
|
|
|
* @param code 证券代码
|
|
|
|
|
*/
|
|
|
|
|
virtual StockInfo getStockInfo(string market, const string& code) = 0;
|
|
|
|
|
|
2020-10-28 00:03:04 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取指定日期范围内 [start, end) 的权限列表
|
2020-10-29 00:03:25 +08:00
|
|
|
|
* @param market 市场简称
|
|
|
|
|
* @param code 证券代码
|
2020-10-28 00:03:04 +08:00
|
|
|
|
* @param start 起始日期
|
|
|
|
|
* @param end 结束日期
|
|
|
|
|
*/
|
2020-10-29 00:03:25 +08:00
|
|
|
|
virtual StockWeightList getStockWeightList(const string& market, const string& code,
|
|
|
|
|
Datetime start, Datetime end);
|
2020-10-28 00:03:04 +08:00
|
|
|
|
|
2019-04-07 22:55:47 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取当前财务信息
|
|
|
|
|
* @param market 市场标识
|
|
|
|
|
* @param code 证券代码
|
|
|
|
|
*/
|
|
|
|
|
virtual Parameter getFinanceInfo(const string& market, const string& code);
|
|
|
|
|
|
2021-01-25 00:31:47 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取指定的MarketInfo
|
|
|
|
|
* @param market 市场简称
|
|
|
|
|
* @return 如未找到,则返回 Null<MarketInfo>()
|
|
|
|
|
*/
|
2021-01-27 00:37:59 +08:00
|
|
|
|
virtual MarketInfo getMarketInfo(const string& market) = 0;
|
2021-01-25 00:31:47 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2021-01-27 00:37:59 +08:00
|
|
|
|
* 获取全部市场信息
|
2021-01-25 00:31:47 +08:00
|
|
|
|
*/
|
2021-01-27 00:37:59 +08:00
|
|
|
|
virtual vector<MarketInfo> getAllMarketInfo() = 0;
|
2021-01-25 00:31:47 +08:00
|
|
|
|
|
2017-10-09 02:25:02 +08:00
|
|
|
|
/**
|
2021-01-27 00:37:59 +08:00
|
|
|
|
* 获取全部证券类型信息
|
2017-10-09 02:25:02 +08:00
|
|
|
|
*/
|
2021-01-27 00:37:59 +08:00
|
|
|
|
virtual vector<StockTypeInfo> getAllStockTypeInfo() = 0;
|
2017-10-09 02:25:02 +08:00
|
|
|
|
|
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
|
|
|
|
|
2021-02-07 00:56:04 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取所有节假日日期
|
|
|
|
|
*/
|
|
|
|
|
virtual std::unordered_set<Datetime> getAllHolidays() = 0;
|
|
|
|
|
|
2017-10-09 02:25:02 +08:00
|
|
|
|
private:
|
|
|
|
|
bool checkType();
|
2015-01-07 01:26:14 +08:00
|
|
|
|
|
|
|
|
|
protected:
|
2017-10-09 02:25:02 +08:00
|
|
|
|
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&);
|
2017-10-09 02:25:02 +08:00
|
|
|
|
|
|
|
|
|
inline const string& BaseInfoDriver::name() const {
|
|
|
|
|
return m_name;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 01:26:14 +08:00
|
|
|
|
} /* namespace hku */
|
|
|
|
|
#endif /* BASEINFODRIVER_H_ */
|