Code Monkey home page Code Monkey logo

rgdax's Introduction

rgdax 1.2.3

Build Status CRAN_Status_Badge

Note:

The version less than 1.1.0 are now broken and unsupported. Coinbase had support for the old GDAX API's only till the end of 2018. Version 1.1 and above WILL break the previous implementations and hence, it is recommended that all users should test this extensively with their existing applications (bulit pre-March 2021) and make changes as necessary.

This package is inspired by official and unofficial wrappers for Coinbase Pro API. Please read through the api docs to gain a better understanding of how each end point is likely to work.

There are two main groups of api end points.

Public: All functions belonging to this group start with public_ and can be used without any authentication.

Auth: This category of functions will require API Key, API Secret and Passphrase to connect successfully to the account. To get your api keys, refer to how to create Coinbase Pro api keys. The behavior of the functions will also depend upon what kind of access (view, transfer or trade) the api keys have.

What is New in this version

News

Supported Functions

Complete List of Supported Public Functions with Coinbase Pro end point mapping:

# function public mapping
01 candles historic rates
02 daystats 24hr stats
03 info currencies & products
04 orderbook product orderbook
05 ticker product ticker
06 time time
07 trades trades

Complete List of Supported Auth Functions with Coinbase Pro end point mapping:

Accounts

# function auth mapping
08 accounts list accounts
09 account an account
10 account_hist account history
11 holds holds

Orders

# function auth mapping
12 add_order place a new order
13 cancel_order cancel an order & cancel all
14 list_orders list order
XX PENDING get an order

Others

# function auth mapping
15 fills list fills
16 pymt_methods list payment methods

Apart from these two categories, the library also contains a few internal functions which are used across the public and the auth functions:

  1. parse_response
  2. auth

Currently Unsupported Functions - AUTH

# function auth mapping
XX pending exchange limits
XX pending list deposits
XX pending single deposit
XX pending deposut to payment method
XX pending deposit from coinbase
XX pending generate deposit address
XX pending list withdrawl
XX pending single withdrawl
XX pending cancelled withdrawl
XX pending withdraw to payment method
XX pending withdraw to coinbase
XX pending withdraw to address
XX pending withdrawal fee
XX pending create conversion
XX pending list payment methods
XX pending list coinbase accounts
XX pending current fee
XX pending create a new report
XX pending report status
XX pending list profiles
XX pending get a profile
XX pending transfer funds across profiles

Currently Unsupported Functions - PUBLIC

# function mapping
XX pending get a single product

Apart from the above listed pending functions, the current version does not support the following capabilities:

  1. Pagination

How to install:

From CRAN

library(rgdax)

This is same as installing master branch from github.

From Github dev

library(devtools)
install_github("DheerajAgarwal/rgdax", ref="dev")

URLs

rgdax CRAN

CRAN codebase

DEV codebase

License:

MIT

DISCLAIMER Use at your own risk.

rgdax's People

Contributors

angelaponte avatar dheerajagarwal avatar skivalov avatar wittec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rgdax's Issues

/fills suggestion.

When I perform a GET /fills I get an uneven nested list. Your code grabs specific list elements to overcome this. What about something like below which is what I used before seeing your package (I have my own private). This way you get the complete response. Just my $0.02 though. If you need a contributor I would be happy to spend some time on your package if you need it. :)

