daroczig / binancer

An R client to the Public Rest API for Binance.
https://daroczig.github.io/binancer
53 stars 57 forks source link

Where to put API Key & Secret Key Variables #5

Closed canholyavkin closed 6 years ago

canholyavkin commented 6 years ago

Firstly, I want to thank you for sharing this script.

However, I couldn't able to run the script. Actually, I couldn't find where to put the API Key & Secret Keys and which function should I run first. Could you please provide a bit more detail in Readme?

Thank you.

YsoSirius commented 6 years ago

I am also not sure how the current code is intented and should run like that. I got it working, but i had to adapt the "binance_credentials" function, so that it assignes the 2 values to global variables after initializing credentials .

credentials <- list()
binance_credentials <- function(key, secret) {
    credentials$key <<- key
    credentials$secret <<- key
}

So if you insert key and secret here and run it again, it should work.

key <- "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
secret <-  "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
binance_credentials(key, secret)
binance_account()

But i would try to avoid using <<- and assigning to the global environment, so I would actually adapt the functions a bit, so that we merge all the credential functions in one, which returns an object that is further used. Im not so sure right now, what would be the most elegant way. But im definitly gonna check it out a bit more.

@cholyavkin: Do you attempt to create a CRAN-package with this? The formatting looks a lot like it ;)

YsoSirius commented 6 years ago

Ok, i missed the zzz-file. The credentials object is defined here. To gt it running, you have to build it to a package. It runs then without any modifications to the code ;) So all good!

canholyavkin commented 6 years ago

@YsoSirius Thank you. I've compiled it as package, and it is solved.

daroczig commented 6 years ago

Sorry guys, unfortunately, I did not get any notifications on these tickets -- fixing that issue now.

FTR no need to mess around with <<-, the binance_credentials function is part of the package and should get you working:

library(binancer)
binance_credentials(key = ..., secret = ...)
balances <- binance_balances(threshold = -1, usdt = TRUE)