Skip to content

Commit

Permalink
New version + updated tests, docs + refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vnegi10 committed Jul 16, 2021
1 parent 3c4bb9f commit c8d9a4f
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CoinbaseProExchange"
uuid = "06c3450d-869c-4596-88b4-6f9fb82f72bd"
authors = ["Vikas Negi <[email protected]>"]
version = "0.1.2"
version = "0.1.3"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
34 changes: 4 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## CoinbaseProExchange
# CoinbaseProExchange.jl

[![Build status (Github Actions)](https://github.com/vnegi10/CoinbaseProExchange.jl/workflows/CI/badge.svg)](https://github.com/vnegi10/CoinbaseProExchange.jl/actions)

Expand All @@ -17,7 +17,7 @@ This package provides an unofficial Julia wrapper for the Coinbase Pro REST API.

Public endpoints can be accessed without a Coinbase Pro account.

In order to use the private endpoints, you will need to register and create an account on [Coinbase](https://www.coinbase.com/). Please note that Coinbase Pro account is separate froom Coinbase, but they use the same login credentials. More information about the API can be found [here](https://docs.pro.coinbase.com/#api)
In order to use the private endpoints, you will need to register and create an account on [Coinbase](https://www.coinbase.com/). Please note that Coinbase Pro account is separate from Coinbase, but they use the same login credentials. More information about the API can be found [here.](https://docs.pro.coinbase.com/#api)

## API key permissions

Expand All @@ -33,11 +33,7 @@ Some examples of available functions along with the expected output are shown be
* Press '?' to enter the help mode
* Type function name and press enter

### Available functions

show_historical_data, show_server_time, show_all_products, show_latest_trades, show_product_data, show_all_accounts, show_account_info, place_market_order, place_limit_order, show_open_orders, show_single_order, show_exchange_limits, show_fills, cancel_order, cancel_all_orders

### Public endpoints (Coinbase account is not necessary)
## Public endpoints (Coinbase account is not necessary)

```julia
julia> show_server_time("iso")
Expand All @@ -62,7 +58,7 @@ julia> show_historical_data("ETH-EUR", 3600)

**Check docs for more examples:** [![](https://img.shields.io/badge/docs-stable-blue.svg)](https://vnegi10.github.io/CoinbaseProExchange.jl/stable)

### Private endpoints (Coinbase Pro account + API keys are needed)
## Private endpoints (Coinbase Pro account + API keys are needed)

Obtain your API key, API secret and passphrase from your Coinbase Pro account. Create an object **user_data** with type **UserInfo** to store your API data, as shown below:

Expand Down Expand Up @@ -93,28 +89,6 @@ Dict{String, Any} with 14 entries:
"type" => "market"
```
```julia
julia> place_limit_order("sell", "BTC-EUR", 0.0005, 30000, user_data)

[ Info: Order placed
Dict{String, Any} with 15 entries:
"created_at" => "2021-07-04T21:59:11.083132Z"
"price" => "30000"
"stp" => "dc"
"product_id" => "BTC-EUR"
"settled" => false
"status" => "pending"
"id" => "cae9158e-1660-448e-bd9a-d368ce3fdc8a"
"executed_value" => "0"
"post_only" => false
"size" => "0.0005"
"filled_size" => "0"
"side" => "sell"
"time_in_force" => "GTC"
"fill_fees" => "0"
"type" => "limit"
```
**Check docs for more examples:** [![](https://img.shields.io/badge/docs-stable-blue.svg)](https://vnegi10.github.io/CoinbaseProExchange.jl/stable)
Expand Down
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Documenter
using CoinbaseProExchange

makedocs(
sitename = "CoinbaseProExchange",
sitename = "CoinbaseProExchange.jl",
format = Documenter.HTML(),
modules = [CoinbaseProExchange]
)
Expand Down
42 changes: 31 additions & 11 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,61 @@
# CoinbaseProExchange.jl
# User Guide
---

### Available functions
## Overview
CoinbaseProExchange.jl provides a Julia wrapper for the Coinbase Pro REST API. Available endpoints are implemented in the form of callable functions. Depending on the operation, a function can return data (either as a DataFrame or Dict) or the associated HTTP response (Dict).

#### Public endpoints (Coinbase account is not necessary)
## Available functions
```@index
```

## Public endpoints (Coinbase Pro account is not necessary)
```@docs
show_server_time(time_type::String)
show_server_time(time_type::String="iso")
show_historical_data(pair::String, interval::Int64)
show_historical_data(pair::String, interval::Int64=300)
show_all_products(currency::String)
show_all_products(currency::String="USD")
show_latest_trades(pair::String)
show_product_data(pair::String, endpoint::String)
show_product_data(pair::String, endpoint::String="24hr stats")
```

#### Private endpoints (Coinbase Pro account + API keys are needed)
## Private endpoints (Coinbase Pro account + API keys are needed)

### API key should have "trade" or "view" permission
```@docs
show_all_accounts(user_data::UserInfo, currencies::Vector{String})
show_account_info(user_data::UserInfo, currency::String, info_type::String)
show_exchange_limits(user_data::UserInfo, currency::String)
show_fills(user_data::UserInfo, pair::String)
show_transfers(user_data::UserInfo, transfer_type::String="deposit")
show_fees(user_data::UserInfo)
show_profiles(user_data::UserInfo)
```

### API key should have "trade" permission
```@docs
place_market_order(side::String, pair::String, amount::IntOrFloat, amount_type::String, user_data::UserInfo)
place_limit_order(side::String, pair::String, amount::IntOrFloat, price::IntOrFloat, user_data::UserInfo)
show_open_orders(user_data::UserInfo)
show_single_order(order_ID::String, user_data::UserInfo)
cancel_order(order_id::String, user_data::UserInfo)
cancel_all_orders(user_data::UserInfo)
```

show_exchange_limits(user_data::UserInfo, currency::String)

show_fills(user_data::UserInfo, pair::String)
```



Expand Down
4 changes: 3 additions & 1 deletion src/CoinbaseProExchange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export show_historical_data, show_server_time, show_all_products,
show_latest_trades, show_product_data, show_all_accounts,
show_account_info, place_market_order, place_limit_order,
show_open_orders, show_single_order, show_exchange_limits,
show_fills, cancel_order, cancel_all_orders, UserInfo
show_fills, show_transfers, show_fees, show_profiles,
cancel_order, cancel_all_orders, UserInfo, IntOrFloat


using DataFrames, HTTP, JSON, CSV, Dates, Statistics, Query, Base64, Nettle

Expand Down
16 changes: 15 additions & 1 deletion src/GetDataFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,27 @@ function get_exchange_limits(auth_data::CoinbaseProAuth, currency::String)
return df_limits
end

function get_fills(auth_data::CoinbaseProAuth)
function get_common_df(auth_data::CoinbaseProAuth)

account_dict = get_data_dict(auth_data::CoinbaseProAuth)

return vcat(DataFrame.(account_dict)...)
end

function get_fees(auth_data::CoinbaseProAuth)

account_dict = get_data_dict(auth_data::CoinbaseProAuth)

return DataFrame(account_dict)
end











Expand Down
119 changes: 114 additions & 5 deletions src/ShowDataFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ function show_single_order(order_ID::String, user_data::UserInfo)
return df_orders
end

#----------------------------------------------------------------------------------------#

"""
show_exchange_limits(user_data::UserInfo, currency::String)
Expand Down Expand Up @@ -414,6 +416,8 @@ function show_exchange_limits(user_data::UserInfo, currency::String)
return df_limits
end

#----------------------------------------------------------------------------------------#

"""
show_fills(user_data::UserInfo, pair::String)
Expand All @@ -437,20 +441,121 @@ julia> show_fills(user_data, "ETH-EUR")
```
"""
function show_fills(user_data::UserInfo, pair::String)
auth_data = CoinbaseProAuth("/fills?product_id=$(pair)", user_data.api_key, user_data.secret_key, user_data.passphrase, "GET", "")

return do_try_catch("/fills?product_id=$(pair)", user_data, get_common_df)
end

#----------------------------------------------------------------------------------------#

"""
show_transfers(user_data::UserInfo, deposit_type::String="deposit")
Get a list of deposits/withdrawals from the profile of the API key, in descending order by created time.
# Arguments
- `user_data::UserInfo` : API data
- `deposit_type::String` : "deposit" (default), "internal_deposit" (transfer between portfolios), "withdraw" or "internal_withdraw"
# Example
```julia-repl
julia> show_transfers(user_data, "internal_deposit")
4×7 DataFrame
Row │ account_id amount created_at curren ⋯
│ String String String String ⋯
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 6defb94d-80e3-45b4-a6bf-0420cc5f… 10.0000000000000000 2021-07-16 11:10:10.253255+00 EUR ⋯
2 │ 6defb94d-80e3-45b4-a6bf-0420cc5f… 10.0000000000000000 2021-07-16 11:07:48.003446+00 EUR
```
"""
function show_transfers(user_data::UserInfo, transfer_type::String="deposit")

return do_try_catch("/transfers?type=$(transfer_type)", user_data, get_common_df)
end

#----------------------------------------------------------------------------------------#

"""
show_fees(user_data::UserInfo)
Get current maker & taker fee rates, as well as your 30-day trailing volume.
# Arguments
- `user_data::UserInfo` : API data
# Example
```julia-repl
julia> show_fees(user_data_default)
1×3 DataFrame
Row │ maker_fee_rate taker_fee_rate usd_volume
│ String String String
─────┼────────────────────────────────────────────
1 │ 0.0050 0.0050 117.09
```
"""
function show_fees(user_data::UserInfo)
auth_data = CoinbaseProAuth("/fees", user_data.api_key, user_data.secret_key, user_data.passphrase, "GET", "")

df_fees = DataFrame()

df_fills = DataFrame()
try
df_fills = get_fills(auth_data)
df_fees = get_fees(auth_data)
catch e
if isa(e, HTTP.ExceptionRequest.StatusError)
@info "404 Not Found - Check if the input data is valid"
@info "404 Not Found/403 Forbidden - Check if the input data is valid"
else
@info "Could not retrieve data, try again!"
end
end

return df_fees
end

#----------------------------------------------------------------------------------------#

"""
show_profiles(user_data::UserInfo)
Get a list of all user profiles/portfolios.
# Arguments
- `user_data::UserInfo` : API data
# Example
```julia-repl
julia> show_profiles(user_data_default)
6×6 DataFrame
Row │ active created_at id is_default name ⋯
│ Bool String String Bool String ⋯
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────
1 │ true 2019-06-23T00:19:33.647283Z dc06c753-2e85-4e2f-b281-3a78bc7b… true default ⋯
2 │ true 2021-05-07T21:10:07.037681Z 4617f329-2709-453b-b95d-d14727cb… false Julia Bot
3 │ true 2021-05-07T22:08:15.362932Z 70c483c4-112e-402d-a498-3dd70155… false Julia Bot
```
"""
function show_profiles(user_data::UserInfo)

return do_try_catch("/profiles", user_data, get_common_df)
end

##################### Helper function #####################

function do_try_catch(endpoint::String, user_data::UserInfo, get_common_df)

auth_data = CoinbaseProAuth(endpoint, user_data.api_key, user_data.secret_key, user_data.passphrase, "GET", "")

df_data = DataFrame()

try
df_data = get_common_df(auth_data)
catch e
if isa(e, HTTP.ExceptionRequest.StatusError)
@info "404 Not Found/403 Forbidden - Check if the input data is valid"
else
@info "Could not retrieve data, try again!"
end
end

return df_fills
return df_data
end


Expand All @@ -468,4 +573,8 @@ end








Loading

2 comments on commit c8d9a4f

@vnegi10
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

  • Added new functions: show_transfers, show_fees, show_profiles
  • Code refactoring
  • Updated tests and documentation

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/41006

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.3 -m "<description of version>" c8d9a4f223e29de262d0ea145cbd21dd9cfe202c
git push origin v0.1.3

Please sign in to comment.