#' @title GET Account Fills Info
#'
#' @description Requires authentication, will retreive account information including profile-id, currency balances, currency availability (differs from balances if there are any holds), and hold amounts.
#'
#' @param apiKey Your API key from the gdax account page
#' @param secret Your API secret from the gdax account page
#' @param passphrase your API passphrase from the gdax account page
#' @param product_id optional market product id.  String must be one of "LTC-EUR", "LTC-BTC", "LTC-USD", "ETH-USD", "ETH-EUR", "ETH-BTC", "BTC-USD", "BTC-EUR", or "BTC-GBP".
#' @export
#' @seealso \url{https://docs.gdax.com/}
#' @return response a data frame of account information including available balances.
#' @examples  \dontrun{
#' api.key <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
#' secret <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
#' passphrase <- "xxxxxxxxxxx"
#' actInfo<-gdaxFills(api.key,secret,passphrase)
#' }
gdaxFills<-function(apiKey,secret,passphrase,product_id){
  if(missing(product_id)){product_id<-'*'}

  # Libs
  require(httr)
  require(RCurl)
  
  # Endpoint
  apiURL <- "https://api.gdax.com"
  reqURL <- "/fills"
  meth <- "GET"
  
  # Official timestamp
  timestamp<-as.character(getTime()[1,2])
  
  # Encode Info
  key <- base64Decode(secret, mode="raw")
  what <- paste0(timestamp, toupper(meth), reqURL)
  
  signa <- base64Encode(hmac(key, what, algo="sha256", raw=TRUE))
  
  # https://stackoverflow.com/questions/27153979/converting-nested-list-unequal-length-to-data-frame
  res <- GET(paste0(apiURL,reqURL), 
             add_headers('CB-ACCESS-KEY'=apiKey,
                         'CB-ACCESS-SIGN'=signa,
                         'CB-ACCESS-TIMESTAMP'=timestamp,
                         'CB-ACCESS-PASSPHRASE'=passphrase,
                         'Content-Type'='application/json'))
  print(http_status(res)$message)
  lst<-content(res)
  indx <- sapply(lst, length)
  res <- as.data.frame(do.call(rbind,lapply(lst, `length<-`,
                                            max(indx))))
  
  colnames(res) <- names(lst[[which.max(indx)]])
  res<-res[grepl(product_id,sapply(res$product_id,'[')),]
  return(res)
  
}

The interesting bit is arranging the info into a df filled w/ NULL if needed and then using grepl to perform a subset based on product. Again, just my $0.02 and trying to help!

error with some public_ functions

Hi,

Working with rgdax_1.2.1 on Rstudio with the below config:
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

The majority of the rgdax functions work fine, but the following are creating an error (shown below):
public_daystats()
public_tickers()

Example call and the error given:

public_ticker(product_id = "BTC-USD")
Error in build_url(utils::modifyList(old, new)) :
is.character(query) is not TRUE

The same error is shown for both of these functions no matter the coin pair input..

Many thanks with any help on this.

Chris.

The public_orderbook function does not appear to be passing the level to the CBP API

In version 1.1.0, using the public_orderbook for BTC-USD and level = 1, yields a tibble with 1 row, 7 columns. This is to be expected. Using level 2 yields the same output. I believe the issue is in the parse_response function. It doesn't seem to be passing the query parameter to the API. manually running httr::GET("https://api.pro.coinbase.com/products/BTC-USD/book?level=2") then passing the response into content() yields the expected 50 row by 7 columns.

add_order Forbidden

I am trying to use the add_order() function. add_order(api.key = "api.key", secret = "secret", passphrase = "passphrase", product_id = "ETH-USD", type = "limit", side = "b", price = 4200, size = 69)

This returns:

[1] "An order with Order id: was successfully created."
message
1 Forbidden

I am running macOS Big Sur Version 11.6. Running rgdax 1.2.1.

Any suggestions?

public_candles() error in timing inputs

I am trying to collect some historical bitcoin daily data via Coinbase API using 'rgdax' package's "public_candles" command.
Thus, I tried the following:

public_candles(product_id = "BTC-USD", start = 2018-01-01, end = 2018-02-01,granularity = 86400)

However, I keep on getting errors as such:

