platformobject.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #ifndef PLATFORMOBJECT_H
  2. #define PLATFORMOBJECT_H
  3. #include <QObject>
  4. #include <vector>
  5. #include <QMutex>
  6. using namespace std;
  7. class QNetworkAccessManager;
  8. struct DataPlatform
  9. {
  10. QString strPlatformType;
  11. QString strSymbol;
  12. __int64 nData; //ms
  13. float fPrice;
  14. };
  15. //开仓
  16. struct OpenContractInfo
  17. {
  18. QString tokenId;
  19. QString symbolId;
  20. int businessLine;
  21. QString secondBusinessLine;
  22. int businessSource;
  23. int enterPointSource;
  24. QString delegateCount;
  25. int orderType;
  26. int delegateType;
  27. QString pricedSymbol;
  28. int timeInForceValue;
  29. double delegatePrice;
  30. int languageType;
  31. OpenContractInfo()
  32. {
  33. tokenId = "USDT";
  34. symbolId = "BTCUSDT_UMCBL";
  35. businessLine = 10;
  36. secondBusinessLine = "N/A";
  37. businessSource = 0;
  38. enterPointSource = 1;
  39. delegateCount = "0.02";
  40. orderType = 0;
  41. delegateType = 1;
  42. pricedSymbol = "USDT";
  43. timeInForceValue = 0;
  44. delegatePrice = 0;
  45. languageType = 1;
  46. }
  47. };
  48. //平仓
  49. struct CloseContractInfo
  50. {
  51. QString tokenId;
  52. QString symbolId;
  53. int businessLine;
  54. int businessSource;
  55. int enterPointSource;
  56. QString secondBusinessLine;
  57. int timeInForceValue;
  58. bool cancelOrder;
  59. QString delegateCount;
  60. int orderType;
  61. int delegateType;
  62. int languageType;
  63. CloseContractInfo()
  64. {
  65. tokenId = "USDT";
  66. symbolId = "BTCUSDT_UMCBL";
  67. businessLine = 10;
  68. businessSource = 10;
  69. enterPointSource = 1;
  70. secondBusinessLine = "N/A";
  71. timeInForceValue = 0;
  72. cancelOrder = true;
  73. delegateCount = "0.02";
  74. orderType = 1;
  75. delegateType = 3;
  76. languageType = 1;
  77. }
  78. };
  79. //撤单
  80. struct CancleContractInfo
  81. {
  82. int businessLine;
  83. QString orderId;
  84. QString tokenId;
  85. QString symbolId;
  86. QString secondBusinessLine;
  87. int languageType;
  88. CancleContractInfo()
  89. {
  90. orderId = "1242653936208982023";
  91. tokenId = "USDT";
  92. symbolId = "BTCUSDT_UMCBL";
  93. businessLine = 10;
  94. secondBusinessLine = "N/A";
  95. languageType = 1;
  96. }
  97. };
  98. class PlatformObject : public QObject
  99. {
  100. Q_OBJECT
  101. public:
  102. PlatformObject(QObject *parent = nullptr);
  103. ~PlatformObject();
  104. private:
  105. QString m_strPlatName; // 平台名称
  106. double m_price; // 当前价格
  107. double m_dBNPrice;//当前bn价格
  108. double m_deviationCompensation; // 偏差补偿值
  109. double m_deviationPercentage; // 偏离度百分比
  110. bool m_isPositionOpen; // 当前是否开仓
  111. bool m_isDealState;//true:开多 false:开空
  112. bool m_bOrderDirection; // 下单方向,true :"buy"或 false:"sell"
  113. double m_dAverage;
  114. int m_nLever;//杠杆
  115. bool m_bCon;
  116. vector<DataPlatform> m_vDataVec;
  117. QNetworkAccessManager* m_pNetworkManager;
  118. QMutex m_QMutex;
  119. public:
  120. void MinData(const DataPlatform &item);
  121. void SetPlatformName(QString strName);
  122. float CalcAverageSelf();
  123. double GetAverage();
  124. double GetRealPrice();
  125. double GetRealNewPrice();
  126. void CalcdeviationCompensation(double dBinance);
  127. double GetDeviationCompensation();
  128. void CalcdeviationPercentage(double dBinancePrice);
  129. void executeTradingLogic(double entryThreshold);
  130. QByteArray PackJson_Open(const OpenContractInfo &item);
  131. QByteArray PackJson_Close(const CloseContractInfo &item);
  132. QByteArray PackJson_Cancle(const CancleContractInfo &item);
  133. void SetPostionState();
  134. //开多 - 限价
  135. void OpenContractMore_XJ();
  136. //开空 - 限价
  137. void OpenContractEmpty_XJ();
  138. //开空 - 市价
  139. void OpenContractEmpty_SJ();
  140. //平仓 - 闪现平仓 平多
  141. void CloseContractMore();
  142. //平仓 - 闪现平仓 平空
  143. void CloseContractEmpty();
  144. void SendPostRequst(QString strUrl,QByteArray &dataArray);
  145. public slots:
  146. void ReplyFinshed();
  147. };
  148. #endif // PLATFORMOBJECT_H