cfunc.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. #ifndef _CFUNC_H_
  2. #define _CFUNC_H_
  3. #include "FixValue.h"
  4. #include "FixValueNumber.h"
  5. #ifdef _cplusplus
  6. extern "C" {
  7. #endif
  8. typedef unsigned int uint;
  9. typedef signed char schar;
  10. typedef unsigned char uchar;
  11. typedef unsigned short ushort;
  12. typedef long long int64;
  13. typedef unsigned long long uint64;
  14. typedef struct SessionID SessionID;
  15. typedef struct SessionSettings SessionSettings;
  16. typedef struct Dictionary Dictionary;
  17. typedef struct Message Message;
  18. typedef struct AppTradeClient AppTradeClient;
  19. typedef struct IApplication {
  20. /// Notification of a session begin created
  21. void (*onCreate)(AppTradeClient *, SessionID *);
  22. /// Notification of a session successfully logging on
  23. void (*onLogon)(AppTradeClient *, SessionID *);
  24. /// Notification of a session logging off or disconnecting
  25. void (*onLogout)(AppTradeClient *, SessionID *);
  26. /// Notification of admin message being sent to target
  27. void (*toAdmin)(AppTradeClient *, Message *, SessionID *);
  28. /// Notification of app message being sent to target
  29. void (*toApp)(AppTradeClient *, Message *, SessionID *);
  30. /// Notification of admin message being received from target
  31. void (*fromAdmin)(AppTradeClient *, const Message *, SessionID *);
  32. /// Notification of app message being received from target
  33. void (*fromApp)(AppTradeClient *, const Message *, SessionID *);
  34. //为了go的调用方便,封装了这样的一个接口
  35. void (*defaultCallBack) (void *pfunc, AppTradeClient *, const Message *, SessionID *);
  36. void *onCreateCB;
  37. void *onLogonCB;
  38. void *onLogoutCB;
  39. void *toAdminCB;
  40. void *fromAdminCB;
  41. void *fromAppCB;
  42. void *toAppCB;
  43. } IApplication;
  44. //预留一点空间,现在测试的情况是最大20
  45. #define MAX_BID_ASK_COUNT 25
  46. typedef struct TickFull
  47. {
  48. double AskPrice[MAX_BID_ASK_COUNT];
  49. double BidPrice[MAX_BID_ASK_COUNT];
  50. double AskVolume[MAX_BID_ASK_COUNT];
  51. double BidVolume[MAX_BID_ASK_COUNT];
  52. char Symbol[8];
  53. int Time;
  54. int Millisecond;
  55. int AskCount;
  56. int BidCount;
  57. double LastPx ;
  58. double LastShares ;
  59. } TickFull;
  60. typedef struct StockInfo
  61. {
  62. char Symbol[15];
  63. int Position ;
  64. char SecurityExchange[10];
  65. }StockInfo;
  66. typedef struct AccountInfo
  67. {
  68. double FB;
  69. double FAV;
  70. double MV;
  71. double F;
  72. double SV;
  73. double FBF;
  74. }AccountInfo;
  75. typedef struct OrderInfo
  76. {
  77. char OrderID[32];//Unique identifier for Order as assigned by exchange
  78. char SecondaryExecID[32];
  79. char ClOrdID[32] ;//Client side order identifier
  80. char OrigClOrdID[32];
  81. char OrdStatusReqID[32];
  82. char ExecID[32] ; //Execution ID for this fill.
  83. char Account[16];//Account ID of the current logged in LMAX member
  84. char Symbol[16];
  85. char SecurityID[8];
  86. double AvgPx ;//Calculated average price of all fills on this order.
  87. double CumQty;//Contains the cumulated traded quantity for the order through its life.
  88. double LastPx ;//Price of this fill
  89. double LastQty;//
  90. double OrderQty ;//Number of contracts submitted by the client
  91. double LeavesQty ;//成交手数
  92. double Price ;//Price per contract
  93. char *Text;
  94. int OrdRejReason;
  95. int TransactTime ;//Time of execution/order creation
  96. int Millisecond ;
  97. char SecurityIDSource[2];
  98. char TimeInForce ;//Specifies how long the order remains in effect. 0=Good for Day (GFD) 3=Immediate or Cancel (IOC) 4=Fill or Kill (FOK)Limit Orders support TimeInForce values of IOC, FOK, and GFD. Market Orders support TimeInForce values of IOC, FOK.
  99. char OrdType;
  100. char OrdStatus ;
  101. char Side ;//1=BUY ,2=SELL
  102. char ExecType ;//Describes the type of execution report. Same possible values as Order Status. 0=NEW 1=PARTIALLY FILL 2=FILL 4=CANCELED 5=REPLACE 8=REJECTED
  103. } OrderInfo;
  104. //SessionSettings api
  105. SessionSettings * NewSessionSettings(const char *file);
  106. void FreeSessionSettings(SessionSettings *obj);
  107. Dictionary* SessionSettingsGet(SessionSettings *ss, SessionID *sid);
  108. //Dictionary api
  109. int DictionaryHas(Dictionary *obj, const char *find);
  110. const char * DictionaryGetString(Dictionary *obj, const char *find);
  111. void FreeDictionary(Dictionary *dict);
  112. //message api
  113. Message * WarpMessage(void *msg);
  114. void MessageSetField(Message *msg, int field, const char *value);
  115. int MessageSend(Message *msg);
  116. char * MessageToStr(const Message *msg);
  117. void Free(void *);
  118. const Message * WarpConstMessage(const void *msg);
  119. void PrintHello(char *data[], int n);
  120. //SessionID api
  121. SessionID * WarpSessionID(const void *sid);
  122. IApplication * NewDefaultIApplication();
  123. void IApplicationSetCB(void *);
  124. IApplication * NewCBIApplication(void *cb, void *onCreate, void *onLogon, void *onLogout, void *toAdmin, void *toApp, void *fromAdmin, void *fromApp);
  125. IApplication * NewIApplication(void *onCreate, void *onLogon, void *onLogout, void *toAdmin, void *toApp, void *fromAdmin, void *fromApp);
  126. void FreeIApplication(IApplication *app);
  127. //application api
  128. AppTradeClient * NewAppTradeClient(IApplication *app, SessionSettings *setting);
  129. void FreeAppTradeClient(AppTradeClient * app);
  130. void AppTradeClientStart(AppTradeClient * app);
  131. void AppTradeClientStop(AppTradeClient * app);
  132. int AppTradeClientRun(AppTradeClient * app);
  133. SessionID *AppTradeClientSessionID(AppTradeClient * app);
  134. const char *AppTradeClientSenderCompID(AppTradeClient * app);
  135. const char *AppTradeClientTargetCompID(AppTradeClient * app);
  136. const char *AppTradeClientClOrdID(AppTradeClient * app);
  137. int GetAccountInfo(const Message * msg, AccountInfo* accountinfo,int *bLastRptRequested);
  138. int GetFieldValue(const Message * msg, int key,char * value);
  139. int GetMarketData(const Message *msg, TickFull *tick);
  140. int GetOrderInfo(const Message * msg, OrderInfo * orderinfo);
  141. int GetAccountStockInfo(const Message * msg, StockInfo * stockinfo ,int *bLastRptRequested);
  142. int GetMsgType(const Message * msg ,char * cTypeValue);
  143. const char * AppTradeClientOrigClOrdID(AppTradeClient * app, const Message *msg);
  144. int AppTradeClientSendOrder(AppTradeClient * trade, const char * aSymbol,const char *clordid, const char side, const char orderType,
  145. double qty, double price, const char *account); //,const char * secondaryClOrdID,const char * onBehalfOfCompID
  146. int AppTradeClientTradeCaptureReportRequest(AppTradeClient * trade, const char *reqId, int reqType, char subReqType);
  147. int AppTradeClientOrderStatus(AppTradeClient * trade,
  148. const char *aSymbol,
  149. const char *clordId,
  150. //const char *ordStatusReqId,
  151. const char side,
  152. //const char * account,
  153. //const char * securitytype,
  154. const char * orderid
  155. );
  156. int AppTradeClientCancelOrder(AppTradeClient * trade,
  157. const char *aSymbol,
  158. const char *origClOrdID,
  159. const char *clordid,
  160. const char side,
  161. //double qty,
  162. const char * account,
  163. //const char * securitytype,
  164. const char * orderid );
  165. int AppTradeCilentOrderCancelReplace(AppTradeClient * trade,
  166. const char *aSymbol,
  167. const char * origclordid ,
  168. const char *clordid,
  169. const char aHandlInst,
  170. const char side,
  171. const char orderType,
  172. double price,
  173. double qty ,
  174. const char * account,
  175. const char * securitytype,
  176. const char * orderid
  177. );
  178. int AppTradeClientCollectiveOrder(AppTradeClient * trade ,
  179. const char *clordId,
  180. const char aHandlInst,
  181. const char ordertype,
  182. const char *sideStr,
  183. const char *symbolStr,
  184. const char *orderQtyStr,
  185. const char *priceStr,
  186. const char *securityExchangeStr,
  187. const char *currencyStr,
  188. const char *account,
  189. const char *securityTypeStr,
  190. const char *accountStr,
  191. int entrustNum
  192. );
  193. int AppTradeClientCollectiveOrderCancel(AppTradeClient * trade,
  194. const char *clordId,
  195. int entrustNum ,
  196. const char *entrustNoStr,
  197. const char *securityExchangeStr,
  198. const char *currencyStr,
  199. const char *account
  200. );
  201. int AppTradeClientCollectiveOrderStatus(AppTradeClient * trade,
  202. int entrustNum ,
  203. const char *entrustNoStr,
  204. const char *account
  205. );
  206. int AppTradeClientBatchOrder(AppTradeClient * trade,
  207. const char *clordId,
  208. const char aHandlInst,
  209. const char ordertype,
  210. const char **symbolStr,
  211. const char **sideStr,
  212. const char **orderQtyStr,
  213. const char **priceStr,
  214. const char **securityExchangeStr,
  215. const char **currencyStr,
  216. const char **securityTypeStr,
  217. const char *account,
  218. int num
  219. );
  220. int AppTradeClientRequestForPositions(AppTradeClient * trade,
  221. const char *posReqID,
  222. int posReqType,
  223. const char *account,
  224. int accountType
  225. );
  226. int AppTradeClientMarketData(AppTradeClient * trade, const char *bookId,const char subscriptionRequestType);
  227. #ifdef _cplusplus
  228. }
  229. #endif
  230. #endif