cctpcb.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Copyright 2013-2014 Fuzamei tech Ltd. All rights reserved.
  2. package gocctp
  3. /*
  4. #include <libcctp.h>
  5. #include <string.h>
  6. */
  7. import "C"
  8. import (
  9. "unsafe"
  10. )
  11. //export GoOnMdRspUserLogin
  12. func GoOnMdRspUserLogin(pRspUserLogin *C.CThostFtdcRspUserLoginField, pRspInfo *C.CThostFtdcRspInfoField, nRequestID int, bIsLast bool, ctx unsafe.Pointer) {
  13. errMsg := ""
  14. if unsafe.Pointer(pRspInfo) != nil {
  15. errNo := pRspInfo.ErrorID
  16. if errNo != 0 {
  17. errMsg = C.GoString(&pRspInfo.ErrorMsg[0])
  18. }
  19. }
  20. mdApi := (*MdApi)(ctx)
  21. mdApi.OnRspUserLogin(errMsg)
  22. }
  23. //export GoOnMdRspUserLogout
  24. func GoOnMdRspUserLogout(pUserLogout *C.CThostFtdcUserLogoutField, pRspInfo *C.CThostFtdcRspInfoField, nRequestID int, bIsLast bool, ctx unsafe.Pointer) {
  25. errMsg := ""
  26. if unsafe.Pointer(pRspInfo) != nil {
  27. errNo := pRspInfo.ErrorID
  28. if errNo != 0 {
  29. errMsg = C.GoString(&pRspInfo.ErrorMsg[0])
  30. }
  31. }
  32. mdApi := (*MdApi)(ctx)
  33. mdApi.OnRspUserLogout(errMsg)
  34. }
  35. //export GoOnMdRspError
  36. func GoOnMdRspError(pRspInfo *C.CThostFtdcRspInfoField, nRequestID int, bIsLast bool, ctx unsafe.Pointer) {
  37. errMsg := ""
  38. if unsafe.Pointer(pRspInfo) != nil {
  39. errNo := pRspInfo.ErrorID
  40. if errNo != 0 {
  41. errMsg = C.GoString(&pRspInfo.ErrorMsg[0])
  42. }
  43. }
  44. mdApi := (*MdApi)(ctx)
  45. mdApi.OnRspError(errMsg)
  46. }
  47. //export GoOnTdRspUserLogin
  48. func GoOnTdRspUserLogin(pRspUserLogin *C.CThostFtdcRspUserLoginField, pRspInfo *C.CThostFtdcRspInfoField, nRequestID int, bIsLast bool, ctx unsafe.Pointer) {
  49. errMsg := ""
  50. if unsafe.Pointer(pRspInfo) != nil {
  51. errNo := pRspInfo.ErrorID
  52. if errNo != 0 {
  53. errMsg = C.GoString(&pRspInfo.ErrorMsg[0])
  54. }
  55. }
  56. tdApi := (*TdApi)(ctx)
  57. tdApi.OnRspUserLogin(errMsg)
  58. }
  59. //export GoOnTdRspUserLogout
  60. func GoOnTdRspUserLogout(pUserLogout *C.CThostFtdcUserLogoutField, pRspInfo *C.CThostFtdcRspInfoField, nRequestID int, bIsLast bool, ctx unsafe.Pointer) {
  61. errMsg := ""
  62. if unsafe.Pointer(pRspInfo) != nil {
  63. errNo := pRspInfo.ErrorID
  64. if errNo != 0 {
  65. errMsg = C.GoString(&pRspInfo.ErrorMsg[0])
  66. }
  67. }
  68. tdApi := (*TdApi)(ctx)
  69. tdApi.OnRspUserLogout(errMsg)
  70. }
  71. //export GoOnTdRspError
  72. func GoOnTdRspError(pRspInfo *C.CThostFtdcRspInfoField, nRequestID int, bIsLast bool, ctx unsafe.Pointer) {
  73. errMsg := ""
  74. if unsafe.Pointer(pRspInfo) != nil {
  75. errNo := pRspInfo.ErrorID
  76. if errNo != 0 {
  77. errMsg = C.GoString(&pRspInfo.ErrorMsg[0])
  78. }
  79. }
  80. tdApi := (*TdApi)(ctx)
  81. tdApi.OnRspError(errMsg)
  82. }
  83. //export GoOnRtnDepthMarketData
  84. func GoOnRtnDepthMarketData(pDepthMarketData *C.CThostFtdcDepthMarketDataField, ctx unsafe.Pointer) {
  85. field := &CThostFtdcDepthMarketDataField{}
  86. size := unsafe.Sizeof(*field)
  87. C.memcpy(unsafe.Pointer(field), unsafe.Pointer(pDepthMarketData), C.size_t(size))
  88. mdApi := (*MdApi)(ctx)
  89. mdApi.OnRtnDepthMarketData(field)
  90. }
  91. //export GoOnRspQryExchange
  92. func GoOnRspQryExchange(pExchange *C.CThostFtdcExchangeField, pRspInfo *C.CThostFtdcRspInfoField, nRequestID int, bIsLast bool, ctx unsafe.Pointer) {
  93. field := &CThostFtdcExchangeField{}
  94. size := unsafe.Sizeof(*field)
  95. C.memcpy(unsafe.Pointer(field), unsafe.Pointer(pExchange), C.size_t(size))
  96. errMsg := ""
  97. if unsafe.Pointer(pRspInfo) != nil {
  98. errNo := pRspInfo.ErrorID
  99. if errNo != 0 {
  100. errMsg = C.GoString(&pRspInfo.ErrorMsg[0])
  101. }
  102. }
  103. tdApi := (*TdApi)(ctx)
  104. tdApi.OnRspQryExchange(field, errMsg, bIsLast)
  105. }
  106. //export GoOnRspQryInstrument
  107. func GoOnRspQryInstrument(pInstrument *C.CThostFtdcInstrumentField, pRspInfo *C.CThostFtdcRspInfoField, nRequestID int, bIsLast bool, ctx unsafe.Pointer) {
  108. field := &CThostFtdcInstrumentField{}
  109. size := unsafe.Sizeof(*field)
  110. C.memcpy(unsafe.Pointer(field), unsafe.Pointer(pInstrument), C.size_t(size))
  111. errMsg := ""
  112. if unsafe.Pointer(pRspInfo) != nil {
  113. errNo := pRspInfo.ErrorID
  114. if errNo != 0 {
  115. errMsg = C.GoString(&pRspInfo.ErrorMsg[0])
  116. }
  117. }
  118. tdApi := (*TdApi)(ctx)
  119. tdApi.OnRspQryInstrument(field, errMsg, bIsLast)
  120. }