cfunc.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. } TickFull;
  58. typedef struct StockInfo
  59. {
  60. char Symbol[15];
  61. int Position ;
  62. char SecurityExchange[10];
  63. }StockInfo;
  64. typedef struct OrderInfo
  65. {
  66. char OrderID[32];//Unique identifier for Order as assigned by exchange
  67. char SecondaryExecID[32];
  68. char ClOrdID[32] ;//Client side order identifier
  69. char OrigClOrdID[32];
  70. char OrdStatusReqID[32];
  71. char ExecID[32] ; //Execution ID for this fill.
  72. char Account[16];//Account ID of the current logged in LMAX member
  73. char SecurityID[8];
  74. double AvgPx ;//Calculated average price of all fills on this order.
  75. double CumQty;//Contains the cumulated traded quantity for the order through its life.
  76. double LastPx ;//Price of this fill
  77. double LastQty;//
  78. double OrderQty ;//Number of contracts submitted by the client
  79. double LeavesQty ;//成交手数
  80. double Price ;//Price per contract
  81. char *Text;
  82. int OrdRejReason;
  83. int TransactTime ;//Time of execution/order creation
  84. int Millisecond ;
  85. char SecurityIDSource[2];
  86. 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.
  87. char OrdType;
  88. char OrdStatus ;
  89. char Side ;//1=BUY ,2=SELL
  90. 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
  91. } OrderInfo;
  92. //SessionSettings api
  93. SessionSettings * NewSessionSettings(const char *file);
  94. void FreeSessionSettings(SessionSettings *obj);
  95. Dictionary* SessionSettingsGet(SessionSettings *ss, SessionID *sid);
  96. //Dictionary api
  97. int DictionaryHas(Dictionary *obj, const char *find);
  98. const char * DictionaryGetString(Dictionary *obj, const char *find);
  99. void FreeDictionary(Dictionary *dict);
  100. //message api
  101. Message * WarpMessage(void *msg);
  102. void MessageSetField(Message *msg, int field, const char *value);
  103. int MessageSend(Message *msg);
  104. char * MessageToStr(const Message *msg);
  105. void Free(void *);
  106. const Message * WarpConstMessage(const void *msg);
  107. void PrintHello(char *data[], int n);
  108. //SessionID api
  109. SessionID * WarpSessionID(const void *sid);
  110. IApplication * NewDefaultIApplication();
  111. void IApplicationSetCB(void *);
  112. IApplication * NewCBIApplication(void *cb, void *onCreate, void *onLogon, void *onLogout, void *toAdmin, void *toApp, void *fromAdmin, void *fromApp);
  113. IApplication * NewIApplication(void *onCreate, void *onLogon, void *onLogout, void *toAdmin, void *toApp, void *fromAdmin, void *fromApp);
  114. void FreeIApplication(IApplication *app);
  115. //application api
  116. AppTradeClient * NewAppTradeClient(IApplication *app, SessionSettings *setting);
  117. void FreeAppTradeClient(AppTradeClient * app);
  118. void AppTradeClientStart(AppTradeClient * app);
  119. void AppTradeClientStop(AppTradeClient * app);
  120. int AppTradeClientRun(AppTradeClient * app);
  121. SessionID *AppTradeClientSessionID(AppTradeClient * app);
  122. const char *AppTradeClientSenderCompID(AppTradeClient * app);
  123. const char *AppTradeClientTargetCompID(AppTradeClient * app);
  124. const char *AppTradeClientClOrdID(AppTradeClient * app);
  125. int GetMarketData(const Message *msg, TickFull *tick);
  126. int GetOrderInfo(const Message * msg, OrderInfo * orderinfo);
  127. int GetAccountStockInfo(const Message * msg, StockInfo * stockinfo ,int *bLastRptRequested);
  128. int GetMsgType(const Message * msg ,char * cTypeValue);
  129. const char * AppTradeClientOrigClOrdID(AppTradeClient * app, const Message *msg);
  130. int AppTradeClientSendOrder(AppTradeClient * trade, const char * aSymbol,const char *clordid, const char aHandlInst ,const char side, const char orderType,
  131. double qty, double price, const char *account,const char * securitytype,const char * securityexchange,const char * currency);
  132. int AppTradeClientTradeCaptureReportRequest(AppTradeClient * trade, const char *reqId, int reqType, char subReqType);
  133. int AppTradeClientOrderStatus(AppTradeClient * trade,
  134. const char *aSymbol,
  135. const char *clordId,
  136. //const char *ordStatusReqId,
  137. const char side,
  138. const char * account,
  139. const char * securitytype,
  140. const char * orderid
  141. );
  142. int AppTradeClientCancelOrder(AppTradeClient * trade,
  143. const char *aSymbol,
  144. const char *origClOrdID,
  145. const char *clordid,
  146. const char side,
  147. double qty,
  148. const char * account,
  149. const char * securitytype,
  150. const char * orderid );
  151. int AppTradeCilentOrderCancelReplace(AppTradeClient * trade,
  152. const char *aSymbol,
  153. const char * origclordid ,
  154. const char *clordid,
  155. const char aHandlInst,
  156. const char side,
  157. const char orderType,
  158. double price,
  159. double qty ,
  160. const char * account,
  161. const char * securitytype,
  162. const char * orderid
  163. );
  164. int AppTradeClientCollectiveOrder(AppTradeClient * trade ,
  165. const char *clordId,
  166. const char aHandlInst,
  167. const char ordertype,
  168. const char *sideStr,
  169. const char *symbolStr,
  170. const char *orderQtyStr,
  171. const char *priceStr,
  172. const char *securityExchangeStr,
  173. const char *currencyStr,
  174. const char *account,
  175. const char *securityTypeStr,
  176. const char *accountStr,
  177. int entrustNum
  178. );
  179. int AppTradeClientCollectiveOrderCancel(AppTradeClient * trade,
  180. const char *clordId,
  181. int entrustNum ,
  182. const char *entrustNoStr,
  183. const char *securityExchangeStr,
  184. const char *currencyStr,
  185. const char *account
  186. );
  187. int AppTradeClientCollectiveOrderStatus(AppTradeClient * trade,
  188. int entrustNum ,
  189. const char *entrustNoStr,
  190. const char *account
  191. );
  192. int AppTradeClientBatchOrder(AppTradeClient * trade,
  193. const char *clordId,
  194. const char aHandlInst,
  195. const char ordertype,
  196. const char **symbolStr,
  197. const char **sideStr,
  198. const char **orderQtyStr,
  199. const char **priceStr,
  200. const char **securityExchangeStr,
  201. const char **currencyStr,
  202. const char **securityTypeStr,
  203. const char *account,
  204. int num
  205. );
  206. int AppTradeClientRequestForPositions(AppTradeClient * trade,
  207. const char *posReqID,
  208. int posReqType,
  209. const char *account,
  210. int accountType
  211. );
  212. int AppTradeClientMarketData(AppTradeClient * trade, const char *bookId,const char * securityExchange);
  213. #ifdef _cplusplus
  214. }
  215. #endif
  216. #endif