void OnReceiveQuotes(object sender, EventHandler.XingAPI.Quotes e) { if (int.TryParse(e.Time, out int time) && (time < 090007 && time > 045959) == false && (time > 153459 && time < 180000) == false && string.IsNullOrEmpty(API.Classification) == false) { double[] bp = new double[] { e.Price[e.Price.Length - 3], e.Price[e.Price.Length - 4], e.Price[e.Price.Length - 5] }, sp = new double[] { e.Price[2], e.Price[3], e.Price[4] }; API.MaxAmount = specify.Assets / ((API.Classification.Equals(buy) ? bp[2] : -sp[2]) * Const.TransactionMultiplier * specify.MarginRate); foreach (var kv in API.BuyOrder) { if (Array.Exists(bp, o => o == kv.Value) == false && API.OnReceiveBalance && API.BuyOrder.ContainsKey(kv.Key) && SendClearingOrder(kv.Key)) { return; } } foreach (var kv in API.SellOrder) { if (Array.Exists(sp, o => o == kv.Value) == false && API.OnReceiveBalance && API.SellOrder.ContainsKey(kv.Key) && SendClearingOrder(kv.Key)) { return; } } } else if (time > 153559 && time < 153959 && RollOver) { RollOver = false; SendLiquidationOrder(); } else if (specify.Time == 1440 && time > 153959 && time < 154459 && Assets > 0 && Math.Abs(API.MaxAmount) > 0) { SendLiquidationOrder(GetUserAssets((long)specify.Assets)); } }
void OnReceiveQuotes(object sender, EventHandler.XingAPI.Quotes e) { if (strategy && int.TryParse(e.Time, out int time) && (time > 153459 && time < 180000) == false) { bool accumulate = e.Price[4] == Sell && e.Price[5] == Buy; if (API.OnReceiveBalance && API.WindingClass.Equals(string.Empty) == false) { SendNewOrder(e.Price, API.WindingClass); } if (API.OnReceiveBalance && API.Classification.Equals(string.Empty) == false) { SendNewOrder(e.Price, API.Classification); } if (API.OnReceiveBalance && accumulate) { if (e.Price[4] == Sell && e.Price[5] == Buy) { OnDetermineTheTrend(AccumulateSell += e.Sell, AccumulateBuy += e.Buy, e.Price[4], e.Price[5]); } else if (Sell > e.Price[4] || Buy > e.Price[5]) { OnDetermineTheTrend(1, 0, e.Price[4], e.Price[5]); } else if (Sell < e.Price[4] || Buy < e.Price[5]) { OnDetermineTheTrend(0, 1, e.Price[4], e.Price[5]); } } if (accumulate == false) { AccumulateSell = 0; AccumulateBuy = 0; Sell = e.Price[4]; Buy = e.Price[5]; } } else if (strategy && API.Trend.Count > 0 && int.TryParse(e.Time, out int roll) && roll > 153459 && roll < 154500) { int over = 0; foreach (var kv in API.Trend) { over += kv.Value.Contains("-") ? -1 : 1; } API.Trend.Clear(); if (over != 0) { SendRollOverOrder(over); } } }
public void OnReceiveQuotes(object sender, EventHandler.XingAPI.Quotes e) => BeginInvoke(new Action(() => { var time = DateTime.ParseExact(e.Time, "HHmmss", null).ToString("HH : mm : ss"); if (quotes10.ForeColor.Equals(e.Color) == false) { quotes10.ForeColor = e.Color; } if (quotes10.Text.Equals(time) == false) { quotes10.Text = time; } for (int i = 0; i < e.Price.Length; i++) { var temp = string.Concat("quotes", i).FindByName <Label>(this); var param = e.Price[i].ToString("N2"); var temporary = string.Concat("order", i).FindByName <Label>(this); if (temp.Text.Equals(param) == false) { temp.Text = param; } if (e.SellOrder != null && i < 5 && e.SellOrder.ContainsValue(e.Price[i])) { var number = int.Parse(e.SellOrder.First(o => o.Value == e.Price[i]).Key).ToString(); if (temporary.Text.Equals(number)) { continue; } temporary.Text = number; } else if (e.BuyOrder != null && i > 4 && e.BuyOrder.ContainsValue(e.Price[i])) { var number = int.Parse(e.BuyOrder.First(o => o.Value == e.Price[i]).Key).ToString(); if (temporary.Text.Equals(number)) { continue; } temporary.Text = number; } else { temporary.Text = string.Empty; } } Application.DoEvents(); }));
void OnReceiveQuotes(object sender, EventHandler.XingAPI.Quotes e) { if (int.TryParse(e.Time, out int time) && (time < 090007 && time > 045959) == false && (time > 153459 && time < 180000) == false && string.IsNullOrEmpty(API.Classification) == false) { string classification = API.Classification, price; var check = classification.Equals(buy); var max = Max(specify.Assets / ((check ? e.Price[5] : e.Price[4]) * Const.TransactionMultiplier * specify.MarginRate), classification); double[] sp = new double[10], bp = new double[10]; API.MaxAmount = max * (check ? 1 : -1); for (int i = 0; i < 10; i++) { if (double.TryParse((e.Price[5] - Const.ErrorRate * (9 - i)).ToString("F2"), out double bt) && double.TryParse((e.Price[4] + Const.ErrorRate * (9 - i)).ToString("F2"), out double st)) { sp[i] = st; bp[i] = bt; } } if (API.AvgPurchase != null && API.AvgPurchase.Equals(avg) == false && API.OnReceiveBalance && API.Quantity != 0) { price = GetExactPrice(API.AvgPurchase); switch (classification) { case sell: if (API.Quantity < 0) { if (API.BuyOrder.Count == 0 && max < 1 - API.Quantity && ForTheLiquidationOfSellOrder(price, bp)) { return; } if (API.BuyOrder.Count > 0 && ForTheLiquidationOfSellOrder(bp)) { return; } if (API.SellOrder.Count > 0 && SetCorrectionSellOrder(price, sp[sp.Length - 1])) { return; } } else if (API.BuyOrder.Count > 1 && SetBuyDecentralize(bp[bp.Length - 1])) { return; } break; case buy: if (API.Quantity > 0) { if (API.SellOrder.Count == 0 && max < API.Quantity - 1 && ForTheLiquidationOfBuyOrder(price, sp)) { return; } if (API.SellOrder.Count > 0 && ForTheLiquidationOfBuyOrder(sp)) { return; } if (API.BuyOrder.Count > 0 && SetCorrectionBuyOrder(price, bp[bp.Length - 1])) { return; } } else if (API.SellOrder.Count > 1 && SetSellDecentralize(sp[sp.Length - 1])) { return; } break; } } foreach (var kv in check ? API.BuyOrder : API.SellOrder) { if (Array.Exists(check ? bp : sp, o => o == kv.Value) == false && API.OnReceiveBalance && (check ? API.BuyOrder.ContainsKey(kv.Key) : API.SellOrder.ContainsKey(kv.Key)) && SendClearingOrder(kv.Key)) { return; } } if (API.OnReceiveBalance && SendNewOrder(e.Price, classification)) { return; } } else if (time > 153559 && time < 154459 && RollOver) { RollOver = false; SendLiquidationOrder(); } }
void OnReceiveQuotes(object sender, EventHandler.XingAPI.Quotes e) { if (int.TryParse(e.Time, out int time) && (time > 153459 && time < 180000) == false && string.IsNullOrEmpty(API.Classification) == false) { string classification = API.Classification; var check = classification.Equals(buy); var max = Max(specify.Assets / ((check ? e.Price[5] : e.Price[4]) * Const.TransactionMultiplier * Const.MarginRate200402), classification); int i, being = (int)max; double[] sp = new double[5], bp = new double[5]; API.MaxAmount = max * (classification.Equals(buy) ? 1 : -1); for (i = 0; i < 5; i++) { sp[i] = e.Price[i]; bp[i] = e.Price[9 - i]; } switch (classification) { case sell: if (API.OnReceiveBalance && API.Quantity < 0 && API.AvgPurchase != null && API.AvgPurchase.Equals(avg) == false) { var price = GetExactPrice(API.AvgPurchase); switch (API.BuyOrder.Count) { case 0: if (API.OnReceiveBalance && price.Equals(Price) == false) { SendNewOrder(price, buy); Price = price; return; } else if (API.OnReceiveBalance && max < Math.Abs(API.Quantity)) { SendNewOrder(e.Price, max, buy); return; } break; case 1: var number = API.BuyOrder.First().Key; if (API.BuyOrder.TryGetValue(number, out double cbp)) { if (cbp.ToString("F2").Equals(price) == false && API.OnReceiveBalance) { SendCorrectionOrder(price, number); return; } else if (Array.Exists(bp, o => o == cbp) == false && API.OnReceiveBalance) { SendClearingOrder(number); return; } } break; default: var order = API.BuyOrder.First(f => f.Value == API.BuyOrder.Max(o => o.Value)).Key; if (API.OnReceiveBalance && API.BuyOrder.ContainsKey(order)) { SendClearingOrder(order); return; } break; } } for (i = 4; i > -1; i--) { if (being + API.Quantity <= i && API.SellOrder.ContainsValue(sp[i])) { var number = API.SellOrder.First(o => o.Value == API.SellOrder.Min(m => m.Value)).Key; var price = API.SellOrder.Max(o => o.Value) + Const.ErrorRate; if (API.OnReceiveBalance && API.SellOrder.ContainsKey(number)) { SendCorrectionOrder(price.ToString("F2"), number); return; } } } break; case buy: if (API.OnReceiveBalance && API.Quantity > 0 && API.AvgPurchase != null && API.AvgPurchase.Equals(avg) == false) { var price = GetExactPrice(API.AvgPurchase); switch (API.SellOrder.Count) { case 0: if (API.OnReceiveBalance && (price.Equals(Price) == false)) { SendNewOrder(price, sell); Price = price; return; } else if (API.OnReceiveBalance && max < API.Quantity) { SendNewOrder(e.Price, max, sell); return; } break; case 1: var number = API.SellOrder.First().Key; if (API.SellOrder.TryGetValue(number, out double csp)) { if (csp.ToString("F2").Equals(price) == false && API.OnReceiveBalance) { SendCorrectionOrder(price, number); return; } else if (Array.Exists(sp, o => o == csp) == false && API.OnReceiveBalance) { SendClearingOrder(number); return; } } break; default: var order = API.SellOrder.First(f => f.Value == API.SellOrder.Min(o => o.Value)).Key; if (API.OnReceiveBalance && API.SellOrder.ContainsKey(order)) { SendClearingOrder(order); return; } break; } } for (i = 4; i > -1; i--) { if (being - API.Quantity <= i && API.BuyOrder.ContainsValue(bp[i])) { var number = API.BuyOrder.First(o => o.Value == API.BuyOrder.Max(m => m.Value)).Key; var price = API.BuyOrder.Min(o => o.Value) - Const.ErrorRate; if (API.OnReceiveBalance && API.BuyOrder.ContainsKey(number)) { SendCorrectionOrder(price.ToString("F2"), number); return; } } } break; } foreach (var kv in check ? API.BuyOrder : API.SellOrder) { if (Array.Exists(check ? bp : sp, o => o == kv.Value) == false && API.OnReceiveBalance && (check ? API.BuyOrder.ContainsKey(kv.Key) : API.SellOrder.ContainsKey(kv.Key))) { SendClearingOrder(kv.Key); return; } } if (API.OnReceiveBalance) { SendNewOrder(e.Price, max, classification); } } }