public int CloseOrder(BinanceApiClient client, string side = "") { if (m_NewOrder == null) { return(-1); } var order = client.GetOrder(m_Symbol, m_NewOrder.OrderId); if (side != "" && order.Side != side) { return(1); } /*if (order.Status == "FILLED" || order.Status == "PARTIALLY_FILLED") * { * if (order.Side == "BUY") * { * client.PostNewOrder(m_Symbol, order.ExecutedQty, 0.0m, OrderSide.SELL, OrderType.MARKET); * } * else if (order.Side == "SELL") * { * client.PostNewOrder(m_Symbol, order.ExecutedQty, 0.0m, OrderSide.BUY, OrderType.MARKET); * } * } * else if (order.Status == "NEW") * { * client.CancelOrder(m_Symbol, order.OrderId); * }*/ m_NewOrder = null; return(0); }
public HMA_RESULT Engine(BinanceApiClient client) { HMA_RESULT hma = new HMA_RESULT(ENUM_TREND.NO_TREND, 0.0m); if (!client.GetServerConnection()) { return(hma); // server disconnected } var candles = client.GetCandleStick(m_Symbol, m_TimeInterval); if (candles == null) { return(hma); // candle sticks is null } try { hma = m_Hma.iHMA(candles, 1, true); if (hma.Trend == ENUM_TREND.NO_TREND) { //CloseOrder(client); m_NewOrder = null; return(hma); // No Signal } if (hma.Trend == ENUM_TREND.UP_TREND) { int result = CloseOrder(client, "SELL"); if (result == 1) { return(hma); // Buy Order Existing } m_NewOrder = client.PostNewOrder(m_Symbol, m_Quantity, 0.0m, OrderSide.BUY, OrderType.MARKET); } else if (hma.Trend == ENUM_TREND.DOWN_TREND) { int result = CloseOrder(client, "BUY"); if (result == 1) { return(hma); // SELL Order Existing } m_NewOrder = client.PostNewOrder(m_Symbol, m_Quantity, 0.0m, OrderSide.SELL, OrderType.MARKET); } return(hma); // Sumit Order } catch (Exception e) { throw e; } }
public int CloseAllOrders(BinanceApiClient client, string symbol) { var orders = client.GetCurrentOpenOrders(symbol); foreach (var order in orders) { if (order.Side == "BUY") { client.PostNewOrder(m_Symbol, order.ExecutedQty, 0.0m, OrderSide.SELL, OrderType.MARKET); } else if (order.Side == "SELL") { client.PostNewOrder(m_Symbol, order.ExecutedQty, 0.0m, OrderSide.BUY, OrderType.MARKET); } } return(0); }
static async Task TestBinance() { try { var binance = new BinanceApiClient(); // public api // signed api var orders = await binance.GetOpenOrdersAsync(); Debug.Assert(orders.Success); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void Disconnect() { //ThreadStart = false; //Thread.Sleep(1000); if (ThreadStart) { string message = "HMA Robot is running now. Please Stop Robot first"; string caption = "Warning"; MessageBoxEx(message, caption); return; } this.JOIN_BUTTON.BackColor = Color.FromArgb(200, 200, 200, 200); this.JOIN_BUTTON.Text = "JOIN"; if (this.m_BinanceApi == null) { return; } //this.m_BinanceApi.CloseUserStream(); this.m_BinanceApi = null; }
public HmaStrategy(string symbol, string strTimeInterval, int period, string applied, decimal quantity, BinanceApiClient client, Order last = null) { m_Symbol = symbol; m_TimeInterval = strTimeInterval; m_Period = period; m_Applied = applied; m_Quantity = quantity; m_Hma = new HMA(m_Period, m_Applied); try { if (last == null) { m_NewOrder = null; } else { var candles = client.GetCandleStick(m_Symbol, m_TimeInterval); if (candles == null) { m_NewOrder = null; } else { var hmaArray = m_Hma.iHMA_Array(candles); int preSignal = -1; for (int i = hmaArray.Length - 1; i >= 0; i--) { if (last.Side == "BUY") { if (hmaArray[i].Trend != ENUM_TREND.UP_TREND) { preSignal = i; break; } } else if (last.Side == "SELL") { if (hmaArray[i].Trend != ENUM_TREND.DOWN_TREND) { preSignal = i; break; } } } if (preSignal < 0 || preSignal >= hmaArray.Length) { m_NewOrder = null; } else { if (candles.ElementAt(preSignal).CloseTime >= last.Time) { m_NewOrder = null; } else { m_NewOrder = new NewOrder(); m_NewOrder.OrderId = last.OrderId; m_NewOrder.ClientOrderId = last.ClientOrderId; m_NewOrder.Symbol = symbol; m_NewOrder.TransactTime = last.Time; } } } } } catch { m_NewOrder = null; } }
public BinanceProxy(ApiInformation apiInformation) { binance = new BinanceApiClient(apiInformation.ApiKey, apiInformation.ApiSecret); this.SetPairs(GetMarkets().ToArray()); }
private void JOIN_BUTTON_Click(object sender, EventArgs e) { var Now = DateTime.Now; if (m_ExpiredDate < Now) { return; } if (Connected()) { Disconnect(); return; } if (API_KEY_TEXT.Text.Length == 0) { string message = "You did not enter a Binance API KEY. Cancel this operation?"; string caption = "Error Detected in Input"; MessageBoxEx(message, caption); return; } if (API_SECRET_TEXT.Text.Length == 0) { string message = "You did not enter a Binance API SECRET. Cancel this operation?"; string caption = "Error Detected in Input"; MessageBoxEx(message, caption); return; } if (SYMBOLS_TEXT.Text.Length == 0) { string message = "You did not enter a SYMBOLS List. Cancel this operation?"; string caption = "Error Detected in Input"; MessageBoxEx(message, caption); return; } if (this.TIME_INTERVAL_COMBO.Text.Length == 0) { string message = "You did not select TIME INTERVAL. Cancel this operation?"; string caption = "Error Detected in Input"; MessageBoxEx(message, caption); return; } this.ApiSecret = this.API_SECRET_TEXT.Text; this.ApiKey = this.API_KEY_TEXT.Text; nSymbolsCount = SplitSymbols(this.SYMBOLS_TEXT.Text); this.TimeInterval = this.TIME_INTERVAL_COMBO.Text; if (this.m_BinanceApi != null) { this.m_BinanceApi = null; } this.m_BinanceApi = new BinanceApiClient(this.ApiKey, this.ApiSecret); //DateTime date = m_BinanceApi.GetServerTime(); if (!this.m_BinanceApi.GetServerConnection()) { Disconnect(); string message = "Server Connection is failed. Please use the correct API KEY and API SECRET?"; string caption = "Error Detected in Input"; MessageBoxEx(message, caption); return; } //DateTime serverTime = this.m_BinanceApi.GetServerTime(); this.JOIN_BUTTON.BackColor = Color.FromArgb(200, 0, 255, 0); this.JOIN_BUTTON.Text = "LOG OUT"; SaveSecretInfo(); }