I have an outgoing POST (in Spot) from another application, and with the help of Fiddler I want to send another order opening request. I managed to take the necessary data from the original request, sign the request using HMAC256 and send it to Binance, but I get a “bad request” in the response and I don’t understand what’s wrong here. I would appreciate any help.
public static void OnBeforeResponse(Session oSession)
{
if (oSession.HTTPMethodIs("POST") && oSession.uriContains("order"))
{
String strBody = oSession.GetRequestBodyAsString();
//Price
int PriceStart = strBody.IndexOf("price=") + 6;
int PriceEND = strBody.IndexOf("&", PriceStart);
string priceStr = strBody.Substring(PriceStart, PriceEND - PriceStart);
float priceF = float.Parse(priceStr, System.Globalization.CultureInfo.InvariantCulture);
// SYMBOL
int symbolStart = strBody.IndexOf("symbol=") + 7;
int symbolend = strBody.IndexOf("BTC", symbolStart);
string symbol = strBody.Substring(symbolStart, symbolend - symbolStart);
// Quantity
int quantStart = strBody.IndexOf("quantity=") + 9;
int quantend = strBody.IndexOf("&price", quantStart);
string quant = strBody.Substring(quantStart, quantend - quantStart);
float quantity = float.Parse(quant, System.Globalization.CultureInfo.InvariantCulture) * 2;
// timestamp
decimal timestamp = Math.Round(Convert.ToDecimal(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds), 0);
//Sign
Encoding ascii = Encoding.ASCII;
string secretKey = "lfaeGkjitNwvyG2lqDueMhSAOzRFlzL73w5pKRCAvSy7YrxyTkvwKCcHBHj...";
HMACSHA256 hmac = new HMACSHA256(ascii.GetBytes(secretKey));
// string query_string_LIMIT = "symbol="+symbol+"USDT&side=BUY&type=LIMIT&timeInForce=GTC&quantity="+quantity+"&price="+priceF+"&recvWindow=5000×tamp="+timestamp+"&signature=";
string result = "symbol=" + symbol + "USDT&side=BUY&type=MARKET&quantity=" + quantity + "&recvWindow=5000×tamp=" + timestamp + "&signature=";
String signature = BitConverter.ToString(hmac.ComputeHash(ascii.GetBytes(result))).Replace("-", "");
oSession.host = "fapi.binance.com";
string resultRequest = "symbol=" + symbol + "USDT&side=BUY&type=MARKET&quantity=" + quantity + "&recvWindow=5000×tamp=" + timestamp + "&signature=" + signature;
byte[] resulByte = System.Text.Encoding.ASCII.GetBytes(resultRequest);
//oSession.utilReplaceInRequest("api/v3/order","fapi/v1/order?"+resultFin);
oSession.url = oSession.url.Replace("api/v3/order", "fapi/v1/order?" + resultRequest);
FiddlerApplication.oProxy.SendRequest(oSession.RequestHeaders, resulByte, null);
}
}