Tongshi.cpp
上传用户:zhanglf88
上传日期:2013-11-19
资源大小:6036k
文件大小:7k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. /*
  2. Cross Platform Core Code.
  3. Copyright(R) 2001-2002 Balang Software.
  4. All rights reserved.
  5. Using:
  6. Tongshi interface convertor functions;
  7. */
  8. #include "StdAfx.h"
  9. #include "Stockdrv.h"
  10. #include "Tongshi.h"
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // Convertor
  20. // 股票市场
  21. DWORD TSMarket_to_Market( WORD wMarket )
  22. {
  23. DWORD dwMarket = CStock::marketCHNA;
  24. if( SH_MARKET_EX == wMarket )
  25. dwMarket = CStock::marketSHSE;
  26. else if( SZ_MARKET_EX == wMarket )
  27. dwMarket = CStock::marketSZSE;
  28. return dwMarket;
  29. }
  30. WORD Market_to_TSMarket( DWORD dwMarket )
  31. {
  32. WORD wMarket = SH_MARKET_EX;
  33. if( CStock::marketSHSE == dwMarket )
  34. wMarket = SH_MARKET_EX;
  35. else if( CStock::marketSZSE == dwMarket )
  36. wMarket = SZ_MARKET_EX;
  37. return wMarket;
  38. }
  39. int DataType_to_TSDataType( int nDataType )
  40. {
  41. int nDataTypeTS = -1;
  42. switch( nDataType )
  43. {
  44. case CStock::dataInfo:
  45. case CStock::dataReport:
  46. nDataTypeTS = RCV_REPORT;
  47. break;
  48. case CStock::dataK:
  49. nDataTypeTS = FILE_HISTORY_EX;
  50. break;
  51. case CStock::dataDR:
  52. nDataTypeTS = FILE_POWER_EX;
  53. break;
  54. case CStock::dataBasetable:
  55. break;
  56. case CStock::dataBasetext:
  57. nDataTypeTS = FILE_BASE_EX;
  58. break;
  59. case CStock::dataNews:
  60. nDataTypeTS = FILE_NEWS_EX;
  61. break;
  62. case CStock::dataMinute:
  63. nDataTypeTS = FILE_MINUTE_EX;
  64. break;
  65. case CStock::dataOutline:
  66. break;
  67. case CStock::dataMultisort:
  68. nDataTypeTS = FILE_MULTISORT_EX;
  69. break;
  70. case CStock::dataDetail:
  71. nDataTypeTS = FILE_DETAIL_EX;
  72. break;
  73. default:;
  74. }
  75. return nDataTypeTS;
  76. }
  77. // 通视RCV_REPORT_STRUCTEx 转换为 标准 REPORT
  78. BOOL convert_TSREPORT_to_REPORT( RCV_REPORT_STRUCTEx *pTSReport, REPORT * pReport )
  79. {
  80. SP_ASSERT( pTSReport && pReport );
  81. if( NULL == pTSReport || NULL == pReport )
  82. return FALSE;
  83. memset( pReport, 0, sizeof(REPORT) );
  84. // 股票市场
  85. pReport->m_dwMarket = TSMarket_to_Market( pTSReport->m_wMarket );
  86. strncpy( pReport->m_szCode, pTSReport->m_szLabel, min(sizeof(pReport->m_szCode)-1,sizeof(pTSReport->m_szLabel)) );
  87. strncpy( pReport->m_szName, pTSReport->m_szName, min(sizeof(pReport->m_szName)-1,sizeof(pTSReport->m_szName)) );
  88. pReport->m_time = pTSReport->m_time;
  89. pReport->m_fLast = pTSReport->m_fLastClose;
  90. pReport->m_fOpen = pTSReport->m_fOpen;
  91. pReport->m_fHigh = pTSReport->m_fHigh;
  92. pReport->m_fLow = pTSReport->m_fLow;
  93. pReport->m_fNew = pTSReport->m_fNewPrice;
  94. pReport->m_fVolume = pTSReport->m_fVolume * 100;
  95. pReport->m_fAmount = pTSReport->m_fAmount;
  96. pReport->m_fBuyPrice[0] = pTSReport->m_fBuyPrice[0];
  97. pReport->m_fBuyPrice[1] = pTSReport->m_fBuyPrice[1];
  98. pReport->m_fBuyPrice[2] = pTSReport->m_fBuyPrice[2];
  99. pReport->m_fBuyVolume[0] = pTSReport->m_fBuyVolume[0] * 100;
  100. pReport->m_fBuyVolume[1] = pTSReport->m_fBuyVolume[1] * 100;
  101. pReport->m_fBuyVolume[2] = pTSReport->m_fBuyVolume[2] * 100;
  102. pReport->m_fSellPrice[0] = pTSReport->m_fSellPrice[0];
  103. pReport->m_fSellPrice[1] = pTSReport->m_fSellPrice[1];
  104. pReport->m_fSellPrice[2] = pTSReport->m_fSellPrice[2];
  105. pReport->m_fSellVolume[0] = pTSReport->m_fSellVolume[0] * 100;
  106. pReport->m_fSellVolume[1] = pTSReport->m_fSellVolume[1] * 100;
  107. pReport->m_fSellVolume[2] = pTSReport->m_fSellVolume[2] * 100;
  108. if( pTSReport->m_cbSize >= sizeof(RCV_REPORT_STRUCTEx) )
  109. {
  110. pReport->m_fBuyPrice[3] = pTSReport->m_fBuyPrice4;
  111. pReport->m_fBuyVolume[3] = pTSReport->m_fBuyVolume4 * 100;
  112. pReport->m_fSellPrice[3] = pTSReport->m_fSellPrice4;
  113. pReport->m_fSellVolume[3] = pTSReport->m_fSellVolume4 * 100;
  114. pReport->m_fBuyPrice[4] = pTSReport->m_fBuyPrice5;
  115. pReport->m_fBuyVolume[4] = pTSReport->m_fBuyVolume5 * 100;
  116. pReport->m_fSellPrice[4] = pTSReport->m_fSellPrice5;
  117. pReport->m_fSellVolume[4] = pTSReport->m_fSellVolume5 * 100;
  118. }
  119. return TRUE;
  120. }
  121. BOOL convert_TSHISTORY_to_KDATA( DWORD dwMarket, LPCTSTR lpszCode, RCV_HISTORY_STRUCTEx * pHistory, KDATA * pkd )
  122. {
  123. SP_ASSERT( pHistory && pkd );
  124. if( NULL == pHistory || NULL == pkd )
  125. return FALSE;
  126. memset( pkd, 0, sizeof(KDATA) );
  127. pkd->m_dwMarket = dwMarket;
  128. if( NULL != lpszCode )
  129. strncpy( pkd->m_szCode, lpszCode, min(sizeof(pkd->m_szCode)-1,strlen(lpszCode)) );
  130. pkd->m_time = pHistory->m_time;
  131. CSPTime sptime(pkd->m_time);
  132. if( 0 != pkd->m_time && -1 != pkd->m_time )
  133. pkd->m_date = sptime.ToStockTimeDay();
  134. pkd->m_fOpen = pHistory->m_fOpen;
  135. pkd->m_fHigh = pHistory->m_fHigh;
  136. pkd->m_fLow = pHistory->m_fLow;
  137. pkd->m_fClose = pHistory->m_fClose;
  138. pkd->m_fVolume = pHistory->m_fVolume * 100;
  139. pkd->m_fAmount = pHistory->m_fAmount;
  140. pkd->m_dwAdvance = pHistory->m_wAdvance;
  141. pkd->m_dwDecline = pHistory->m_wDecline;
  142. return TRUE;
  143. }
  144. BOOL convert_TSMINUTE_to_MINUTE( DWORD dwMarket, LPCTSTR lpszCode, RCV_MINUTE_STRUCTEx * pTSMinute, MINUTE * pMinute )
  145. {
  146. SP_ASSERT( pTSMinute && pMinute );
  147. if( NULL == pTSMinute || NULL == pMinute )
  148. return FALSE;
  149. memset( pMinute, 0, sizeof(MINUTE) );
  150. pMinute->m_dwType = 1; // 1 min
  151. pMinute->m_dwMarket = dwMarket;
  152. if( NULL != lpszCode )
  153. strncpy( pMinute->m_szCode, lpszCode, min(sizeof(pMinute->m_szCode)-1,strlen(lpszCode)) );
  154. pMinute->m_time = pTSMinute->m_time;
  155. pMinute->m_fNew = pTSMinute->m_fPrice;
  156. pMinute->m_fHigh = pTSMinute->m_fPrice;
  157. pMinute->m_fLow = pTSMinute->m_fPrice;
  158. pMinute->m_fVolume = pTSMinute->m_fVolume * 100;
  159. pMinute->m_fAmount = pTSMinute->m_fAmount;
  160. return TRUE;
  161. }
  162. BOOL convert_TSMULTISORT_to_MULTISORT( RCV_MULTISORT_STRUCTEx * pTSMultisort, MULTISORT * pMultisort )
  163. {
  164. SP_ASSERT( pTSMultisort && pMultisort );
  165. if( NULL == pTSMultisort || NULL == pMultisort )
  166. return FALSE;
  167. SP_ASSERT( sizeof(RCV_MULTISORT_STRUCTEx) == sizeof(MULTISORT) );
  168. memcpy( pMultisort, pTSMultisort, sizeof(MULTISORT) );
  169. return TRUE;
  170. }
  171. BOOL convert_TSPOWER_to_DRDATA( DWORD dwMarket, LPCTSTR lpszCode, RCV_POWER_STRUCTEx * pTSPower, DRDATA * pdr )
  172. {
  173. SP_ASSERT( pTSPower && pdr );
  174. if( NULL == pTSPower || NULL == pdr )
  175. return FALSE;
  176. memset( pdr, 0, sizeof(DRDATA) );
  177. pdr->m_dwMarket = dwMarket;
  178. if( NULL != lpszCode )
  179. strncpy( pdr->m_szCode, lpszCode, min(sizeof(pdr->m_szCode)-1,strlen(lpszCode)) );
  180. pdr->m_time = pTSPower->m_time;
  181. CSPTime sptime(pdr->m_time);
  182. if( 0 != pdr->m_time && -1 != pdr->m_time )
  183. pdr->m_date = sptime.ToStockTimeDay();
  184. pdr->m_fGive = pTSPower->m_fGive;
  185. pdr->m_fPei = pTSPower->m_fPei;
  186. pdr->m_fPeiPrice = pTSPower->m_fPeiPrice;
  187. pdr->m_fProfit = pTSPower->m_fProfit;
  188. return TRUE;
  189. }