ApplicationParameter.cs 34 KB

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