I use wsclient and binance in play to interact。
here is the scala code
val timestamp = System.currentTimeMillis()
val t = timestamp
val params = List(
("symbol", "BNBUSDT"),
("side", "BUY"),
("type", "MARKET"),
("quantity", "1"),
("timestamp", s"$t"),
)
val queryString = params.map { case (k, v) => s"$k=$v" }.mkString("&")
// first param is secret key testnet
val sign = HmacSha256Signer.sha256("o0QYxeB76oJu2mnOHlso3X0Jc5WCcKadiAucp3gnXRj7xlGQGl9rk9LgXH29gJdK", queryString)
val signParams = ("signature", sign) :: params
val map = signParams.map(c=>c._1 -> c._2).toMap
//ws is WSClient
val future = ws.url("https://testnet.binance.vision/api/v3/order")
.withHttpHeaders(
"X-MBX-APIKEY" -> "ABjsc3SLWUOQMqbZGZ9jdDAnvg5c6AshTEQ0RQM5JgVxkdbxg8FnqwL3tkp1t2Ow", // api key just testnet
)
.post(
map
)
future.onComplete(c=>{
println(c.get.body)
println(c.get.status)
})
It return
{"code":-1022,"msg":"Signature for this request is not valid."}
I use java OkHttpClient is correct。
The input content is the same, and the signature results of scala and Java are the same, so I wonder if there is something I don’t know about wsclient. Is there an expert who knows it? Help me, thank you