hikyuu2/hikyuu_cpp/hikyuu/StockManager.h

238 lines
6.5 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* StockManager.h
*
* Created on: 2011-11-9
* Author: fasiondog
*/
#ifndef STOCKMANAGER_H_
#define STOCKMANAGER_H_
#include <hikyuu_utils/iniparser/IniParser.h>
#include "utilities/Parameter.h"
#include "data_driver/DataDriverFactory.h"
2016-04-03 00:08:31 +08:00
#include "Block.h"
2015-01-07 01:26:14 +08:00
#include "MarketInfo.h"
#include "StockTypeInfo.h"
namespace hku {
typedef vector<string> MarketList;
2017-10-13 01:50:11 +08:00
Parameter default_preload_param();
Parameter default_other_param();
2017-10-13 01:50:11 +08:00
2015-01-07 01:26:14 +08:00
/**
*
* @ingroup StockManage
*/
class HKU_API StockManager {
public:
/** 获取StockManager单例实例 */
static StockManager& instance();
virtual ~StockManager();
/**
*
* @param baseInfoParam
* @param blockParam
* @param kdataParam
* @param preloadParam
* @param hikyuuParam
2015-01-07 01:26:14 +08:00
*/
void init(const Parameter& baseInfoParam,
const Parameter& blockParam,
const Parameter& kdataParam,
const Parameter& preloadParam = default_preload_param(),
const Parameter& hikyuuParam = default_other_param());
2017-10-13 01:50:11 +08:00
Parameter getBaseInfoDriverParameter() const;
Parameter getBlockDriverParameter() const;
Parameter getKDataDriverParameter() const;
Parameter getPreloadParameter() const;
Parameter getHikyuuParameter() const;
BaseInfoDriverPtr getBaseInfoDriver() const;
void setKDataDriver(const KDataDriverPtr&);
2015-01-07 01:26:14 +08:00
/**
*
* m_config中的tmpdir
*/
string tmpdir() const;
/** 获取数据目录 */
string datadir() const;
2015-01-07 01:26:14 +08:00
/** 获取证券数量 */
size_t size() const;
/**
* "市场简称证券代码"
* @param querystr "sh000001"
* @return Null<Stock>()
*/
Stock getStock(const string&) const;
/** 同 getStock @see getStock */
Stock operator[](const string&) const;
/**
*
* @param market
* @return Null<MarketInfo>()
*/
MarketInfo getMarketInfo(const string& market) const;
/**
*
* @param type
* @return Null<StockTypeInf>()
*/
StockTypeInfo getStockTypeInfo(hku_uint32 type) const;
/** 获取市场简称列表 */
MarketList getAllMarket() const;
2016-04-03 00:08:31 +08:00
/**
*
* @param category
* @param name
* @return
*/
Block getBlock(const string& category, const string& name);
/**
*
* @param category
* @return
*/
BlockList getBlockList(const string&);
/**
*
* @return
*/
BlockList getBlockList();
//目前支持"SH"
DatetimeList getTradingCalendar(const KQuery& query,
const string& market = "SH");
2015-01-07 01:26:14 +08:00
/**
* StockBaseInfoDriver子类使用
* @param stock
* @return true | false
*/
bool addStock(const Stock& stock);
/**
*
* @param marketInfo
* @return
*/
bool addMarketInfo(const MarketInfo& marketInfo);
/**
*
* @param stkTypeInfo
* @return
*/
bool addStockTypeInfo(const StockTypeInfo& stkTypeInfo);
/**
* CSV文件K线数据StockCSV格式的K线数据时
* @details Stockmarket为TMP
* @param code Stock相同Null<Stock>
* @param day_filename 线CSV文件名
* @param min_filename 线CSV文件名
* @param tick 0.01
* @param tickValue 0.01
* @param precision 2
* @param minTradeNumber 1
* @param maxTradeNumber 1000000
* @return
*/
Stock addTempCsvStock(const string& code,
const string& day_filename,
const string& min_filename,
price_t tick = 0.01,
price_t tickValue = 0.01,
int precision = 2,
size_t minTradeNumber = 1,
size_t maxTradeNumber = 1000000);
/**
* Stock
* @param code
*/
void removeTempCsvStock(const string& code);
2015-01-07 01:26:14 +08:00
public:
2016-04-03 00:08:31 +08:00
typedef StockMapIterator const_iterator;
const_iterator begin() const { return m_stockDict.begin(); }
const_iterator end() const { return m_stockDict.end(); }
2015-01-07 01:26:14 +08:00
private:
StockManager() { }
private:
static shared_ptr<StockManager> m_sm;
2017-10-13 01:50:11 +08:00
string m_tmpdir;
string m_datadir;
BlockInfoDriverPtr m_blockDriver;
2016-04-03 00:08:31 +08:00
StockMapIterator::stock_map_t m_stockDict; // SH000001 -> stock
typedef unordered_map<string, MarketInfo> MarketInfoMap;
MarketInfoMap m_marketInfoDict;
typedef unordered_map<hku_uint32, StockTypeInfo> StockTypeInfoMap;
StockTypeInfoMap m_stockTypeInfo;
Parameter m_baseInfoDriverParam;
Parameter m_blockDriverParam;
Parameter m_kdataDriverParam;
Parameter m_preloadParam;
Parameter m_hikyuuParam;
2015-01-07 01:26:14 +08:00
};
inline size_t StockManager::size() const {
return m_stockDict.size();
}
inline Stock StockManager::operator[](const string& query) const {
return getStock(query);
}
inline Parameter StockManager::getBaseInfoDriverParameter() const {
return m_baseInfoDriverParam;
}
inline Parameter StockManager::getBlockDriverParameter() const {
return m_blockDriverParam;
}
inline Parameter StockManager::getKDataDriverParameter() const {
return m_kdataDriverParam;
}
inline Parameter StockManager::getPreloadParameter() const {
return m_preloadParam;
}
inline Parameter StockManager::getHikyuuParameter() const {
return m_hikyuuParam;
}
inline BaseInfoDriverPtr StockManager::getBaseInfoDriver() const {
return DataDriverFactory::getBaseInfoDriver(m_baseInfoDriverParam);
}
2015-01-07 01:26:14 +08:00
} /* namespace */
#endif /* STOCKMANAGER_H_ */