private void codeCoboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (dc != null) { if (dc.SelectedCodeItem != null) { if (dc.HqDict.ContainsKey(dc.SelectedCodeItem.Code)) { dc.ShowHQ = dc.HqDict[dc.SelectedCodeItem.Code]; } else { FutureHQ fh = new FutureHQ(); fh.SCode = dc.SelectedCodeItem.Code; dc.ShowHQ = fh; } ChangePrice(); } } } catch { } }
public void FutureHQ() { var channelHQ = connection.CreateModel(); channelHQ.ExchangeDeclare(exchange: G.CONFIG.FutureHQExchangeName, type: "fanout", durable: true); var consumerHQ = new EventingBasicConsumer(channelHQ); consumerHQ.Received += (model, ea) => { var body = ea.Body.ToArray(); var message = Encoding.UTF8.GetString(body.ToArray()); FutureHQ hq = Newtonsoft.Json.JsonConvert.DeserializeObject <FutureHQ>(message); OnReceiveHQ(hq); //UpdateProfit(hq); }; var queueName = channelHQ.QueueDeclare().QueueName; channelHQ.QueueBind(queue: queueName, exchange: G.CONFIG.FutureHQExchangeName, routingKey: ""); channelHQ.BasicConsume(queue: queueName, autoAck: true, consumer: consumerHQ); }
// 更新浮动盈亏数据 public static void UpdateProfit(FutureHQ hq) { string code = hq.SCode.Substring(0, hq.SCode.Length - 3); lock (hqLock) { if (G.UserDict.ContainsKey("1_" + code)) { var longAcc = G.UserDict["1_" + code]; if (longAcc.total_amount > 0) { var float_profit = (hq.NewPrice - longAcc.cost) * longAcc.total_amount * 10000; //var d = float_profit % 50; //if (Math.Abs(d) <= 10) //{ // float_profit = float_profit - d; //} //if (Math.Abs(d) >= 40) //{ // if (d > 0) // { // float_profit = float_profit + (50 - d); // } // else // { // float_profit = float_profit + (-50 - d); // } //} //float_profit = ModifyPorfit(float_profit); longAcc.float_profit = float_profit; longAcc.total_profit = longAcc.float_profit + longAcc.real_profit; longAcc.update_time = DateTime.Now; } else { longAcc.float_profit = 0; longAcc.total_profit = longAcc.float_profit + longAcc.real_profit; longAcc.update_time = DateTime.Now; } } if (G.UserDict.ContainsKey("2_" + code)) { var shortAcc = G.UserDict["2_" + code]; if (shortAcc.total_amount > 0) { var float_profit = (shortAcc.cost - hq.NewPrice) * shortAcc.total_amount * 10000; //var d = float_profit % 50; //if (Math.Abs(d) <= 10) //{ // float_profit = float_profit - d; //} //if (Math.Abs(d) >= 40) //{ // if (d > 0) // { // float_profit = float_profit + (50-d); // } // else // { // float_profit = float_profit + (-50-d); // } //} //float_profit = ModifyPorfit(float_profit); shortAcc.float_profit = float_profit; shortAcc.total_profit = shortAcc.float_profit + shortAcc.real_profit; shortAcc.update_time = DateTime.Now; } else { shortAcc.float_profit = 0; shortAcc.total_profit = shortAcc.float_profit + shortAcc.real_profit; shortAcc.update_time = DateTime.Now; } } } }