// ContractData.h
#pragma once
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace rapidjson;
class IPluginContext;
using namespace std;
class ContractData
{
public:
ContractData() = delete;
ContractData(const shared_ptr instrumentID, const shared_ptr exchangeID,
double priceTick, int volumeMultiple,
int maxMarketOrderVolume, int minMarketOrderVolume, int maxLimitOrderVolume, int minLimitOrderVolume,
double longMarginRatio, double shortMarginRatio
);
virtual ~ContractData();
inline void addOneCancelTime() { this->m_curCancelTimes++; }
inline const shared_ptr InstrumentID() { return this->m_instrumentID; }
inline const shared_ptr ExchangeID() { return this->m_exchangeID; }
inline const shared_ptr ExchangeInstrument() { return this->m_exchangeInstrument; }
inline double PriceTick() { return this->m_priceTick; }
inline int VolumeMultiple() { return this->m_volumeMultiple; }
inline unsigned int CurCancelTimes() { return this->m_curCancelTimes; }
inline void setLongPosSPtr(PositionSPtr longPosSptr) { this->m_longPosSptr = longPosSptr; }
inline PositionSPtr CurLongPosSPtr() { return this->m_longPosSptr; }
inline void setShortPosSPtr(PositionSPtr shortPosSptr) { this->m_shortPosSptr = shortPosSptr; }
inline PositionSPtr CurShortPosSPtr() { return this->m_shortPosSptr; }
inline void setFuturesType(OPFuturesType futuresType) { this->m_futuresType = futuresType; }
inline OPFuturesType FuturesType() { return this->m_futuresType; }
inline void setCancelOrderTimesUpperLimit(int cancelOrderTimesUpperLimit) { this->m_cancelOrderTimesUpperLimit = cancelOrderTimesUpperLimit; }
inline int CancelOrderTimesUpperLimit() { return this->m_cancelOrderTimesUpperLimit; }
inline void setOpenLotsUpperLimit(int openLotsUpperLimit) { this->m_openLotsUpperLimit = openLotsUpperLimit; }
inline int OpenLotsUpperLimit() { return this->m_openLotsUpperLimit; }
bool InsertOrderSPtr(const OrderSPtr orderSPtr);
OrderSPtr GetOrderSPtr(const string& orderRef);
inline int MaxMarketOrderVolume() { return this->m_maxMarketOrderVolume; }
inline int MinMarketOrderVolume() { return this->m_minMarketOrderVolume; }
inline int MaxLimitOrderVolume() { return this->m_maxLimitOrderVolume; }
inline int MinLimitOrderVolume() { return this->m_minLimitOrderVolume; }
inline double LongMarginRatio() { return this->m_longMarginRatio; }
inline double ShortMarginRatio() { return this->m_shortMarginRatio; }
inline bool addTradeSPtr(TradeSPtr tradeSPtr) {
if (!tradeSPtr)
return false;
this->m_tradeVector.push_back(tradeSPtr);
return true;
}
// #. create in core;
// #. make with config file;
// #. call back before Update(tickSPtr);
inline bool setContextsConfig() { return false; }
void WakeUpContexts();
void Update(TickSPtr tickSPtr);
bool IsTradingTime();
int CurLocalTime();
inline bool ContextsPos() { return this->m_contextsPos; }
inline void setSessionDay(vector> sessionDay) { this->m_sessionDay = sessionDay; }
inline void setSessionNight(vector> sessionNight) { this->m_sessionNight = sessionNight; }
private:
shared_ptr m_instrumentID;
shared_ptr m_exchangeID;
shared_ptr m_exchangeInstrument;
double m_priceTick;
int m_volumeMultiple;
int m_maxMarketOrderVolume;
int m_minMarketOrderVolume;
int m_maxLimitOrderVolume;
int m_minLimitOrderVolume;
double m_longMarginRatio;
double m_shortMarginRatio;
unsigned int m_curCancelTimes;
PositionSPtr m_longPosSptr;
PositionSPtr m_shortPosSptr;
unordered_map m_orderRefSPtrMap; // m_tradeVector;
OPFuturesType m_futuresType;
int m_cancelOrderTimesUpperLimit;
int m_openLotsUpperLimit;
vector> m_contexts;
int m_contextsPos;
vector> m_sessionDay;
vector> m_sessionNight;
};
using ContractUPtr = unique_ptr;
using ContractSPtr = shared_ptr;
// ContractData.cc
#include
#include
#include
#include
#include
ContractData::ContractData(const shared_ptr instrumentID, const shared_ptr exchangeID, double priceTick, int volumeMultiple, int maxMarketOrderVolume, int minMarketOrderVolume, int maxLimitOrderVolume, int minLimitOrderVolume, double longMarginRatio, double shortMargi服务器托管网nRatio):
m_instrumentID(instrumentID),
m_exchangeID(exchangeID),
m_priceTick(priceTick),
m_volumeMultiple(volumeMultiple),
m_curCancelTimes(0),
m_maxMarketOrderVolume(maxMarketOrderVolume),
m_minMarketOrderVolume(minMarketOrderVolume),
m_maxLimitOrderVolume(maxLimitOrderVolume),
m_minLimitOrderVolume(minLimitOrderVolume),
m_longMarginRatio(longMarginRatio),
m_shortMarginRatio(shortMarginRatio),
m_contextsPos(0)
{
this->m_exchangeInstrument = make_shared(this->m_exchangeID->data() + string(".") + this->m_instrumentID->data());
}
void ContractData::Update(TickSPtr tickSPtr) {
if (!this->IsTradingTime()) {
this->m_contextsPos = 0;
return;
}
int totlePos = 0;
for (size_t i = 0; i m_contexts.size(); i++) {
this->m_contexts[i]->OnTickUpdate(tickSPtr);
totlePos += this->m_contexts[i]->ContextPos();
}
double priceRange = (tickSPtr->UpperLimitPrice() - tickSPtr->OpenPrice()) * 0.服务器托管网96;
if ((tickSPtr->LastPrice() > (tickSPtr->OpenPrice() + priceRange)) || (tickSPtr->LastPrice() OpenPrice() - priceRange))) {
this->m_contextsPos = 0;
return;
}
this->m_contextsPos = totlePos;
}
void ContractData::WakeUpContexts() {
for (size_t i = 0; i m_contexts.size(); i++) {
this->m_contexts[i]->OnContextWakeUpCall();
}
}
bool ContractData::IsTradingTime() {
int localTime = this->CurLocalTime();
for (const vector& session : this->m_sessionDay) {
if (2 != session.size())
continue;
if (session[0] & session : this->m_sessionNight) {
if (2 != session.size())
continue;
int sessionStart = session[0];
int sessionEnd = session[1];
if (sessionStart sessionEnd) {
if ((sessionStart tm_hour * 100 + newtime->tm_min;
}
bool ContractData::InsertOrderSPtr(const OrderSPtr orderSPtr) {
/* m_orderRefSPtrMap 只会记录本次登录认证后系统内发的单子; */
if (orderSPtr->ExchangeInstrument() == this->ExchangeInstrument()) {
if (!orderSPtr->OrderRef()) // orderRef 为空;
return false;
const string orderRef = orderSPtr->OrderRef()->data();
if (this->m_orderRefSPtrMap.count(orderRef) > 0) // error log: orderRef is exist.
return false;
this->m_orderRefSPtrMap[orderRef] = orderSPtr;
return true;
}
/* error log: not same ExchangeInstrument. */
return false;
}
OrderSPtr ContractData::GetOrderSPtr(const string& orderRef) {
return (this->m_orderRefSPtrMap.count(orderRef) > 0) ? this->m_orderRefSPtrMap[orderRef] : nullptr;
}
ContractData::~ContractData() {
if (this->m_instrumentID) this->m_instrumentID.reset();
if (this->m_exchangeID) this->m_exchangeID.reset();
if (this->m_exchangeInstrument) this->m_exchangeInstrument.reset();
if (this->m_longPosSptr) this->m_longPosSptr.reset();
if (this->m_shortPosSptr) this->m_shortPosSptr.reset();
for (auto& pair : this->m_orderRefSPtrMap) {
if (pair.second) pair.second.reset();
}
this->m_orderRefSPtrMap.clear();
for (int i = 0; i m_tradeVector.size(); i++) {
if (this->m_tradeVector[i])
this->m_tradeVector[i].reset();
}
this->m_tradeVector.clear();
for (int i = 0; i m_contexts.size(); i++) {
if (this->m_contexts[i])
this->m_contexts[i].reset();
}
this->m_contexts.clear();
}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
前言 本文来源于知乎的一个提问,提问的是一个大一软件工程专业的学生,他想要自学C#但是不知道该怎么去学,这让他感到很迷茫,希望有人能给他一些建议和提供一些学习方向。 个人建议 确认目标:自学C#首先你需要大概了解该门语言的发展、前景和基本特点,从自身实…