Search code examples
c#binance

Binance.Net placing order with the entire quantity


I wanted to put orders with 100% of my quantity but I don't seem to find built-in functionality in Binance.Net, so I decided to make it myself.

var balance = _client.GetAccountInfo().Data.Balances.FirstOrDefault(e => e.Asset == "TRX").Free;
var orderId = _client.PlaceOrder("TRXUSDT", OrderSide.Sell, OrderType.Limit, quantity: balance, price: 0.01460m, timeInForce: TimeInForce.GoodTillCancel);

The following code is selling 100% of my TRX quantity for USDT.

The problem is that I only have the crypto pair saved into my database (TRXUSDT) and I don't have TRX and USDT, separately. Of course, I could use substring but there are symbols with more than 3 symbols, e.g. MATICUSDT.

Yes, I could use StartsWith:

var asdf = client.GetAccountInfo().Data.Balances.Where(e => e.Asset.StartsWith("TRXUSDT".Substring(0, 3)));

This gets the first pair (TRX) but what about the second pair (USDT)? I can't think of any solution.


Solution

  • I would do that using https://www.binance.com/api/v3/exchangeInfo

    That will return an object with all the Symbols and for each Symbol it will get you detailed information, such as the BaseAsset (first pair) And QuoteAsset (second pair):

    Using a for each through the Symbol list of the exchangeinfo object you can extract detailed info of each Symbol, such as the information of each pair