akka http - How to call poloniex trading api in scala -


my code following.

import org.apache.commons.codec.binary.hex import akka.actor.actorsystem import akka.http.scaladsl.http import akka.http.scaladsl.model.headers.rawheader import akka.http.scaladsl.model._ import akka.stream.actormaterializer import akka.util.bytestring import javax.crypto.spec.secretkeyspec import javax.crypto.mac  import scala.concurrent.executioncontext.implicits.global import scala.concurrent.future  class poloniex {   def post(postdata: string): future[httpresponse] = {     val command = "returnbalances"     val nonce = (system.currenttimemillis / 1000).tostring     val postdata = s"nonce=$nonce&command=$command"     val headers: scala.collection.immutable.seq[httpheader] = scala.collection.immutable.seq(       rawheader("key", api_key),       rawheader("sign", hmacsha512(postdata))     )      val entity = httpentity(postdata)      {       r <- http().singlerequest(httprequest(httpmethods.post, trading_url, headers, entity))     } yield r   }    private def hmacsha512(postdata: string): string = {     val secret = new secretkeyspec(api_secret.getbytes, hmac_sha512)     val mac = mac.getinstance(hmac_sha512)     mac.init(secret)     val result: array[byte] = mac.dofinal(postdata.getbytes)     new string(hex.encodehex(result))   } } 

i

{"error":"invalid command."} 

but couldn't find why error. can find reason why error?

the api documentation here. https://poloniex.com/support/api/

thanks.

the content type of request must application/x-www-form-urlencoded. set this, use formdata:

val entity =   formdata(map("nonce" -> nonce, "command" -> command)).toentity(httpcharsets.`utf-8`) 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -