加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tradespi.h 4.32 KB
一键复制 编辑 原始数据 按行查看 历史
1ndustry 提交于 2022-09-05 10:16 . fitst
#ifndef TRADESPI_H
#define TRADESPI_H
#include "ThostFtdcTraderApi.h"
#include <Windows.h>
#include <vector>
#include <string>
#include <map>
#include <iostream>
#include <QList>
using namespace std;
extern CThostFtdcTraderApi*pUserApi;
enum TLoginStatus {LSConnected,LSDisconnected, LSAuthenticate_successful, LSAuthenticate_failed, LSLogin_successful, LSLogin_failed};
class CTraderSpi :public QObject,public CThostFtdcTraderSpi
{
Q_OBJECT
public:
explicit CTraderSpi(QObject *parent = nullptr);
typedef struct HYstruct{
int hycs;
double hyds;
} ;
HYstruct hy(QString);
void ReqOrderInsert(QString dm,QString lx,int lots,double price);
void ReqOrderAction(QString brokerid,QString wth,QString jys);
private:
QList<CThostFtdcTraderSpi*> m_SpiList;
TThostFtdcPriceType LIMIT_PRICE;
TThostFtdcDirectionType DIRECTION;
int iRequestID = 0;
TThostFtdcFrontIDType FRONT_ID;
TThostFtdcSessionIDType SESSION_ID;
TThostFtdcOrderRefType ORDER_REF;
char INSTRUMENT_ID[7] = "";
public:
TLoginStatus Status = LSDisconnected;
signals:
void sendDataCJ(QString);
void sendDataWT(QString);
void sendDataHY(QString);
void sendDataCC(QString);
void sendDataZJ(QString);
public:
void init();
void RegisterSpi(CThostFtdcTraderSpi *pSpi);
void UnReisterSpi(CThostFtdcTraderSpi *pSpi);
///当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
virtual void OnFrontConnected();
///当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
///@param nReason 错误原因
/// 0x1001 网络读失败
/// 0x1002 网络写失败
/// 0x2001 接收心跳超时
/// 0x2002 发送心跳失败
/// 0x2003 收到错误报文
virtual void OnFrontDisconnected(int nReason);
///心跳超时警告。当长时间未收到报文时,该方法被调用。
///@param nTimeLapse 距离上次接收报文的时间
///客户端认证响应
virtual void OnRspAuthenticate(CThostFtdcRspAuthenticateField *pRspAuthenticateField, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
void ReqQryInvestorPosition();
///登录请求响应
virtual void OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
///登出请求响应
///报单录入请求响应
virtual void OnRspOrderInsert(CThostFtdcInputOrderField *pInputOrder, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
///请求查询报单响应
virtual void OnRspQryOrder(CThostFtdcOrderField *pOrder, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
///请求查询成交响应
///请求查询资金账户响应
bool IsErrorRspInfo(CThostFtdcRspInfoField *pRspInfo);
void ReqQryTradingAccount();
virtual void OnRspQryTradingAccount(CThostFtdcTradingAccountField *pTradingAccount, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
///请求查询投资者响应
///请求查询合约响应
void ReqQryInstrument();
virtual void OnRspQryInstrument(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
///请求查询结算信息确认响应
virtual void OnRspSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField *pSettlementInfoConfirm, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) ;
void ReqSettlementInfoConfirm();
virtual void OnRspQrySettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField *pSettlementInfoConfirm, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
virtual void OnRspQryInvestorPosition(CThostFtdcInvestorPositionField *pInvestorPosition, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
///错误应答
virtual void OnRspError(CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
///报单通知
virtual void OnRtnOrder(CThostFtdcOrderField *pOrder);
///成交通知
virtual void OnRtnTrade(CThostFtdcTradeField *pTrade);
bool IsMyOrder(CThostFtdcOrderField *pOrder);
bool IsTradingOrder(CThostFtdcOrderField *pOrder);
};
#endif // TRADESPI_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化