POST encripted request with JSON body on R -


i trying use r post encrypted request api.

specifically /v3/orders/ request.

it requires use of api key , secret, increasing nonce.

using openssl, jsonlite , httr libraries:

the body has json encoded:

book<-"btc_eth" side<-"sell" major<-"0.1" price<-"100" type<-"limit"  payload<-tojson(data.frame(book=book,side=side,major=major,price=price,type=type)) 

it requires authorization header constructed sha256 encrypted signature.

n<-nonce() # "1503033312"  method<-"post"  path<-"/v3/orders/"  signature<-sha256(paste0(n,method,path,payload),secret)  header<-paste0("bitso ",key,":",n,":",signature) 

finally request should this:

url<-"https://api.bitso.com/v3/orders/"  r<-post(url, body = payload, add_headers(authorization=header)) 

i have been able post requests empty payload api before, call sends unsupported media type error, way i'm json encoding paylod causing this.

there's ruby , php examples on how place request here.

as haven't got key try, answer case once face — might want change little bit json call. tojson puts bracket @ each side of call. need remove them :

# go payload<- jsonlite::tojson(data.frame(book=book,side=side,major=major,price=price,type=type)) payload [{"book":"btc_eth","side":"sell","major":"0.1","price":"100","type":"limit"}]   # payload <- gsub("\\[|\\]", "", payload) payload {"book":"btc_eth","side":"sell","major":"0.1","price":"100","type":"limit"} 

let me know if works,

best,

colin


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -