Skip to content

Commit c8d9a4f

Browse files
committed
New version + updated tests, docs + refactoring
1 parent 3c4bb9f commit c8d9a4f

8 files changed

Lines changed: 194 additions & 63 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CoinbaseProExchange"
22
uuid = "06c3450d-869c-4596-88b4-6f9fb82f72bd"
33
authors = ["Vikas Negi <vikas.negi10@gmail.com>"]
4-
version = "0.1.2"
4+
version = "0.1.3"
55

66
[deps]
77
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

README.md

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## CoinbaseProExchange
1+
# CoinbaseProExchange.jl
22

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

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

1818
Public endpoints can be accessed without a Coinbase Pro account.
1919

20-
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)
20+
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)
2121

2222
## API key permissions
2323

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

36-
### Available functions
37-
38-
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
39-
40-
### Public endpoints (Coinbase account is not necessary)
36+
## Public endpoints (Coinbase account is not necessary)
4137

4238
```julia
4339
julia> show_server_time("iso")
@@ -62,7 +58,7 @@ julia> show_historical_data("ETH-EUR", 3600)
6258

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

65-
### Private endpoints (Coinbase Pro account + API keys are needed)
61+
## Private endpoints (Coinbase Pro account + API keys are needed)
6662

6763
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:
6864

@@ -93,28 +89,6 @@ Dict{String, Any} with 14 entries:
9389
"type" => "market"
9490
```
9591
96-
```julia
97-
julia> place_limit_order("sell", "BTC-EUR", 0.0005, 30000, user_data)
98-
99-
[ Info: Order placed
100-
Dict{String, Any} with 15 entries:
101-
"created_at" => "2021-07-04T21:59:11.083132Z"
102-
"price" => "30000"
103-
"stp" => "dc"
104-
"product_id" => "BTC-EUR"
105-
"settled" => false
106-
"status" => "pending"
107-
"id" => "cae9158e-1660-448e-bd9a-d368ce3fdc8a"
108-
"executed_value" => "0"
109-
"post_only" => false
110-
"size" => "0.0005"
111-
"filled_size" => "0"
112-
"side" => "sell"
113-
"time_in_force" => "GTC"
114-
"fill_fees" => "0"
115-
"type" => "limit"
116-
```
117-
11892
**Check docs for more examples:** [![](https://img.shields.io/badge/docs-stable-blue.svg)](https://vnegi10.github.io/CoinbaseProExchange.jl/stable)
11993
12094

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using Documenter
22
using CoinbaseProExchange
33

44
makedocs(
5-
sitename = "CoinbaseProExchange",
5+
sitename = "CoinbaseProExchange.jl",
66
format = Documenter.HTML(),
77
modules = [CoinbaseProExchange]
88
)

docs/src/index.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,61 @@
1-
# CoinbaseProExchange.jl
1+
# User Guide
22
---
33

4-
### Available functions
4+
## Overview
5+
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).
56

6-
#### Public endpoints (Coinbase account is not necessary)
7+
## Available functions
8+
```@index
9+
```
710

11+
## Public endpoints (Coinbase Pro account is not necessary)
812
```@docs
9-
show_server_time(time_type::String)
13+
show_server_time(time_type::String="iso")
1014
11-
show_historical_data(pair::String, interval::Int64)
15+
show_historical_data(pair::String, interval::Int64=300)
1216
13-
show_all_products(currency::String)
17+
show_all_products(currency::String="USD")
1418
1519
show_latest_trades(pair::String)
1620
17-
show_product_data(pair::String, endpoint::String)
21+
show_product_data(pair::String, endpoint::String="24hr stats")
1822
```
1923

20-
#### Private endpoints (Coinbase Pro account + API keys are needed)
24+
## Private endpoints (Coinbase Pro account + API keys are needed)
2125

26+
### API key should have "trade" or "view" permission
2227
```@docs
2328
show_all_accounts(user_data::UserInfo, currencies::Vector{String})
2429
2530
show_account_info(user_data::UserInfo, currency::String, info_type::String)
2631
32+
show_exchange_limits(user_data::UserInfo, currency::String)
33+
34+
show_fills(user_data::UserInfo, pair::String)
35+
36+
show_transfers(user_data::UserInfo, transfer_type::String="deposit")
37+
38+
show_fees(user_data::UserInfo)
39+
40+
show_profiles(user_data::UserInfo)
41+
```
42+
43+
### API key should have "trade" permission
44+
```@docs
45+
place_market_order(side::String, pair::String, amount::IntOrFloat, amount_type::String, user_data::UserInfo)
46+
47+
place_limit_order(side::String, pair::String, amount::IntOrFloat, price::IntOrFloat, user_data::UserInfo)
48+
2749
show_open_orders(user_data::UserInfo)
2850
2951
show_single_order(order_ID::String, user_data::UserInfo)
3052
3153
cancel_order(order_id::String, user_data::UserInfo)
3254
3355
cancel_all_orders(user_data::UserInfo)
56+
```
3457

35-
show_exchange_limits(user_data::UserInfo, currency::String)
3658

37-
show_fills(user_data::UserInfo, pair::String)
38-
```
3959

4060

4161

src/CoinbaseProExchange.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ export show_historical_data, show_server_time, show_all_products,
44
show_latest_trades, show_product_data, show_all_accounts,
55
show_account_info, place_market_order, place_limit_order,
66
show_open_orders, show_single_order, show_exchange_limits,
7-
show_fills, cancel_order, cancel_all_orders, UserInfo
7+
show_fills, show_transfers, show_fees, show_profiles,
8+
cancel_order, cancel_all_orders, UserInfo, IntOrFloat
9+
810

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

src/GetDataFunctions.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,27 @@ function get_exchange_limits(auth_data::CoinbaseProAuth, currency::String)
197197
return df_limits
198198
end
199199

200-
function get_fills(auth_data::CoinbaseProAuth)
200+
function get_common_df(auth_data::CoinbaseProAuth)
201201

202202
account_dict = get_data_dict(auth_data::CoinbaseProAuth)
203203

204204
return vcat(DataFrame.(account_dict)...)
205205
end
206206

207+
function get_fees(auth_data::CoinbaseProAuth)
208+
209+
account_dict = get_data_dict(auth_data::CoinbaseProAuth)
210+
211+
return DataFrame(account_dict)
212+
end
213+
214+
215+
216+
217+
218+
219+
220+
207221

208222

209223

src/ShowDataFunctions.jl

Lines changed: 114 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ function show_single_order(order_ID::String, user_data::UserInfo)
374374
return df_orders
375375
end
376376

377+
#----------------------------------------------------------------------------------------#
378+
377379
"""
378380
show_exchange_limits(user_data::UserInfo, currency::String)
379381
@@ -414,6 +416,8 @@ function show_exchange_limits(user_data::UserInfo, currency::String)
414416
return df_limits
415417
end
416418

419+
#----------------------------------------------------------------------------------------#
420+
417421
"""
418422
show_fills(user_data::UserInfo, pair::String)
419423
@@ -437,20 +441,121 @@ julia> show_fills(user_data, "ETH-EUR")
437441
```
438442
"""
439443
function show_fills(user_data::UserInfo, pair::String)
440-
auth_data = CoinbaseProAuth("/fills?product_id=$(pair)", user_data.api_key, user_data.secret_key, user_data.passphrase, "GET", "")
444+
445+
return do_try_catch("/fills?product_id=$(pair)", user_data, get_common_df)
446+
end
447+
448+
#----------------------------------------------------------------------------------------#
449+
450+
"""
451+
show_transfers(user_data::UserInfo, deposit_type::String="deposit")
452+
453+
Get a list of deposits/withdrawals from the profile of the API key, in descending order by created time.
454+
455+
# Arguments
456+
- `user_data::UserInfo` : API data
457+
- `deposit_type::String` : "deposit" (default), "internal_deposit" (transfer between portfolios), "withdraw" or "internal_withdraw"
458+
459+
# Example
460+
```julia-repl
461+
julia> show_transfers(user_data, "internal_deposit")
462+
4×7 DataFrame
463+
Row │ account_id amount created_at curren ⋯
464+
│ String String String String ⋯
465+
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────
466+
1 │ 6defb94d-80e3-45b4-a6bf-0420cc5f… 10.0000000000000000 2021-07-16 11:10:10.253255+00 EUR ⋯
467+
2 │ 6defb94d-80e3-45b4-a6bf-0420cc5f… 10.0000000000000000 2021-07-16 11:07:48.003446+00 EUR
468+
```
469+
"""
470+
function show_transfers(user_data::UserInfo, transfer_type::String="deposit")
471+
472+
return do_try_catch("/transfers?type=$(transfer_type)", user_data, get_common_df)
473+
end
474+
475+
#----------------------------------------------------------------------------------------#
476+
477+
"""
478+
show_fees(user_data::UserInfo)
479+
480+
Get current maker & taker fee rates, as well as your 30-day trailing volume.
481+
482+
# Arguments
483+
- `user_data::UserInfo` : API data
484+
485+
# Example
486+
```julia-repl
487+
julia> show_fees(user_data_default)
488+
1×3 DataFrame
489+
Row │ maker_fee_rate taker_fee_rate usd_volume
490+
│ String String String
491+
─────┼────────────────────────────────────────────
492+
1 │ 0.0050 0.0050 117.09
493+
```
494+
"""
495+
function show_fees(user_data::UserInfo)
496+
auth_data = CoinbaseProAuth("/fees", user_data.api_key, user_data.secret_key, user_data.passphrase, "GET", "")
497+
498+
df_fees = DataFrame()
441499

442-
df_fills = DataFrame()
443500
try
444-
df_fills = get_fills(auth_data)
501+
df_fees = get_fees(auth_data)
445502
catch e
446503
if isa(e, HTTP.ExceptionRequest.StatusError)
447-
@info "404 Not Found - Check if the input data is valid"
504+
@info "404 Not Found/403 Forbidden - Check if the input data is valid"
505+
else
506+
@info "Could not retrieve data, try again!"
507+
end
508+
end
509+
510+
return df_fees
511+
end
512+
513+
#----------------------------------------------------------------------------------------#
514+
515+
"""
516+
show_profiles(user_data::UserInfo)
517+
518+
Get a list of all user profiles/portfolios.
519+
520+
# Arguments
521+
- `user_data::UserInfo` : API data
522+
523+
# Example
524+
```julia-repl
525+
julia> show_profiles(user_data_default)
526+
6×6 DataFrame
527+
Row │ active created_at id is_default name ⋯
528+
│ Bool String String Bool String ⋯
529+
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────
530+
1 │ true 2019-06-23T00:19:33.647283Z dc06c753-2e85-4e2f-b281-3a78bc7b… true default ⋯
531+
2 │ true 2021-05-07T21:10:07.037681Z 4617f329-2709-453b-b95d-d14727cb… false Julia Bot
532+
3 │ true 2021-05-07T22:08:15.362932Z 70c483c4-112e-402d-a498-3dd70155… false Julia Bot
533+
```
534+
"""
535+
function show_profiles(user_data::UserInfo)
536+
537+
return do_try_catch("/profiles", user_data, get_common_df)
538+
end
539+
540+
##################### Helper function #####################
541+
542+
function do_try_catch(endpoint::String, user_data::UserInfo, get_common_df)
543+
544+
auth_data = CoinbaseProAuth(endpoint, user_data.api_key, user_data.secret_key, user_data.passphrase, "GET", "")
545+
546+
df_data = DataFrame()
547+
548+
try
549+
df_data = get_common_df(auth_data)
550+
catch e
551+
if isa(e, HTTP.ExceptionRequest.StatusError)
552+
@info "404 Not Found/403 Forbidden - Check if the input data is valid"
448553
else
449554
@info "Could not retrieve data, try again!"
450555
end
451556
end
452557

453-
return df_fills
558+
return df_data
454559
end
455560

456561

@@ -468,4 +573,8 @@ end
468573

469574

470575

576+
577+
578+
579+
471580

0 commit comments

Comments
 (0)