Error in parse_response(path = req.url, query = list(start = start, end = end, :
start must be before end

I tried many different permutations of dates but even though the start date is definitely before the end date, I keep getting this same error unfortunately.

May I kindly ask for this help ASAP please?

Thanks and question about the future

Thank you for putting the time into building this package and sharing it with us. The public_candles function has been especially useful to me these last 6 months.

Do we expect that the CRAN package will no longer work as of January 1, 2019, due to Coinbase deprecation of the GDAX API endpoints?

If so, is it a simple URL change in the code to the new Coinbase Pro API endpoint or is the fix more involved?

Thanks again!

public_candles() not passing start/end times

The public_candles() function is not parsing additional query parameters correctly.

When trying to specify start, end, or granularity, it returns

Error in UseMethod("as.request") : no applicable method for 'as.request' applied to an object of class "character"

Looking at the code, it looks like the issue is in the internal function parse_response().

Comparing to public_orderbook() which is passing the level parameter as expected, you have

response <- parse_response(path = req.url, query = list(level = level))

as opposed to

response <- parse_response(path = req.url, query = c(start = start, end = end, granularity = granularity))

I suspect the issue is the function parse_response() is being passed a character vector due to the c() funtion rather than the list() function, which is causing the request to fail. However it also appears public_orderbook() is not parsing the levels parameter properly either, as it only returns one line from the orderbook regardless of the level requested.

Trading is disabled

Hello,
all my trade are now disabled. Don't you think there is a problem with the package since coinbase pro and coinbase are in evolution?
Best regards and thank you so lot for your work!

Suggestions for improvement

Hi Dheeraj,

Thank you again for this great package! I've been using it quite a lot recently and have a few suggestions for improvement:

  • Adding the "time in force" argument to the add_order function for limit orders (good till canceled GTC, good till time GTT, immediate or cancel IOC, and fill or kill FOK). This would helps with the flow in the buying and selling loops.
  • Adding the "funds" argument to the add_order function for market orders. This would be super helpful in order to use the full amount in the balance to buy. At the moment, "size" needs to be specified which requires a workaround in the code and leaves room for errors.

Thanks a lot!

Emilio

URL issue?

Running into the following error:

Error in rawToChar(getURLContent(url = url, curl = getCurlHandle(useragent = "R"),  : 
  argument 'x' must be a raw vector

I read through the auth.R function which seems to be where the error is coming from but I can't figure out why it's the case.

Timeout Error

Hi,
I am running a simple shiny app and I periodically get a timeout error every once in a while (average 1 per day). I make about 3-10 api calls every 5 seconds, so it clearly isn't often, but it only needs to happen once to kill the app from running. Is there a timeout value that can be increases on any one of the api requests (or maybe a trycatch could work some how)? I noticed that the httr package has an option to create the timeout value, but I am not too sure if you are using that for this package or not. Eitherway, let me know!

public_orderbook() issue

Hi @DheerajAgarwal,

thanks for your excellent work on the development of this code. It has been super useful to better manage crypto through R.

I am very new to the package and somewhat to R.

I have been using the function public_orderbook() for the last month or so, but in the last few days it started to show the following error:

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 1, 0

I tried to re-install the package, but the error persists. My current version is rgdax_1.2.1.

Please let m know if you have any directions and I appreciate the help.

LD

Still receiving error related to rawToChar

I have downloaded the latest version of rgdax.

library(devtools)
install_github("DheerajAgarwal/rgdax", ref="dev")

But I am still receive this error that has been discussed in the past in response to the accounts() function:

Error in rawToChar(getURLContent(url = url, curl = getCurlHandle(useragent = "R"), :
argument 'x' must be a raw vector

My understanding is that the fix for this has been incorporated into the latest version on GitHub, so this should not happen any longer.

Any suggestions?

Thanks!

add_order not working

This package is great, thank you for sharing it!
Please can you help? I keep getting "Error: Bad Request" when trying to do a market trade with the 'add_order' function. I think the authentication is working ok, because cancel_order works. Please could you give me an example that works for you to check I am using it right?
Cheers
Simon

parse_response query argument

getting error when running public_info():

Error in build_url(utils::modifyList(old, new)) : is.character(query) is not TRUE

This error goes away and the public_info() starts working appropriately for me when I set query = NA_character instead of NA inside of the parse_response() function.

Using R 4.1.0 & rgdax 1.2.1 on Mac

STOP Orders

Great work with this package. When do you think you'll code in the ability to enter STOP orders? That would be awesome!

Thanks again

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.