0

I am trying to place order on Binance.

Did everything according to documentation LINK TO DOCUMENTATION

Code :

public void PlaceOrder(string baseCurrency, string quoteCurrency, OrderType orderType, decimal quantity, decimal price, OrderSubType orderSubType)
    {
        string timestamp = GetTimestamp().ToString();
        string assetPair = baseCurrency.ToUpper() + quoteCurrency.ToUpper();

        string orderSubTypeId = "";
        if (orderSubType == OrderSubType.LimitOrder)
        {
            orderSubTypeId = "LIMIT";
        }
        if (orderSubType == OrderSubType.MarketOrder)
        {
            orderSubTypeId = "MARKET";
        }

        string type = "";
        if (orderType == OrderType.Sell)
        {
            type = "SELL";
        }
        else
        {
            type = "BUY";
        }

        string paramString = String.Format(
            "symbol={0}&side={1}&type={2}&quantity={3}&recvWindow=60000&timestamp={4}",
            assetPair, type, orderSubTypeId, quantity.ToString(), timestamp);

        string signature = Encode(paramString, secretKey);
        string url = string.Format("https://api.binance.com/api/v3/order?{0}&signature={1}", paramString, signature);

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Headers.Add("X-MBX-APIKEY", apiKey);
        request.ContentType = "application/x-www-form-urlencoded";
        request.Method = WebRequestMethods.Http.Post;
    }

string url is correct. Because, I copy-pasted it into URL and running curl command worked.

CURL :

curl -H "X-MBX-APIKEY: API_KEY_GOES_HERE" -X POST "https://api.binance.com/api/v3/order?symbol=ETHUSDT&side=SELL&type=MARKET&quantity=0.10000000&recvWindow=60000&timestamp=1583924648428&signature=SIGNATURE_GOES_HERE(signature is correct, I checked it)"

parameters passed to the method are correct because url string in code is correct. There is something wrong with request itself.

Guga Todua
  • 462
  • 2
  • 11
  • 27

0 Answers0