"{\"code\":-1022,\"msg\":\"Signature for this request is not valid.\"}"

Hi. i try to send margin order in C#, And it returns me “”{“code”:-1022,“msg”:“Signature for this request is not valid.”}""
Secret key is works. I can read information about marin account.
public string GetMarginAccountInfo()
{
long timeStamp = GetTimestamp();
RestClient Client = new RestClient(“https://api.binance.com”);

        var request = new RestRequest("/sapi/v1/margin/account");
        string ApiKey = _strApiKey;
        request.AddHeader("X-MBX-APIKEY", ApiKey);
        request.AddParameter("timestamp", timeStamp, ParameterType.QueryString);
        request.AddParameter("recvWindow", 60000, ParameterType.QueryString);
        string strsignature = CreateSignature(request.Parameters, _strSecretApiKey);
        request.AddParameter("signature", strsignature, ParameterType.QueryString);
        return Client.Get(request).Content;
    }

public static string CreateSignature(List parameters, string secret)
{
var queryString = “”;
if (parameters.Count > 0)
{
foreach (var item in parameters)
{
if (item.Name != “X-MBX-APIKEY”)
queryString += $"{item.Name}={item.Value}&";
}
queryString = queryString.Substring(0, queryString.Length - 1);
}

        byte[] keyBytes = Encoding.UTF8.GetBytes(secret);
        byte[] queryStringBytes = Encoding.UTF8.GetBytes(queryString);
        HMACSHA256 hmacsha256 = new HMACSHA256(keyBytes);

        byte[] bytes = hmacsha256.ComputeHash(queryStringBytes);

        return BitConverter.ToString(bytes).Replace("-", "").ToLower();
    }

but when I’ll try to send order in my margin account, a get error.

private string sendOderMargin(bool bShort, string strSymbol, double dTotalSum, double dPrice )
        {
            double dQuantity = Math.Round(dTotalSum / dPrice,5);


            long timeStamp = GetTimestamp();
            RestClient Client = new RestClient("https://api.binance.com");
            string strSide = "BUY";
            if (bShort)
            {
                strSide = "SELL";
            }
            
            var request = new RestRequest("/sapi/v1/margin/order");
            string ApiKey = _strApiKey;
            request.AddHeader("X-MBX-APIKEY", ApiKey);
            request.AddParameter("symbol", strSymbol, ParameterType.QueryString);
            request.AddParameter("isIsolated", false);
            request.AddParameter("side", strSide);
            request.AddParameter("type", "MARKET");
            request.AddParameter("quantity", Convert.ToString(dQuantity));
            request.AddParameter("price", Convert.ToString(dPrice));
            //request.AddParameter("quoteOrderQty", "0.00000000");

            request.AddParameter("timestamp", timeStamp, ParameterType.QueryString);
            request.AddParameter("recvWindow", 60000, ParameterType.QueryString);
            string strsignature = CreateSignature(request.Parameters, _strSecretApiKey);
            request.AddParameter("signature", strsignature, ParameterType.QueryString);
           string strRes =  Client.Post(request).Content;
            return strRes;
        }

Hi.
Can you check if the string of request.Parameters put into CreateSignature function has the same order as the final query string?
Please also check this post if the point above is not the root cause. FAQ: Signature for this request is not valid.

See this link: https://github.com/binance/binance-signature-examples