mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 10:59:43 +08:00
update for strategy trade
This commit is contained in:
parent
816557a3d6
commit
96a33080a0
@ -5,6 +5,6 @@
|
|||||||
* Author: fasiondog
|
* Author: fasiondog
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StrategyTradeManager.h"
|
#include "AccountTradeManager.h"
|
||||||
|
|
||||||
namespace hku {} // namespace hku
|
namespace hku {} // namespace hku
|
467
hikyuu_cpp/hikyuu/strategy/AccountTradeManager.h
Normal file
467
hikyuu_cpp/hikyuu/strategy/AccountTradeManager.h
Normal file
@ -0,0 +1,467 @@
|
|||||||
|
/*
|
||||||
|
* Copyright(C) 2021 hikyuu.org
|
||||||
|
*
|
||||||
|
* Create on: 2021-03-23
|
||||||
|
* Author: fasiondog
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../trade_manage/TradeManagerBase.h"
|
||||||
|
|
||||||
|
namespace hku {
|
||||||
|
|
||||||
|
class HKU_API AccountTradeManager : public TradeManagerBase {
|
||||||
|
public:
|
||||||
|
AccountTradeManager() = default;
|
||||||
|
AccountTradeManager(const string& name) : TradeManagerBase(name, TC_Zero()) {}
|
||||||
|
virtual ~AccountTradeManager() = default;
|
||||||
|
|
||||||
|
virtual void _reset() override {}
|
||||||
|
|
||||||
|
virtual shared_ptr<TradeManagerBase> _clone() override {
|
||||||
|
return std::make_shared<AccountTradeManager>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定对象的保证金比率
|
||||||
|
* @param datetime 日期
|
||||||
|
* @param stock 指定对象
|
||||||
|
*/
|
||||||
|
virtual double getMarginRate(const Datetime& datetime, const Stock& stock) override {
|
||||||
|
HKU_WARN("The subclass does not implement a getMarginRate method");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 初始资金 */
|
||||||
|
virtual price_t initCash() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 账户建立日期 */
|
||||||
|
virtual Datetime initDatetime() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return Datetime();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 第一笔买入交易发生日期,如未发生交易返回Null<Datetime>() */
|
||||||
|
virtual Datetime firstDatetime() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return Datetime();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 最后一笔交易日期,注意和交易类型无关,如未发生交易返回账户建立日期 */
|
||||||
|
virtual Datetime lastDatetime() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return Datetime();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回当前现金
|
||||||
|
* @note 仅返回当前信息,不会根据权息进行调整
|
||||||
|
*/
|
||||||
|
virtual price_t currentCash() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定日期的现金
|
||||||
|
* @note 如果不带日期参数,无法根据权息信息调整持仓
|
||||||
|
*/
|
||||||
|
virtual price_t cash(const Datetime& datetime, KQuery::KType ktype = KQuery::DAY) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前是否持有指定的证券
|
||||||
|
* @note 这里未使用日期参数,必须保证是按日期顺序执行
|
||||||
|
* @param stock 指定证券
|
||||||
|
* @return true 是 | false 否
|
||||||
|
*/
|
||||||
|
virtual bool have(const Stock& stock) const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前空头仓位是否持有指定的证券
|
||||||
|
* @note 这里未使用日期参数,必须保证是按日期顺序执行
|
||||||
|
* @param stock 指定证券
|
||||||
|
* @return true 是 | false 否
|
||||||
|
*/
|
||||||
|
virtual bool haveShort(const Stock& stock) const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 当前持有的证券种类数量 */
|
||||||
|
virtual size_t getStockNumber() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 当前空头持有的证券种类数量 */
|
||||||
|
virtual size_t getShortStockNumber() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取指定时刻的某证券持有数量 */
|
||||||
|
virtual double getHoldNumber(const Datetime& datetime, const Stock& stock) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取指定时刻的空头某证券持有数量 */
|
||||||
|
virtual double getShortHoldNumber(const Datetime& datetime, const Stock& stock) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取指定时刻已借入的股票数量 */
|
||||||
|
virtual double getDebtNumber(const Datetime& datetime, const Stock& stock) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取指定时刻已借入的现金额 */
|
||||||
|
virtual price_t getDebtCash(const Datetime& datetime) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取全部交易记录 */
|
||||||
|
virtual TradeRecordList getTradeList() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return TradeRecordList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定日期范围内的交易记录[start, end)
|
||||||
|
* @param start 起始日期
|
||||||
|
* @param end 结束日期
|
||||||
|
* @return 交易记录列表
|
||||||
|
*/
|
||||||
|
virtual TradeRecordList getTradeList(const Datetime& start,
|
||||||
|
const Datetime& end) const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return TradeRecordList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取当前全部持仓记录 */
|
||||||
|
virtual PositionRecordList getPositionList() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return PositionRecordList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取全部历史持仓记录,即已平仓记录 */
|
||||||
|
virtual PositionRecordList getHistoryPositionList() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return PositionRecordList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取当前全部空头仓位记录 */
|
||||||
|
virtual PositionRecordList getShortPositionList() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return PositionRecordList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取全部空头历史仓位记录 */
|
||||||
|
virtual PositionRecordList getShortHistoryPositionList() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return PositionRecordList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取指定证券的当前持仓记录,如当前未持有该票,返回Null<PositionRecord>() */
|
||||||
|
virtual PositionRecord getPosition(const Stock&) const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return PositionRecord();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取指定证券的当前空头仓位持仓记录,如当前未持有该票,返回Null<PositionRecord>() */
|
||||||
|
virtual PositionRecord getShortPosition(const Stock&) const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return PositionRecord();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取当前借入的股票列表 */
|
||||||
|
virtual BorrowRecordList getBorrowStockList() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return BorrowRecordList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存入资金
|
||||||
|
* @param datetime 存入时间
|
||||||
|
* @param cash 存入的资金量
|
||||||
|
* @return true | false
|
||||||
|
*/
|
||||||
|
virtual bool checkin(const Datetime& datetime, price_t cash) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取出资金
|
||||||
|
* @param datetime 取出时间
|
||||||
|
* @param cash 取出的资金量
|
||||||
|
* @return true | false
|
||||||
|
*/
|
||||||
|
virtual bool checkout(const Datetime& datetime, price_t cash) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存入资产
|
||||||
|
* @param datetime 存入日期
|
||||||
|
* @param stock 待存入的股票
|
||||||
|
* @param price 存入股票的每股价格
|
||||||
|
* @param number 存入股票的数量
|
||||||
|
* @return true | false
|
||||||
|
*/
|
||||||
|
virtual bool checkinStock(const Datetime& datetime, const Stock& stock, price_t price,
|
||||||
|
double number) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取出当前资产
|
||||||
|
* @param datetime 取出日期
|
||||||
|
* @param stock 待取出的股票
|
||||||
|
* @param price 取出的每股价格
|
||||||
|
* @param number 取出的数量
|
||||||
|
* @return true | false
|
||||||
|
* @note 应该不会被用到
|
||||||
|
*/
|
||||||
|
virtual bool checkoutStock(const Datetime& datetime, const Stock& stock, price_t price,
|
||||||
|
double number) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 买入操作
|
||||||
|
* @param datetime 买入时间
|
||||||
|
* @param stock 买入的证券
|
||||||
|
* @param realPrice 实际买入价格
|
||||||
|
* @param number 买入数量
|
||||||
|
* @param stoploss 止损价
|
||||||
|
* @param goalPrice 目标价格
|
||||||
|
* @param planPrice 计划买入价格
|
||||||
|
* @param from 记录是哪个系统部件发出的买入指示
|
||||||
|
* @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
|
||||||
|
*/
|
||||||
|
virtual TradeRecord buy(const Datetime& datetime, const Stock& stock, price_t realPrice,
|
||||||
|
double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
|
||||||
|
price_t planPrice = 0.0, SystemPart from = PART_INVALID) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return TradeRecord();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 卖出操作
|
||||||
|
* @param datetime 卖出时间
|
||||||
|
* @param stock 卖出的证券
|
||||||
|
* @param realPrice 实际卖出价格
|
||||||
|
* @param number 卖出数量,如果是 MAX_DOUBLE, 表示全部卖出
|
||||||
|
* @param stoploss 新的止损价
|
||||||
|
* @param goalPrice 新的目标价格
|
||||||
|
* @param planPrice 原计划卖出价格
|
||||||
|
* @param from 记录是哪个系统部件发出的卖出指示
|
||||||
|
* @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
|
||||||
|
*/
|
||||||
|
virtual TradeRecord sell(const Datetime& datetime, const Stock& stock, price_t realPrice,
|
||||||
|
double number = MAX_DOUBLE, price_t stoploss = 0.0,
|
||||||
|
price_t goalPrice = 0.0, price_t planPrice = 0.0,
|
||||||
|
SystemPart from = PART_INVALID) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return TradeRecord();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 卖空
|
||||||
|
* @param datetime 卖空时间
|
||||||
|
* @param stock 卖空的证券
|
||||||
|
* @param realPrice 实际卖空价格
|
||||||
|
* @param number 卖出数量
|
||||||
|
* @param stoploss 止损价
|
||||||
|
* @param goalPrice 目标价格
|
||||||
|
* @param planPrice 计划卖空价格
|
||||||
|
* @param from 记录是哪个系统部件发出的买入指示
|
||||||
|
* @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
|
||||||
|
*/
|
||||||
|
virtual TradeRecord sellShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
|
||||||
|
double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
|
||||||
|
price_t planPrice = 0.0,
|
||||||
|
SystemPart from = PART_INVALID) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return TradeRecord();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 卖空后回补
|
||||||
|
* @param datetime 买入时间
|
||||||
|
* @param stock 买入的证券
|
||||||
|
* @param realPrice 实际买入价格
|
||||||
|
* @param number 卖出数量,如果是 MAX_DOUBLE, 表示全部卖出
|
||||||
|
* @param stoploss 止损价
|
||||||
|
* @param goalPrice 目标价格
|
||||||
|
* @param planPrice 计划买入价格
|
||||||
|
* @param from 记录是哪个系统部件发出的卖出指示
|
||||||
|
* @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
|
||||||
|
*/
|
||||||
|
virtual TradeRecord buyShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
|
||||||
|
double number = MAX_DOUBLE, price_t stoploss = 0.0,
|
||||||
|
price_t goalPrice = 0.0, price_t planPrice = 0.0,
|
||||||
|
SystemPart from = PART_INVALID) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return TradeRecord();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借入资金,从其他来源借取的资金,如融资
|
||||||
|
* @param datetime 借入时间
|
||||||
|
* @param cash 借入的现金
|
||||||
|
* @return true | false
|
||||||
|
*/
|
||||||
|
virtual bool borrowCash(const Datetime& datetime, price_t cash) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 归还资金
|
||||||
|
* @param datetime 归还日期
|
||||||
|
* @param cash 归还现金
|
||||||
|
* @return true | false
|
||||||
|
*/
|
||||||
|
virtual bool returnCash(const Datetime& datetime, price_t cash) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借入证券
|
||||||
|
* @param datetime 借入时间
|
||||||
|
* @param stock 借入的stock
|
||||||
|
* @param price 借入时单股价格
|
||||||
|
* @param number 借入时数量
|
||||||
|
* @return true | false
|
||||||
|
*/
|
||||||
|
virtual bool borrowStock(const Datetime& datetime, const Stock& stock, price_t price,
|
||||||
|
double number) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 归还证券
|
||||||
|
* @param datetime 归还时间
|
||||||
|
* @param stock 归还的stock
|
||||||
|
* @param price 归还时单股价格
|
||||||
|
* @param number 归还数量
|
||||||
|
* @return true | false
|
||||||
|
*/
|
||||||
|
virtual bool returnStock(const Datetime& datetime, const Stock& stock, price_t price,
|
||||||
|
double number) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取账户当前时刻的资产详情
|
||||||
|
* @param ktype 日期的类型
|
||||||
|
* @return 资产详情
|
||||||
|
*/
|
||||||
|
virtual FundsRecord getFunds(KQuery::KType ktype = KQuery::DAY) const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return FundsRecord();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定时刻的资产市值详情
|
||||||
|
* @param datetime 必须大于帐户建立的初始日期,或为Null<Datetime>()
|
||||||
|
* @param ktype 日期的类型
|
||||||
|
* @return 资产详情
|
||||||
|
* @note 当datetime等于Null<Datetime>()时,与getFunds(KType)同
|
||||||
|
*/
|
||||||
|
virtual FundsRecord getFunds(const Datetime& datetime,
|
||||||
|
KQuery::KType ktype = KQuery::DAY) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return FundsRecord();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取资产净值曲线,含借入的资产
|
||||||
|
* @param dates 日期列表,根据该日期列表获取其对应的资产净值曲线
|
||||||
|
* @param ktype K线类型,必须与日期列表匹配,默认KQuery::DAY
|
||||||
|
* @return 资产净值列表
|
||||||
|
*/
|
||||||
|
virtual PriceList getFundsCurve(const DatetimeList& dates,
|
||||||
|
KQuery::KType ktype = KQuery::DAY) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return PriceList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取从账户建立日期到系统当前日期的资产净值曲线(按自然日),含借入的资产
|
||||||
|
* @return 资产净值列表
|
||||||
|
*/
|
||||||
|
virtual PriceList getFundsCurve() override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return PriceList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取收益曲线,即扣除历次存入资金后的资产净值曲线
|
||||||
|
* @param dates 日期列表,根据该日期列表获取其对应的收益曲线,应为递增顺序
|
||||||
|
* @param ktype K线类型,必须与日期列表匹配,默认为KQuery::DAY
|
||||||
|
* @return 收益曲线
|
||||||
|
*/
|
||||||
|
virtual PriceList getProfitCurve(const DatetimeList& dates,
|
||||||
|
KQuery::KType ktype = KQuery::DAY) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return PriceList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取获取从账户建立日期到系统当前日期的收益曲线,即扣除历次存入资金后的资产净值曲线
|
||||||
|
* @return 收益曲线
|
||||||
|
*/
|
||||||
|
virtual PriceList getProfitCurve() override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return PriceList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 直接加入交易记录
|
||||||
|
* @note 如果加入初始化账户记录,将清除全部已有交易及持仓记录
|
||||||
|
* @param tr 待加入的交易记录
|
||||||
|
* @return bool true 成功 | false 失败
|
||||||
|
*/
|
||||||
|
virtual bool addTradeRecord(const TradeRecord& tr) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 字符串输出 */
|
||||||
|
virtual string str() const override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
return string();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以csv格式输出交易记录、未平仓记录、已平仓记录、资产净值曲线
|
||||||
|
* @param path 输出文件所在目录
|
||||||
|
*/
|
||||||
|
virtual void tocsv(const string& path) override {
|
||||||
|
HKU_WARN("The subclass does not implement this method");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace hku
|
@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright(C) 2021 hikyuu.org
|
|
||||||
*
|
|
||||||
* Create on: 2021-03-23
|
|
||||||
* Author: fasiondog
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "../trade_manage/TradeManagerBase.h"
|
|
||||||
|
|
||||||
namespace hku {
|
|
||||||
|
|
||||||
class HKU_API StrategyTradeManager : public TradeManagerBase {
|
|
||||||
public:
|
|
||||||
StrategyTradeManager() = default;
|
|
||||||
virtual ~StrategyTradeManager() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace hku
|
|
@ -152,14 +152,6 @@ TradeManagerPtr TradeManager::_clone() {
|
|||||||
return TradeManagerPtr(p);
|
return TradeManagerPtr(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TradeManager::regBroker(const OrderBrokerPtr& broker) {
|
|
||||||
m_broker_list.push_back(broker);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TradeManager::clearBroker() {
|
|
||||||
m_broker_list.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
double TradeManager::getMarginRate(const Datetime& datetime, const Stock& stock) {
|
double TradeManager::getMarginRate(const Datetime& datetime, const Stock& stock) {
|
||||||
// TODO 获取保证金比率,默认固定取60%
|
// TODO 获取保证金比率,默认固定取60%
|
||||||
return 0.6;
|
return 0.6;
|
||||||
|
@ -51,17 +51,6 @@ public:
|
|||||||
/** 复位,清空交易、持仓记录 */
|
/** 复位,清空交易、持仓记录 */
|
||||||
virtual void _reset() override;
|
virtual void _reset() override;
|
||||||
|
|
||||||
/**
|
|
||||||
* 注册订单代理
|
|
||||||
* @param broker 订单代理实例
|
|
||||||
*/
|
|
||||||
virtual void regBroker(const OrderBrokerPtr& broker) override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清空已注册的订单代理
|
|
||||||
*/
|
|
||||||
virtual void clearBroker() override;
|
|
||||||
|
|
||||||
virtual shared_ptr<TradeManagerBase> _clone() override;
|
virtual shared_ptr<TradeManagerBase> _clone() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -437,7 +426,7 @@ private:
|
|||||||
position_map_type m_short_position; //空头仓位记录
|
position_map_type m_short_position; //空头仓位记录
|
||||||
PositionRecordList m_short_position_history; //空头仓位历史记录
|
PositionRecordList m_short_position_history; //空头仓位历史记录
|
||||||
|
|
||||||
list<OrderBrokerPtr> m_broker_list; //订单代理列表
|
// list<OrderBrokerPtr> m_broker_list; //订单代理列表
|
||||||
// Datetime m_broker_last_datetime; //订单代理最近一次执行操作的时刻
|
// Datetime m_broker_last_datetime; //订单代理最近一次执行操作的时刻
|
||||||
|
|
||||||
list<string> m_actions; //记录交易动作,便于修改或校准实盘时的交易
|
list<string> m_actions; //记录交易动作,便于修改或校准实盘时的交易
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
TradeManagerBase() : TradeManagerBase("", TC_Zero()) {}
|
TradeManagerBase() : TradeManagerBase("", TC_Zero()) {}
|
||||||
|
|
||||||
TradeManagerBase(const string& name, const TradeCostPtr& costFunc)
|
TradeManagerBase(const string& name, const TradeCostPtr& costFunc)
|
||||||
: m_name(name), m_broker_last_datetime(Datetime::now()), m_costfunc(costFunc) {
|
: m_name(name), m_costfunc(costFunc), m_broker_last_datetime(Datetime::now()) {
|
||||||
setParam<int>("precision", 2); //计算精度
|
setParam<int>("precision", 2); //计算精度
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,15 +186,15 @@ public:
|
|||||||
* 注册订单代理
|
* 注册订单代理
|
||||||
* @param broker 订单代理实例
|
* @param broker 订单代理实例
|
||||||
*/
|
*/
|
||||||
virtual void regBroker(const OrderBrokerPtr& broker) {
|
void regBroker(const OrderBrokerPtr& broker) {
|
||||||
HKU_WARN("The subclass does not implement a regBroker method");
|
m_broker_list.push_back(broker);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空已注册的订单代理
|
* 清空已注册的订单代理
|
||||||
*/
|
*/
|
||||||
virtual void clearBroker() {
|
void clearBroker() {
|
||||||
HKU_WARN("The subclass does not implement a clearBroker method");
|
m_broker_list.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -633,9 +633,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
string m_name; //账户名称
|
string m_name; // 账户名称
|
||||||
Datetime m_broker_last_datetime; // 当前启动运行时间
|
TradeCostPtr m_costfunc; // 成本算法
|
||||||
TradeCostPtr m_costfunc; //成本算法
|
|
||||||
|
Datetime m_broker_last_datetime; // 订单代理最近一次执行操作的时刻,当前启动运行时间
|
||||||
|
list<OrderBrokerPtr> m_broker_list; // 订单代理列表
|
||||||
|
|
||||||
//============================================
|
//============================================
|
||||||
// 序列化支持
|
// 序列化支持
|
||||||
@ -647,16 +649,18 @@ private:
|
|||||||
void save(Archive& ar, const unsigned int version) const {
|
void save(Archive& ar, const unsigned int version) const {
|
||||||
ar& BOOST_SERIALIZATION_NVP(m_params);
|
ar& BOOST_SERIALIZATION_NVP(m_params);
|
||||||
ar& BOOST_SERIALIZATION_NVP(m_name);
|
ar& BOOST_SERIALIZATION_NVP(m_name);
|
||||||
ar& BOOST_SERIALIZATION_NVP(m_broker_last_datetime);
|
|
||||||
ar& BOOST_SERIALIZATION_NVP(m_costfunc);
|
ar& BOOST_SERIALIZATION_NVP(m_costfunc);
|
||||||
|
ar& BOOST_SERIALIZATION_NVP(m_broker_last_datetime);
|
||||||
|
ar& BOOST_SERIALIZATION_NVP(m_broker_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Archive>
|
template <class Archive>
|
||||||
void load(Archive& ar, const unsigned int version) {
|
void load(Archive& ar, const unsigned int version) {
|
||||||
ar& BOOST_SERIALIZATION_NVP(m_params);
|
ar& BOOST_SERIALIZATION_NVP(m_params);
|
||||||
ar& BOOST_SERIALIZATION_NVP(m_name);
|
ar& BOOST_SERIALIZATION_NVP(m_name);
|
||||||
ar& BOOST_SERIALIZATION_NVP(m_broker_last_datetime);
|
|
||||||
ar& BOOST_SERIALIZATION_NVP(m_costfunc);
|
ar& BOOST_SERIALIZATION_NVP(m_costfunc);
|
||||||
|
ar& BOOST_SERIALIZATION_NVP(m_broker_last_datetime);
|
||||||
|
ar& BOOST_SERIALIZATION_NVP(m_broker_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_SERIALIZATION_SPLIT_MEMBER()
|
BOOST_SERIALIZATION_SPLIT_MEMBER()
|
||||||
|
@ -40,7 +40,6 @@ add_requires("fmt", {system=false, configs = {header_only = true, vs_runtime = "
|
|||||||
add_requires("spdlog", {system=false, configs = {header_only = true, fmt_external=true, vs_runtime = "MD"}})
|
add_requires("spdlog", {system=false, configs = {header_only = true, fmt_external=true, vs_runtime = "MD"}})
|
||||||
add_requires("flatbuffers", {system=false, configs = {vs_runtime="MD"}})
|
add_requires("flatbuffers", {system=false, configs = {vs_runtime="MD"}})
|
||||||
add_requires("nng", {system=false, configs = {vs_runtime="MD"}})
|
add_requires("nng", {system=false, configs = {vs_runtime="MD"}})
|
||||||
add_requires("yyjson", {system=false, configs = {vs_runtime="MD"}})
|
|
||||||
|
|
||||||
add_defines("SPDLOG_DISABLE_DEFAULT_LOGGER") -- 禁用 spdlog 默认 logger
|
add_defines("SPDLOG_DISABLE_DEFAULT_LOGGER") -- 禁用 spdlog 默认 logger
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user