ApplicationParameter.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. using Muchinfo.MTPClient.Data.Enums;
  2. using Muchinfo.MTPClient.Infrastructure.LinkProxy;
  3. using Muchinfo.MTPClient.Infrastructure.LinkProxy.Enum;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Net;
  9. using System.Net.NetworkInformation;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Xml.Linq;
  15. using Muchinfo.MTPClient.Data.Model;
  16. using Muchinfo.MTPClient.Data.Model.Account;
  17. using Muchinfo.MTPClient.Infrastructure.Cache;
  18. namespace Muchinfo.MTPClient.Infrastructure.Utilities
  19. {
  20. /// <summary>
  21. /// ApplicationParameter类
  22. /// </summary>
  23. public class ApplicationParameter
  24. {
  25. #region 私有字段
  26. private static DateTime _serverTimeNow;
  27. private static int _showChart = 0;
  28. private static System.Timers.Timer _serverTimer;
  29. /// <summary>
  30. /// 基础时间 1970/01/01 00:00:00
  31. /// </summary>
  32. private static DateTime _basicDateTime = new DateTime(1970, 1, 1, 0, 0, 0);
  33. #endregion
  34. #region 公有静态属性
  35. /// <summary>
  36. /// 获取服务器当前时间
  37. /// </summary>
  38. public static DateTime ServerTimeNow
  39. {
  40. get { return _serverTimeNow; }
  41. set { _serverTimeNow = value; }
  42. }
  43. /// <summary>
  44. /// 获取基础时间 1970/01/01 00:00:00
  45. /// </summary>
  46. public static DateTime BasicDateTime
  47. {
  48. get { return _basicDateTime; }
  49. }
  50. /// <summary>
  51. /// 配置是否显示图表
  52. /// </summary>
  53. public static int ShowChart
  54. {
  55. get { return _showChart; }
  56. set { _showChart = value; }
  57. }
  58. /// <summary>
  59. /// 配置是否显示报表
  60. /// </summary>
  61. public static string ReportAddress { get; set; }
  62. /// <summary>
  63. /// 配置F10地址
  64. /// </summary>
  65. public static string FtenAddress { get; set; }
  66. private static string _isShowIdentifyingCode;
  67. /// <summary>
  68. /// 是否显示验证码【 0:不显示,1:显示,2:错误后显示】
  69. /// </summary>
  70. public static string IsShowIdentifyingCode
  71. {
  72. get { return _isShowIdentifyingCode; }
  73. set { _isShowIdentifyingCode = value; }
  74. }
  75. private static int _MarketTradeDefaultPriceMode = -1;
  76. /// <summary>
  77. /// 做市模式默认价格类型:若商品为做市模式,则默认成交的价格类型为“市价”【备注:0为市价,1为限价】
  78. /// </summary>
  79. public static int MarketTradeDefaultPriceMode
  80. {
  81. get { return _MarketTradeDefaultPriceMode; }
  82. set { _MarketTradeDefaultPriceMode = value; }
  83. }
  84. private static int _BidTradeDefaultPriceMode = -1;
  85. /// <summary>
  86. /// 竞价模式默认价格类型: 若商品为竞价模式,则默认成交的价格类型为“限价”【备注:0为市价,1为限价】
  87. /// </summary>
  88. public static int BidTradeDefaultPriceMode
  89. {
  90. get { return _BidTradeDefaultPriceMode; }
  91. set { _BidTradeDefaultPriceMode = value; }
  92. }
  93. /// <summary>
  94. /// 是否显示总浮动盈亏
  95. /// </summary>
  96. public static int IsShowSumPL { get; set; }
  97. /// <summary>
  98. /// 会员风控间隔时间
  99. /// </summary>
  100. public static int MemberMonitorTick { get; set; }
  101. /// <summary>
  102. /// 取历史Tick数据量
  103. /// </summary>
  104. public static short QuoteTickCount
  105. {
  106. get;
  107. set;
  108. }
  109. /// <summary>
  110. /// 是否显示风险提示
  111. /// </summary>
  112. public static int IsShowRateTips { get; set; }
  113. /// <summary>
  114. /// 是否显示托管计划
  115. /// </summary>
  116. public static bool IsShowDepositPlanMarket
  117. {
  118. get;
  119. set;
  120. }
  121. /// <summary>
  122. /// 服务超时时间
  123. /// </summary>
  124. public static int ServerTimeOut { get; set; }
  125. /// <summary>
  126. /// 交易地址
  127. /// </summary>
  128. public static string BizAddress { get; set; }
  129. /// <summary>
  130. /// 行情地址
  131. /// </summary>
  132. public static string QuoteAddress { get; set; }
  133. /// <summary>
  134. /// 游客行情地址
  135. /// </summary>
  136. public static string GuestQuoteAddress { get; set; }
  137. /// <summary>
  138. /// 开户注册地址
  139. /// </summary>
  140. public static string RegAccountAddress { get; set; }
  141. /// <summary>
  142. /// 是否显示预埋单功能
  143. /// </summary>
  144. public static int IsPrePostVisible { get; set; }
  145. /// <summary>
  146. /// 是否限制预埋单数量:【是否限制预埋单数量(不限制:0,限制数量:1)】
  147. /// </summary>
  148. public static decimal MaxPrePostOrderLot { get; set; }
  149. /// <summary>
  150. /// 默认下单数量
  151. /// </summary>
  152. public static decimal DefaultOrderLot { get; set; }
  153. private static int _defaultOpenMode = 1; //edit by dk 默认为1 建仓方式,枚举值发生变化20171128
  154. /// <summary>
  155. /// 设置下单默认建仓模式(1:建仓 2平仓;先平后建:3)
  156. /// </summary>
  157. public static int DefaultOpenMode
  158. {
  159. get { return _defaultOpenMode; }
  160. set { _defaultOpenMode = value; }
  161. }
  162. /// <summary>
  163. /// 提货单打印地址
  164. /// </summary>
  165. public static string TakeOrderPrintAdress { get; set; }
  166. #endregion
  167. #region 系统参数属性
  168. /// <summary>
  169. /// 官网
  170. /// </summary>
  171. public static string WebSite { get; set; }
  172. /// <summary>
  173. /// 系统布局样色
  174. /// </summary>
  175. public static string LayoutStyle { get; set; }
  176. /// <summary>
  177. /// 系统颜色主题
  178. /// </summary>
  179. public static string ColorStyle { get; set; }
  180. /// <summary>
  181. /// 应用程序版本
  182. /// </summary>
  183. public static string Version
  184. {
  185. get;
  186. set;
  187. }
  188. /// <summary>
  189. /// 显示表格的样式
  190. /// </summary>
  191. public static string DataGridColor { get; set; }
  192. /// <summary>
  193. /// 显示登录界面提示信息
  194. /// </summary>
  195. public static string LoginRemark { get; set; }
  196. /// <summary>
  197. /// 免责条款文件路径
  198. /// </summary>
  199. public static string EscapeClauseFilePath
  200. {
  201. get
  202. {
  203. return Path.Combine(UserManager.SysConfigFolderPath, "EscapeClause.rtf");
  204. }
  205. }
  206. /// <summary>
  207. /// 应用程序默认升级文件夹
  208. /// </summary>
  209. public static string UpdateFolderName { get; set; }
  210. /// <summary>
  211. /// 发送邮件地址
  212. /// </summary>
  213. public static string ToAddress { get; set; }
  214. /// <summary>
  215. /// 应用程序升级地址
  216. /// </summary>
  217. public static string UpdateAddress { get; set; }
  218. public static string TradeSystemName { get; set; }
  219. public static string ExchangeName { get; set; }
  220. public static string MarketName { get; set; }
  221. /// <summary>
  222. /// 登录Guid
  223. /// </summary>
  224. public static string LoginGuid { get; set; }
  225. /// <summary>
  226. /// 图片扩展名
  227. /// </summary>
  228. public static string ImageExtension { get; set; }
  229. /// <summary>
  230. /// 锁屏时间(0时不锁屏)
  231. /// </summary>
  232. public static int LockSreenTime { get; set; }
  233. /// <summary>
  234. /// 是否显示锁屏背景图片【0:不显示,1显示】
  235. /// </summary>
  236. private static int _IsShowBGLockSreen = 0;
  237. public static int IsShowBGLockSreen
  238. {
  239. get { return _IsShowBGLockSreen; }
  240. set { _IsShowBGLockSreen = value; }
  241. }
  242. /// <summary>
  243. /// 同步账号信息周期
  244. /// </summary>
  245. public static int SyncAccountCycle { get; set; }
  246. private static string _cusBankNetSign = string.Empty;
  247. /// <summary>
  248. /// 网银端签约的银行
  249. /// </summary>
  250. public static string CusBankNetSign
  251. {
  252. get { return _cusBankNetSign; }
  253. set { _cusBankNetSign = value; }
  254. }
  255. /// <summary>
  256. /// 配置是否显示银行绑卡解绑功能
  257. /// </summary>
  258. public static int IsConfigShowBingCard { get; set; }
  259. /// <summary>
  260. /// 网银端签约的提示信息
  261. /// </summary>
  262. public static string CusBankNetSignTipsInfo { get; set; }
  263. public static int DayQuoteInterval { get; set; }
  264. /// <summary>
  265. /// 订单在市
  266. /// </summary>
  267. public static string OrderOnMarket { get; set; }
  268. /// <summary>
  269. /// 已成交
  270. /// </summary>
  271. public static string OrderTraded { get; set; }
  272. /// <summary>
  273. /// 单据是否显示买卖方向
  274. /// </summary>
  275. public static int IsShowDirection { get; set; }
  276. /// <summary>
  277. /// 抬头保存的版本1.1.1.1 (自选.即期.竞价.混合)
  278. /// </summary>
  279. public static string ConfigHeadersVer { get; set; }
  280. /// <summary>
  281. /// 是否为对接新银行
  282. /// </summary>
  283. public static int NewBankPlatform { get; set; }
  284. /// <summary>
  285. /// 是否显示交割信息
  286. /// </summary>
  287. public static int IsDeliveryVisible { get; set; }
  288. /// <summary>
  289. /// 是否显示大字报价
  290. /// </summary>
  291. //public static int IsShowQuoteBoard
  292. //{
  293. // get; set;
  294. //}
  295. private static int _IsShowQuoteBoard = 0;
  296. /// <summary>
  297. /// 是否显示大字报价【默认不显示】
  298. /// </summary>
  299. public static int IsShowQuoteBoard
  300. {
  301. get { return _IsShowQuoteBoard; }
  302. set { _IsShowQuoteBoard = value; }
  303. }
  304. /// <summary>
  305. /// 发售列表头(1,2,)
  306. /// </summary>
  307. public static string SaleQuoteHeaders { get; set; }
  308. /// <summary>
  309. /// 是否显示五档委托量(大利市)
  310. /// </summary>
  311. public static int QuoteQueueInfo { get; set; }
  312. /// <summary>
  313. /// 竞价市场显示的字段
  314. /// </summary>
  315. public static string BidQuoteHeaders { get; set; }
  316. /// <summary>
  317. /// 混合市场显示的字段
  318. /// </summary>
  319. public static string BidMarketQuoteHeaders { get; set; }
  320. /// <summary>
  321. /// 做市市场显示的字段
  322. /// </summary>
  323. public static string MakeMarketQuoteHeaders { get; set; }
  324. /// <summary>
  325. /// 若商品为混合模式,则默认成交的价格类型为“限价”【备注:0为市价,1为限价】
  326. /// </summary>
  327. public static int XMarketDefaultPriceMode { get; set; }
  328. /// <summary>
  329. /// 若商品为混合模式,则默认不显示”【备注:0为不显示,1为显示】
  330. /// </summary>
  331. public static int XMarketShowMarketPrice { get; set; }
  332. /// <summary>
  333. /// 通道交易市场显示的字段
  334. /// </summary>
  335. public static string ChannelQuoteHeaders { get; set; }
  336. public static string Copyright { get; set; }
  337. /// <summary>
  338. /// 是否显示所有商品
  339. /// </summary>
  340. /// <value><c>true</c> if [show all goods]; otherwise, <c>false</c>.</value>
  341. public static bool ShowAllGoods { get; set; }
  342. /// <summary>
  343. /// 是否显示我的自选
  344. /// </summary>
  345. /// <value><c>true</c> if [show my selected goods]; otherwise, <c>false</c>.</value>
  346. public static bool ShowMySelectedGoods { get; set; }
  347. /// <summary>
  348. /// 是否显示外部交易所
  349. /// </summary>
  350. /// <value><c>true</c> if [show external exchage]; otherwise, <c>false</c>.</value>
  351. public static bool ShowExternalExchage { get; set; }
  352. /// <summary>
  353. /// 是否显示平仓
  354. /// </summary>
  355. /// <value><c>true</c> if [show close order]; otherwise, <c>false</c>.</value>
  356. public static bool ShowCloseOrder { get; set; }
  357. public static bool ShowOpenCloseOrder { get; set; }
  358. /// <summary>
  359. /// 是否显示下单界面的买卖价,来源config.xml
  360. /// </summary>
  361. public static bool ShowBuyOrSellPrice { get; set; }
  362. public static bool CanUseAllCloseOrder { get;set; }
  363. public static bool CanUseQuickClose { get;set; }
  364. public static bool CanUseBackHandOpen { get;set; }
  365. public static bool CanUseQuickLockOrder { get;set; }
  366. public static string PublishNetIpAddress { get; set; }
  367. #endregion
  368. #region 风管云平台
  369. /// <summary>
  370. /// 风管云平台服务地址
  371. /// </summary>
  372. public static string ErmcpAddress { get; set; }
  373. #endregion
  374. #region 公有静态方法
  375. /// <summary>
  376. /// 从Config.xml读取系统配置
  377. /// </summary>
  378. public static void InitializeSystemConfig()
  379. {
  380. try
  381. {
  382. LoginGuid = Guid.NewGuid().ToString();
  383. var path = Path.Combine(UserManager.SysConfigFolderPath, "Config.xml");
  384. var xdoc = XDocument.Load(path);
  385. if (xdoc.Root == null) return;
  386. var config = (from e in xdoc.Root.Elements("Config")
  387. select new
  388. {
  389. QuoteAddress = (string)e.Element("QuoteAddress"),
  390. BizAddress = (string)e.Element("BizAddress"),
  391. UpdateAddress = (string)e.Element("UpdateAddress"),
  392. UpdateFolderName = (string)e.Element("UpdateFolderName"),
  393. LoginRemark = (string)e.Element("LoginRemark"),
  394. TradeSystemName = (string)e.Element("TradeSystemName"),
  395. GuestQuoteAddress = (string)e.Element("GuestQuoteAddress"),
  396. DayQuoteInterval = (string)e.Element("DayQuoteInterval"),
  397. RegAccountAddress = (string)e.Element("RegAccountAddress"),
  398. IsShowIdentifyingCode = (string)e.Element("IsShowIdentifyingCode"),
  399. ConfigHeadersVer = (string)e.Element("ConfigHeadersVer"),
  400. FtenAddress = (string)e.Element("FtenAddress"),
  401. ExchangeName = (string)e.Element("ExchangeName"),
  402. WebSite = (string)e.Element("WebSite"),
  403. LayoutStyle = (string)e.Element("LayoutStyle"),
  404. Copyright = (e.Element("Copyright") == null) ? "Copyright © 2020" : (string)e.Element("Copyright"),
  405. ShowAllGoods =e.Element("ShowAllGoods") == null || (bool)e.Element("ShowAllGoods"),
  406. ShowMySelectedGoods = e.Element("ShowMySelectedGoods") != null && (bool)e.Element("ShowMySelectedGoods"),
  407. ShowExternalExchage = e.Element("ShowExternalExchage") != null && (bool)e.Element("ShowExternalExchage"),
  408. ShowCloseOrder = e.Element("ShowCloseOrder") != null && (bool)e.Element("ShowCloseOrder"),
  409. ShowOpenCloseOrder = e.Element("ShowOpenCloseOrder") != null && (bool)e.Element("ShowOpenCloseOrder"),
  410. ShowBuyOrSellPrice = e.Element("ShowBuyOrSellPrice") != null && (bool)e.Element("ShowBuyOrSellPrice"),
  411. CanUseAllCloseOrder = e.Element("CanUseAllCloseOrder") != null && (bool)e.Element("CanUseAllCloseOrder"),
  412. CanUseQuickClose = e.Element("CanUseQuickClose") != null && (bool)e.Element("CanUseQuickClose"),
  413. CanUseBackHandOpen = e.Element("CanUseBackHandOpen") != null && (bool)e.Element("CanUseBackHandOpen"),
  414. CanUseQuickLockOrder = e.Element("CanUseQuickLockOrder") != null && (bool)e.Element("CanUseQuickLockOrder"),
  415. PublishNetIpAddress = (string)e.Element("PublishNetIpAddress"),
  416. ErmcpAddress = (string)e.Element("ErmcpAddress"),
  417. }).FirstOrDefault();
  418. if (config == null) return;
  419. QuoteAddress = config.QuoteAddress;
  420. BizAddress = config.BizAddress;
  421. UpdateAddress = config.UpdateAddress;
  422. UpdateFolderName = config.UpdateFolderName;
  423. Version = Application.ResourceAssembly.GetName().Version.ToString();
  424. LoginRemark = config.LoginRemark;
  425. TradeSystemName = config.TradeSystemName;
  426. GuestQuoteAddress = config.GuestQuoteAddress;
  427. RegAccountAddress = config.RegAccountAddress;
  428. ConfigHeadersVer = config.ConfigHeadersVer;
  429. FtenAddress = config.FtenAddress;
  430. IsShowIdentifyingCode = config.IsShowIdentifyingCode;
  431. int interval = 0;
  432. int.TryParse(config.DayQuoteInterval, out interval);
  433. DayQuoteInterval = interval;
  434. ExchangeName = config.ExchangeName;
  435. WebSite = config.WebSite;
  436. LayoutStyle = config.LayoutStyle;
  437. Copyright = config.Copyright;
  438. ShowAllGoods = config.ShowAllGoods;
  439. ShowMySelectedGoods = config.ShowMySelectedGoods;
  440. ShowExternalExchage = config.ShowExternalExchage;
  441. ShowCloseOrder = config.ShowCloseOrder;
  442. ShowOpenCloseOrder = config.ShowOpenCloseOrder;
  443. ShowBuyOrSellPrice = config.ShowBuyOrSellPrice;
  444. CanUseAllCloseOrder = config.CanUseAllCloseOrder;
  445. CanUseQuickClose = config.CanUseQuickClose;
  446. CanUseBackHandOpen = config.CanUseBackHandOpen;
  447. CanUseQuickLockOrder = config.CanUseQuickLockOrder;
  448. PublishNetIpAddress = config.PublishNetIpAddress;
  449. ErmcpAddress = config.ErmcpAddress;
  450. ////初始化链路
  451. InitializeLink();
  452. }
  453. catch (Exception e)
  454. {
  455. throw e;
  456. }
  457. }
  458. /// <summary>
  459. /// 设置系统时间s
  460. /// </summary>
  461. /// <param name="seconds"></param>
  462. public static void SetSystemTime(ulong seconds)
  463. {
  464. long lTime = long.Parse(seconds + "0000000");
  465. TimeSpan toNow = new TimeSpan(lTime);
  466. var timeNow = TimeZone.CurrentTimeZone.ToLocalTime(_basicDateTime.Add(toNow));
  467. SetServerTime(timeNow);
  468. }
  469. /// <summary>
  470. /// 设置系统时间s
  471. /// </summary>
  472. /// <param name="seconds"></param>
  473. public static void SetSystemTime(int seconds)
  474. {
  475. var timeNow = TimeZone.CurrentTimeZone.ToLocalTime(_basicDateTime.AddMilliseconds(seconds));
  476. SetServerTime(timeNow);
  477. }
  478. /// <summary>
  479. /// 设置服务器时间
  480. /// </summary>
  481. /// <param name="serverTime">服务器时间</param>
  482. public static void SetServerTime(DateTime serverTime)
  483. {
  484. if (_serverTimer == null)
  485. {
  486. _serverTimer = new System.Timers.Timer(1000);
  487. _serverTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_ServerTimer_Elapsed);
  488. }
  489. _serverTimer.Stop();
  490. _serverTimeNow = serverTime;
  491. _serverTimer.Start();
  492. }
  493. #endregion
  494. /// <summary>
  495. /// 判断是否显示市价
  496. /// </summary>
  497. public static bool CanMarketPrice(QuoteGoods currentGoods)
  498. {
  499. var external = CacheManager.CacheExchanges;
  500. var groups = CacheManager.CacheGoodsGroups;
  501. var isMarketPrice = "";
  502. if (groups != null && groups.Any())
  503. {
  504. groups.ForEach((group) =>
  505. {
  506. if (group.GoodsGroupid == currentGoods.GroupID)// 先用商品中的groupId 去 商品组中查找,找出ExchangeId
  507. {
  508. var exchangeId = group.ExChangeId;
  509. if (external != null && external.Any())
  510. {
  511. var exchaneInfo = external.Find((externalExchange) => exchangeId == externalExchange.ExchangeId);
  512. isMarketPrice = exchaneInfo.IsMarketPrice;
  513. }
  514. }
  515. });
  516. }
  517. if ("0".Equals(isMarketPrice)) // 不支持
  518. {
  519. return false;
  520. }
  521. else if ("1".Equals(isMarketPrice)) // 支持
  522. {
  523. return true;
  524. }
  525. return false;
  526. }
  527. #region 私有静态方法
  528. /// <summary>
  529. /// Handles the Elapsed event of the m_ServerTimer control.
  530. /// </summary>
  531. /// <param name="sender">The source of the event.</param>
  532. /// <param name="e">The <see cref="System.Timers.ElapsedEventArgs"/> instance containing the event data.</param>
  533. private static void m_ServerTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  534. {
  535. _serverTimeNow = _serverTimeNow.AddSeconds(1);
  536. }
  537. /// <summary>
  538. /// 初始化链路
  539. /// </summary>
  540. private static void InitializeLink()
  541. {
  542. var quotationAddress = QuoteAddress.Split(':');
  543. var tradeAddress = BizAddress.Split(':');
  544. string quotationHost = string.Empty;
  545. string guestQuoteHost = string.Empty;
  546. string tradeHost = string.Empty;
  547. int quotationPort = 0, tradePort = 0, guestQuotePort = 0;
  548. if (quotationAddress.Length == 2)
  549. {
  550. quotationHost = quotationAddress[0];
  551. int.TryParse(quotationAddress[1], out quotationPort);
  552. }
  553. if (tradeAddress.Length == 2)
  554. {
  555. tradeHost = tradeAddress[0];
  556. int.TryParse(tradeAddress[1], out tradePort);
  557. }
  558. if (!string.IsNullOrWhiteSpace(GuestQuoteAddress))
  559. {
  560. var guestQuoteAdd = GuestQuoteAddress.Split(':');
  561. if (quotationAddress.Length == 2)
  562. {
  563. guestQuoteHost = guestQuoteAdd[0];
  564. int.TryParse(guestQuoteAdd[1], out guestQuotePort);
  565. }
  566. }
  567. LinkManager.Instance.Initialize(new LinkManagerParameters()
  568. {
  569. QuotationHost = quotationHost,
  570. QuotationPort = quotationPort,
  571. TradeHost = tradeHost,
  572. TradePort = tradePort,
  573. GuestQuotationHost = guestQuoteHost,
  574. GuestQuotationPort = guestQuotePort,
  575. TradeLinkeType = LinkType.TCP,
  576. TradeDatagramType = DatagramType.Protobuf
  577. });
  578. }
  579. #endregion
  580. #region 风管云平台
  581. /// <summary>
  582. /// 风管云平台参数更新方法,主要是通过GO服务更新相关配置信息
  583. /// </summary>
  584. public static void UpdateErmcpParamete()
  585. {
  586. // 获取交易与行情 Host
  587. String jsonString = HttpUtility.HttpGet(ErmcpAddress);
  588. Dictionary<String, Object> dicJson = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<String, Object>>(jsonString);
  589. Dictionary<String, String> dataJson = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<String, String>>(dicJson["data"].ToString());
  590. LinkManager.Instance.Parameters.TradeHost = dataJson["tradeHost"];
  591. LinkManager.Instance.Parameters.TradePort = int.Parse(dataJson["tradePort"]);
  592. LinkManager.Instance.Parameters.QuotationHost = dataJson["quoteHost"];
  593. LinkManager.Instance.Parameters.QuotationPort = int.Parse(dataJson["quotePort"]);
  594. }
  595. #endregion
  596. public static LockType _LockType = LockType.UnLock;// 锁定商品
  597. /// <summary>
  598. /// 适配自动止损止盈的功能-将本地设置的止盈止损上传到服务端去。由服务端处理
  599. /// </summary>
  600. /// <param name="newOrder"></param>
  601. /// <param name="order"></param>
  602. public static void MakeSpsl(NewEntrustOrder newOrder)
  603. {
  604. if (newOrder == null)
  605. {
  606. return;
  607. }
  608. var userInfo = UserManager.GetCurrentUserInfo();
  609. if (userInfo != null && userInfo.TradeParams != null)
  610. {
  611. var goodsParams = userInfo.TradeParams.AllGoodsForAutoEntrust;
  612. if (goodsParams != null && goodsParams.Count > 0)
  613. {
  614. var _params = goodsParams.FirstOrDefault(item => newOrder.GoodsId == item.GoodsId && newOrder.BuyOrSell == (Direction)item.Direction);// 在匹配商品的同时,还需要匹配买卖方向
  615. if (_params != null && newOrder.BuildType == OpenCloseMode.BUILDTYPE_OPEN) // 只有建仓时候才会考虑上传止盈止损
  616. {
  617. newOrder.SPPoint = _params.Profit;
  618. newOrder.SLPoint = _params.Loss;
  619. }
  620. }
  621. }
  622. }
  623. /// <summary>
  624. /// 交易所下商品组、商品的关系
  625. /// 1、交易所下有多个商品组,商品组下有多个商品。
  626. /// </summary>
  627. /// <returns></returns>
  628. public static void MakeExChangeGroupGoodsMap()
  629. {
  630. // uint是商品组的groupId ,商品的数量
  631. ExChangeCheckModel changeCheckModel = new ExChangeCheckModel();
  632. var allGoods = CacheManager.CacheGoodsBaseInfos;// 所有的商品
  633. foreach (QuoteGoods item in allGoods)
  634. {
  635. if (changeCheckModel.Group.ContainsKey(item.GroupID))
  636. {
  637. changeCheckModel.Group[item.GroupID].Add(item.GoodsId);
  638. }
  639. else
  640. {
  641. List<uint> goodsIds = new List<uint> {item.GoodsId};
  642. changeCheckModel.Group.Add(item.GroupID, goodsIds);
  643. }
  644. }
  645. // 查找交易所和商品组的关系
  646. var groups = CacheManager.CacheGoodsGroups;
  647. foreach (GoodsGroup goodsGroup in groups)
  648. {
  649. if (changeCheckModel.ExChangeGroup.ContainsKey(goodsGroup.ExChangeId))
  650. {
  651. changeCheckModel.ExChangeGroup[goodsGroup.ExChangeId].Add(goodsGroup.GoodsGroupid);
  652. }
  653. else
  654. {
  655. List<long> groupIds = new List<long>() {goodsGroup.GoodsGroupid};
  656. changeCheckModel.ExChangeGroup.Add(goodsGroup.ExChangeId, groupIds);
  657. }
  658. }
  659. CacheManager.LoadExChangeGroupGoods(changeCheckModel);
  660. }
  661. #region 获取ip地址
  662. private static string _publisgNetIp = "";
  663. public static string PublisgNetIp
  664. {
  665. get { return _publisgNetIp ?? HttpGetPublishNetIp(); }
  666. set { _publisgNetIp = value; }
  667. }
  668. /// <summary>
  669. /// 获取公网ip地址 --如果机器是局域网的,获取到的地址就是本机地址,如果电脑是拨号上网或者具有独立的公网IP的情况下,获取到的是公网地址
  670. /// </summary>
  671. /// <param name="netType">"" 表示本地所有ip,InterNetWork表示ipv类型的网络ip,InterNetworkV6 表示获取ipv6类型的网络ip地址</param>
  672. /// <returns></returns>
  673. private static string GetIp(string netType)
  674. {
  675. string hostName = Dns.GetHostName();
  676. IPAddress[] addresses = Dns.GetHostAddresses(hostName);
  677. List<string> ipsList = new List<string>();
  678. if (netType == string.Empty)
  679. {
  680. for (int i = 0; i < addresses.Length; i++)
  681. {
  682. ipsList.Add(addresses[i].ToString());
  683. }
  684. }
  685. else
  686. {
  687. for (int i = 0; i < addresses.Length; i++)
  688. {
  689. if (addresses[i].AddressFamily.ToString() == netType)
  690. {
  691. ipsList.Add(addresses[i].ToString());
  692. }
  693. }
  694. }
  695. for (int i = 0; i < ipsList.Count; i++)
  696. {
  697. if (ipsList[i].Equals("::1"))
  698. {
  699. continue;
  700. }
  701. return ipsList[i];
  702. }
  703. return "";
  704. }
  705. private static string GetNetIp()
  706. {
  707. //试试这个
  708. NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
  709. foreach (NetworkInterface ni in interfaces)
  710. {
  711. if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
  712. {
  713. foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
  714. {
  715. if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
  716. {
  717. return ip.Address.ToString();
  718. }
  719. }
  720. }
  721. }
  722. return GetIp("");
  723. }
  724. public static void MakePublishNetIp()
  725. {
  726. _publisgNetIp = "";
  727. Task.Factory.StartNew(() =>
  728. {
  729. PublisgNetIp = HttpGetPublishNetIp();
  730. });
  731. }
  732. private static string HttpGetPublishNetIp()
  733. {
  734. if (_publisgNetIp != string.Empty)
  735. {
  736. return _publisgNetIp;
  737. }
  738. string ret = "";
  739. try
  740. {
  741. if (ApplicationParameter.PublishNetIpAddress == null ||
  742. ApplicationParameter.PublishNetIpAddress.Equals(""))
  743. {
  744. return GetNetIp();
  745. }
  746. else
  747. {
  748. string url = "";
  749. string encoding = "";
  750. if (ApplicationParameter.PublishNetIpAddress.Contains(@"|"))
  751. {
  752. string[] datas = ApplicationParameter.PublishNetIpAddress.Split(Convert.ToChar(@"|"));
  753. if (datas.Length > 1)
  754. {
  755. url = datas[0];
  756. encoding = datas[1];
  757. }
  758. }
  759. else
  760. {
  761. url = ApplicationParameter.PublishNetIpAddress;
  762. }
  763. if (encoding == string.Empty)
  764. {
  765. encoding = "gbk";
  766. }
  767. Encoding encode = Encoding.GetEncoding(encoding);
  768. MyWebClient MyWebClient = new MyWebClient(3*1000);
  769. MyWebClient.Headers.Add("User-Agent",
  770. "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36");
  771. MyWebClient.Credentials = CredentialCache.DefaultCredentials; //获取或设置用于向Internet资源的请求进行身份验证的网络凭据
  772. Byte[] pageData = MyWebClient.DownloadData(url); //从指定网站下载数据
  773. string pageHtml = encode.GetString(pageData); //如果获取网站页面采用的是GB2312,则 使用这句
  774. ret = parseHtml(pageHtml);
  775. if (ret != String.Empty)
  776. {
  777. return ret;
  778. }
  779. return GetNetIp();
  780. }
  781. }
  782. catch (Exception e)
  783. {
  784. if (ret == String.Empty)
  785. {
  786. GetNetIp();
  787. }
  788. }
  789. finally
  790. {
  791. if (ret == String.Empty)
  792. {
  793. GetNetIp();
  794. }
  795. }
  796. return GetNetIp();
  797. }
  798. private static string parseHtml(String pageHtml)
  799. {
  800. string ip = "";
  801. //Match m = Regex.Match(pageHtml, @"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}");
  802. Match m = Regex.Match(pageHtml, @"((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)");
  803. if (m.Success)
  804. {
  805. return m.Value;
  806. }
  807. ip = pageHtml;
  808. return ip;
  809. }
  810. #endregion
  811. }
  812. }