├── go.mod ├── .travis.yml ├── time_test.go ├── currencies_test.go ├── exchange_rates_test.go ├── helper_test.go ├── time.go ├── prices_test.go ├── README.md ├── currencies.go ├── exchange_rates.go ├── addresses_test.go ├── client_test.go ├── prices.go ├── buys.go ├── sells.go ├── deposits.go ├── withdrawals.go ├── buys_test.go ├── addresses.go ├── transactions_test.go ├── users.go ├── accounts_test.go ├── payment_methods.go ├── client.go ├── accounts.go ├── global.go ├── transactions.go └── LICENSE /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/Zauberstuhl/go-coinbase 2 | 3 | go 1.14 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.9.x 4 | - master 5 | script: 6 | - go test -v -race -coverprofile=coverage.txt -covermode=atomic 7 | after_success: 8 | - bash <(curl -s https://codecov.io/bash) 9 | -------------------------------------------------------------------------------- /time_test.go: -------------------------------------------------------------------------------- 1 | package coinbase 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestGetCurrentTime(t *testing.T) { 8 | a := APIClient{ 9 | Key: "123", 10 | Secret: "123456", 11 | } 12 | time, err := a.GetCurrentTime() 13 | if err != nil { 14 | t.Error("Expected nil, got ", err.Error()) 15 | } 16 | if time.Data.Epoch < 1485347945 { 17 | t.Error("Expected valid unix timestamp, got ", time.Data.Epoch) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /currencies_test.go: -------------------------------------------------------------------------------- 1 | package coinbase 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestGetCurrencies(t *testing.T) { 8 | a := APIClient{ 9 | Key: "123", 10 | Secret: "123456", 11 | } 12 | list, err := a.GetCurrencies() 13 | if err != nil { 14 | t.Error("Expected nil, got ", err.Error()) 15 | } 16 | if len(list.Data) <= 0 { 17 | t.Error("Expected list to be greater then zero") 18 | } 19 | for i, curr := range list.Data { 20 | if len(curr.Id) != 3 { 21 | t.Error(i, ". Expected id length equal three") 22 | } 23 | if len(curr.Name) <= 0 { 24 | t.Error(i, ". Expected name length to be greater then zero") 25 | } 26 | if curr.Min_size <= 0.0 { 27 | t.Error(i, ". Expected min_size to be greater then zero") 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /exchange_rates_test.go: -------------------------------------------------------------------------------- 1 | package coinbase 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestGetExchangeRates(t *testing.T) { 8 | a := APIClient{ 9 | Key: "123", 10 | Secret: "123456", 11 | } 12 | exch, err := a.GetExchangeRates("BTC") 13 | if err != nil { 14 | t.Error("Expected nil, got ", err.Error()) 15 | } 16 | if len(exch.Data.Currency) != 3 { 17 | t.Error("Expected currency length equal three") 18 | } 19 | for key, value := range exch.Data.Rates { 20 | if len(key) < 3 { 21 | t.Error("Expected ", key, " length equal three") 22 | } 23 | rate, err := value.Float64() 24 | if err != nil { 25 | t.Error("Expected nil, got ", err.Error()) 26 | } 27 | if rate <= 0.0 { 28 | t.Error("Expected value to be greater then zero") 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /helper_test.go: -------------------------------------------------------------------------------- 1 | package coinbase 2 | 3 | import ( 4 | "net/http" 5 | "net/http/httptest" 6 | "fmt" 7 | "testing" 8 | ) 9 | 10 | func serverHelper(t *testing.T, method, uri, body *string) *httptest.Server { 11 | return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 12 | w.Header().Set("Content-Type", "application/json") 13 | 14 | if r.RequestURI == "/v2/time" { 15 | // NOTE this is used on a signing request 16 | fmt.Fprintln(w, `{ 17 | "data": { 18 | "iso": "2015-06-23T18:02:51Z", 19 | "epoch": 1435082571 20 | } 21 | }`) 22 | return 23 | } 24 | 25 | if *method != r.Method { 26 | t.Errorf("Expected http method %s, got %s", *method, r.Method) 27 | } 28 | 29 | if *uri != r.RequestURI { 30 | t.Errorf("Expected request uri %s, got %s", *uri, r.RequestURI) 31 | } 32 | 33 | fmt.Fprintln(w, *body) 34 | })) 35 | } 36 | -------------------------------------------------------------------------------- /time.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | /* 23 | 24 | Example Response: 25 | 26 | { 27 | "data": { 28 | "iso": "2015-06-23T18:02:51Z", 29 | "epoch": 1435082571 30 | } 31 | } 32 | 33 | */ 34 | type APITimeData struct { 35 | Iso string 36 | Epoch int64 37 | } 38 | type APITime struct { 39 | Data APITimeData 40 | } 41 | // GetCurrentTime returns an APITime struct 42 | func (a *APIClient) GetCurrentTime() (time APITime, err error) { 43 | err = a.Fetch("GET", "/v2/time", nil, &time) 44 | if err != nil { 45 | return 46 | } 47 | return 48 | } 49 | -------------------------------------------------------------------------------- /prices_test.go: -------------------------------------------------------------------------------- 1 | package coinbase 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | ) 7 | 8 | func TestGetBuyPrice(t *testing.T) { 9 | a := APIClient{} 10 | balance, err := a.GetBuyPrice( 11 | ConfigPrice{ 12 | From: "BTC", 13 | To: "EUR", 14 | }) 15 | if err != nil { 16 | t.Error("Expected nil, got ", err.Error()) 17 | } 18 | if balance.Data.Currency != "EUR" { 19 | t.Error("Expected EUR, got ", balance.Data.Currency) 20 | } 21 | if balance.Data.Amount <= 0.0 { 22 | t.Error("Expected <= 0.0, got ", balance.Data.Amount) 23 | } 24 | } 25 | 26 | func TestGetSellPrice(t *testing.T) { 27 | a := APIClient{} 28 | balance, err := a.GetSellPrice( 29 | ConfigPrice{ 30 | From: "BTC", 31 | To: "EUR", 32 | }) 33 | if err != nil { 34 | t.Error("Expected nil, got ", err.Error()) 35 | } 36 | if balance.Data.Currency != "EUR" { 37 | t.Error("Expected EUR, got ", balance.Data.Currency) 38 | } 39 | if balance.Data.Amount <= 0.0 { 40 | t.Error("Expected <= 0.0, got ", balance.Data.Amount) 41 | } 42 | } 43 | 44 | func TestGetSpotPrice(t *testing.T) { 45 | a := APIClient{} 46 | date, err := time.Parse("2006-01-02", "2017-01-01") 47 | if err != nil { 48 | t.Error("Expected nil, got ", err.Error()) 49 | } 50 | 51 | balance, err := a.GetSpotPrice( 52 | ConfigPrice{ 53 | From: "BTC", 54 | To: "EUR", 55 | Date: date, 56 | }) 57 | if err != nil { 58 | t.Error("Expected nil, got ", err.Error()) 59 | } 60 | if balance.Data.Currency != "EUR" { 61 | t.Error("Expected EUR, got ", balance.Data.Currency) 62 | } 63 | if balance.Data.Amount <= 0.0 { 64 | t.Error("Expected amount > 0.0, got ", balance.Data.Amount) 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Coinbase Golang API Library 2 | 3 | [![Build Status](https://travis-ci.org/Zauberstuhl/go-coinbase.svg?branch=master)](https://travis-ci.org/Zauberstuhl/go-coinbase) 4 | [![GoDoc](https://godoc.org/github.com/Zauberstuhl/go-coinbase?status.svg)](http://godoc.org/github.com/Zauberstuhl/go-coinbase) 5 | [![Codecov](https://codecov.io/gh/Zauberstuhl/go-coinbase/branch/master/graph/badge.svg)](https://codecov.io/gh/Zauberstuhl/go-coinbase) 6 | 7 | The library was tested against coinbase.com APIv2 8 | 9 | ## Installation 10 | 11 | go get github.com/Zauberstuhl/go-coinbase 12 | 13 | # or use gopkg for specific versions 14 | go get gopkg.in/Zauberstuhl/go-coinbase.v1.0.0 15 | 16 | ## Supported API Calls 17 | 18 | * Wallet Endpoints 19 | - [x] Users 20 | - [x] Accounts 21 | - [x] Addresses 22 | - [x] Transactions 23 | - [x] Buys 24 | - [x] Sells 25 | - [x] Deposits 26 | - [x] Withdrawals 27 | - [x] Payment methods 28 | * Data Endpoints 29 | - [x] Currencies 30 | - [x] Exchange rates 31 | - [x] Prices 32 | - [x] Time 33 | 34 | ## Example 35 | 36 | import "github.com/Zauberstuhl/go-coinbase" 37 | 38 | c := coinbase.APIClient{ 39 | Key: "123", 40 | Secret: "123456", 41 | } 42 | 43 | acc, err := c.Accounts() 44 | if err != nil { 45 | fmt.Println(err) 46 | return 47 | } 48 | 49 | for _, acc := range acc.Data { 50 | fmt.Printf("ID: %s\nName: %s\nType: %s\nAmount: %f\nCurrency: %s\n", 51 | acc.Id, acc.Name, acc.Type, 52 | acc.Balance.Amount, acc.Balance.Currency) 53 | } 54 | 55 | # sample output 56 | ID: 1234-12-1234-1232 57 | Name: Test Wallet 58 | Type: BTC 59 | Amount: 0.0 60 | Currency: EUR 61 | [...] 62 | 63 | ## Unit Tests 64 | 65 | Run all available unit tests via: 66 | 67 | go test 68 | 69 | Most of the tests require a internet connection! 70 | -------------------------------------------------------------------------------- /currencies.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | /* 23 | 24 | Example Response: 25 | 26 | { 27 | "data": [ 28 | { 29 | "id": "AED", 30 | "name": "United Arab Emirates Dirham", 31 | "min_size": "0.01000000" 32 | }, 33 | { 34 | "id": "AFN", 35 | "name": "Afghan Afghani", 36 | "min_size": "0.01000000" 37 | }, 38 | { 39 | "id": "ALL", 40 | "name": "Albanian Lek", 41 | "min_size": "0.01000000" 42 | }, 43 | { 44 | "id": "AMD", 45 | "name": "Armenian Dram", 46 | "min_size": "0.01000000" 47 | }, 48 | ... 49 | } 50 | } 51 | 52 | */ 53 | type APICurrenciesData struct { 54 | Id string 55 | Name string 56 | Min_size float64 `json:",string"` 57 | } 58 | type APICurrencies struct { 59 | Data []APICurrenciesData 60 | Errors []Error 61 | } 62 | // GetCurrencies will return an APICurrencies struct 63 | func (a *APIClient) GetCurrencies() (curr APICurrencies, err error) { 64 | err = a.Fetch("GET", "/v2/currencies", nil, &curr) 65 | if err != nil { 66 | return 67 | } 68 | return 69 | } 70 | -------------------------------------------------------------------------------- /exchange_rates.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | import "encoding/json" 23 | 24 | /* 25 | 26 | Example Response: 27 | 28 | { 29 | "data": { 30 | "currency": "BTC", 31 | "rates": { 32 | "AED": "36.73", 33 | "AFN": "589.50", 34 | "ALL": "1258.82", 35 | "AMD": "4769.49", 36 | "ANG": "17.88", 37 | "AOA": "1102.76", 38 | "ARS": "90.37", 39 | "AUD": "12.93", 40 | "AWG": "17.93", 41 | "AZN": "10.48", 42 | "BAM": "17.38", 43 | ... 44 | } 45 | } 46 | } 47 | 48 | */ 49 | type APIExchangeRatesData struct { 50 | Currency string 51 | // using map[string]float64 `json:",string"` 52 | // will result into ain unmarshalling error. 53 | // Using json.Number gets rid of strconv! 54 | Rates map[string]json.Number 55 | } 56 | type APIExchangeRates struct { 57 | Data APIExchangeRatesData 58 | Errors []Error 59 | } 60 | // GetExchangeRates requires the currency as parameter and returns an APIExchangeRates struct 61 | func (a *APIClient) GetExchangeRates(currency string) (rates APIExchangeRates, err error) { 62 | err = a.Fetch("GET", "/v2/exchange-rates?currency=" + currency, nil, &rates) 63 | if err != nil { 64 | return 65 | } 66 | return 67 | } 68 | -------------------------------------------------------------------------------- /addresses_test.go: -------------------------------------------------------------------------------- 1 | package coinbase 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestAddress(t *testing.T) { 8 | method := "GET" 9 | uri := "/v2/accounts/dd3183eb-af1d-5f5d-a90d-cbff946435ff/addresses/mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa" 10 | body := `{ 11 | "data": { 12 | "id": "dd3183eb-af1d-5f5d-a90d-cbff946435ff", 13 | "address": "mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa", 14 | "name": "One off payment", 15 | "created_at": "2015-01-31T20:49:02Z", 16 | "updated_at": "2015-03-31T17:25:29-07:00", 17 | "network": "bitcoin", 18 | "resource": "address", 19 | "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/addresses/dd3183eb-af1d-5f5d-a90d-cbff946435ff" 20 | } 21 | }` 22 | s := serverHelper(t, &method, &uri, &body) 23 | defer s.Close() 24 | 25 | a := APIClient{ 26 | Key: "123", 27 | Secret: "123456", 28 | Endpoint: s.URL, 29 | } 30 | 31 | add, err := a.GetAddress( 32 | "dd3183eb-af1d-5f5d-a90d-cbff946435ff", 33 | "mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa") 34 | if err != nil { 35 | t.Error("Expected nil, got ", err.Error()) 36 | } 37 | address(t, add.Data) 38 | 39 | method = "POST" 40 | uri = "/v2/accounts/mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa/addresses" 41 | add, err = a.CreateAddress( 42 | "mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa", 43 | "One off payment") 44 | if err != nil { 45 | t.Error("Expected nil, got ", err.Error()) 46 | } 47 | address(t, add.Data) 48 | } 49 | 50 | func address(t *testing.T, address APIAddressData) { 51 | if address.Id != "dd3183eb-af1d-5f5d-a90d-cbff946435ff" { 52 | t.Error("Expected dd3183eb-af1d-5f5d-a90d-cbff946435ff, got ", address.Id) 53 | } 54 | if address.Address != "mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa" { 55 | t.Error("Expected mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa, got ", address.Address) 56 | } 57 | if address.Created_at.Year() != 2015 { 58 | t.Error("Expected 2015, got ", address.Created_at.Year()) 59 | } 60 | if address.Updated_at.Year() != 2015 { 61 | t.Error("Expected 2015, got ", address.Created_at.Year()) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /client_test.go: -------------------------------------------------------------------------------- 1 | package coinbase 2 | 3 | import ( 4 | "testing" 5 | "net/http" 6 | "net/http/httptest" 7 | "crypto/sha256" 8 | "crypto/hmac" 9 | "fmt" 10 | ) 11 | 12 | func TestClientFetch(t *testing.T) { 13 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 14 | w.Header().Set("Content-Type", "application/json") 15 | fmt.Fprintln(w, `{"Data":{"Epoch":1485347945}}`) 16 | })) 17 | defer ts.Close() 18 | 19 | a := APIClient{ 20 | Key: "123", 21 | Secret: "123456", 22 | Endpoint: ts.URL, 23 | } 24 | 25 | var result APIClientEpoch 26 | err := a.Fetch("GET", "/v2/time", nil, &result) 27 | if err != nil { 28 | t.Error("Expected nil, got ", err.Error()) 29 | } 30 | if result.Data.Epoch != 1485347945 { 31 | t.Error("Expected valid unix timestamp, got ", result.Data.Epoch) 32 | } 33 | } 34 | 35 | func TestClientAuthenticate(t *testing.T) { 36 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 37 | w.Header().Set("Content-Type", "application/json") 38 | fmt.Fprintln(w, `{"Data":{"Epoch":1485347945}}`) 39 | })) 40 | defer ts.Close() 41 | 42 | req, err := http.NewRequest("GET", "/", nil) 43 | if err != nil { 44 | t.Error("Expected nil, got ", err.Error()) 45 | } 46 | 47 | a := APIClient{ 48 | Key: "123", 49 | Secret: "123456", 50 | Endpoint: ts.URL, 51 | } 52 | err = a.Authenticate("/", req, nil) 53 | if err != nil { 54 | t.Error("Expected nil, got ", err.Error()) 55 | } 56 | 57 | key := req.Header.Get("CB-ACCESS-KEY") 58 | if key != "123" { 59 | t.Error("Expected key to be 123, got ", key) 60 | } 61 | 62 | signatureHeader := []byte(req.Header.Get("CB-ACCESS-SIGN")) 63 | h := hmac.New(sha256.New, []byte("123456")) 64 | h.Write([]byte("1485347945GET/")) 65 | signature := fmt.Sprintf("%x", h.Sum(nil)) 66 | if !hmac.Equal(signatureHeader, []byte(signature)) { 67 | t.Error("Expected equal signatures, got different ones") 68 | } 69 | 70 | timestamp := req.Header.Get("CB-ACCESS-TIMESTAMP") 71 | if timestamp != "1485347945" { 72 | t.Error("Expected valid unix timestamp, got ", timestamp) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /prices.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | // TODO wrong naming convention 23 | type APIBalanceData struct { 24 | Data APIBalance 25 | Errors []Error 26 | } 27 | // GetBuyPrice requires a ConfigPrice struct as parameter 28 | // and returns an APIBalanceData struct 29 | func (a *APIClient) GetBuyPrice(c ConfigPrice) (balance APIBalanceData, err error) { 30 | err = a.Fetch("GET", "/v2/prices/" + c.From + 31 | "-" + c.To + "/buy", nil, &balance) 32 | if err != nil { 33 | return 34 | } 35 | return 36 | } 37 | 38 | // GetSellPrice requires a ConfigPrice struct as parameter 39 | // and returns an APIBalanceData struct 40 | func (a *APIClient) GetSellPrice(c ConfigPrice) (balance APIBalanceData, err error) { 41 | err = a.Fetch("GET", "/v2/prices/" + c.From + 42 | "-" + c.To + "/sell", nil, &balance) 43 | if err != nil { 44 | return 45 | } 46 | return 47 | } 48 | 49 | // GetSpotPrice requires a ConfigPrice struct as parameter 50 | // and returns an APIBalanceData struct. If you define a date 51 | // you will recieve the spot price for the given date. 52 | func (a *APIClient) GetSpotPrice(c ConfigPrice) (balance APIBalanceData, err error) { 53 | var date string = "" 54 | if c.Date.Year() != 1 { 55 | date = "?date=" + c.Date.Format("2006-01-02") 56 | } 57 | err = a.Fetch("GET", "/v2/prices/" + c.From + 58 | "-" + c.To + "/spot" + date, nil, &balance) 59 | if err != nil { 60 | return 61 | } 62 | return 63 | } 64 | -------------------------------------------------------------------------------- /buys.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | /* 22 | 23 | Example: 24 | 2bbf394c-193b-5b2a-9155-3b4732659ede 25 | 26 | */ 27 | type BuyId string 28 | 29 | // ListBuys requires an account ID and returns an APIWalletTransferList struct 30 | func (a *APIClient) ListBuys(id AccountId) (buys APIWalletTransferList, err error) { 31 | path := pathHelper("/v2/accounts/%s/buys", id) 32 | err = a.Fetch("GET", path, nil, &buys) 33 | if err != nil { 34 | return 35 | } 36 | return 37 | } 38 | 39 | // ShowBuy requires an account ID, buy ID and returns an APIWalletTransfer struct 40 | func (a *APIClient) ShowBuy(id AccountId, bid BuyId) (buys APIWalletTransfer, err error) { 41 | path := pathHelper("/v2/accounts/%s/buys/%s", id, bid) 42 | err = a.Fetch("GET", path, nil, &buys) 43 | if err != nil { 44 | return 45 | } 46 | return 47 | } 48 | 49 | // PlaceBuyOrder requires an account ID, APIWalletTransferOrder and returns an APIWalletTransfer struct 50 | func (a *APIClient) PlaceBuyOrder(id AccountId, order APIWalletTransferOrder) (buys APIWalletTransfer, err error) { 51 | path := pathHelper("/v2/accounts/%s/buys", id) 52 | err = a.Fetch("POST", path, order, &buys) 53 | if err != nil { 54 | return 55 | } 56 | return 57 | } 58 | 59 | // CommitBuy requires an account ID, buy ID and returns an APIWalletTransfer struct 60 | func (a *APIClient) CommitBuy(id AccountId, bid BuyId) (buys APIWalletTransfer, err error) { 61 | path := pathHelper("/v2/accounts/%s/buys/%s/commit", id, bid) 62 | err = a.Fetch("POST", path, nil, &buys) 63 | if err != nil { 64 | return 65 | } 66 | return 67 | } 68 | -------------------------------------------------------------------------------- /sells.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | 23 | /* 24 | 25 | Example: 26 | 2bbf394c-193b-5b2a-9155-3b4732659ede 27 | 28 | */ 29 | type SellId string 30 | 31 | // ListSells requires an account ID and returns an APIWalletTransferList struct 32 | func (a *APIClient) ListSells(id AccountId) (sells APIWalletTransferList, err error) { 33 | path := pathHelper("/v2/accounts/%s/sells", id) 34 | err = a.Fetch("GET", path, nil, &sells) 35 | if err != nil { 36 | return 37 | } 38 | return 39 | } 40 | 41 | // ShowSell requires an account ID, buy ID and returns an APIWalletTransfer struct 42 | func (a *APIClient) ShowSell(id AccountId, sid SellId) (sells APIWalletTransfer, err error) { 43 | path := pathHelper("/v2/accounts/%s/sells/%s", id, sid) 44 | err = a.Fetch("GET", path, nil, &sells) 45 | if err != nil { 46 | return 47 | } 48 | return 49 | } 50 | 51 | // PlaceSellOrder requires an account ID, APIWalletTransferOrder and returns an APIWalletTransfer struct 52 | func (a *APIClient) PlaceSellOrder(id AccountId, order APIWalletTransferOrder) (sells APIWalletTransfer, err error) { 53 | 54 | path := pathHelper("/v2/accounts/%s/sells", id) 55 | err = a.Fetch("POST", path, order, &sells) 56 | if err != nil { 57 | return 58 | } 59 | return 60 | } 61 | 62 | // CommitSell requires an account ID, sell ID and returns an APIWalletTransfer struct 63 | func (a *APIClient) CommitSell(id AccountId, sid SellId) (sells APIWalletTransfer, err error) { 64 | path := pathHelper("/v2/accounts/%s/buys/%s/commit", id, sid) 65 | err = a.Fetch("POST", path, nil, &sells) 66 | if err != nil { 67 | return 68 | } 69 | return 70 | } 71 | -------------------------------------------------------------------------------- /deposits.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | 23 | /* 24 | 25 | Example: 26 | 2bbf394c-193b-5b2a-9155-3b4732659ede 27 | 28 | */ 29 | type DepositId string 30 | 31 | // ListDeposits requires an account ID and returns an APIWalletTransferList struct 32 | func (a *APIClient) ListDeposits(id AccountId) (deposits APIWalletTransferList, err error) { 33 | path := pathHelper("/v2/accounts/%s/deposits", id) 34 | err = a.Fetch("GET", path, nil, &deposits) 35 | if err != nil { 36 | return 37 | } 38 | return 39 | } 40 | 41 | // ShowDeposit requires an account ID, deposit ID and returns an APIWalletTransfer struct 42 | func (a *APIClient) ShowDeposit(id AccountId, did DepositId) (deposits APIWalletTransfer, err error) { 43 | path := pathHelper("/v2/accounts/%s/deposits/%s", id, did) 44 | err = a.Fetch("GET", path, nil, &deposits) 45 | if err != nil { 46 | return 47 | } 48 | return 49 | } 50 | 51 | // DepositFunds requires an account ID, APIWalletTransferOrder and returns an APIWalletTransfer struct 52 | func (a *APIClient) DepositFunds(id AccountId, order APIWalletTransferOrder) (deposits APIWalletTransfer, err error) { 53 | path := pathHelper("/v2/accounts/%s/deposits", id) 54 | err = a.Fetch("POST", path, order, &deposits) 55 | if err != nil { 56 | return 57 | } 58 | return 59 | } 60 | 61 | // CommitDeposit requires an account ID, deposit ID and returns an APIWalletTransfer struct 62 | func (a *APIClient) CommitDeposit(id AccountId, did DepositId) (deposits APIWalletTransfer, err error) { 63 | path := pathHelper("/v2/accounts/%s/buys/%s/commit", id, did) 64 | err = a.Fetch("POST", path, nil, &deposits) 65 | if err != nil { 66 | return 67 | } 68 | return 69 | } 70 | -------------------------------------------------------------------------------- /withdrawals.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | /* 23 | 24 | Example: 25 | 2bbf394c-193b-5b2a-9155-3b4732659ede 26 | 27 | */ 28 | type WithdrawalId string 29 | 30 | // ListWithdrawals requires an account ID and returns an APIWalletTransferList struct 31 | func (a *APIClient) ListWithdrawals(id AccountId) (withdrawals APIWalletTransferList, err error) { 32 | path := pathHelper("/v2/accounts/%s/withdrawals", id) 33 | err = a.Fetch("GET", path, nil, &withdrawals) 34 | if err != nil { 35 | return 36 | } 37 | return 38 | } 39 | 40 | // ShowWithdrawal requires an account ID, withdrawal ID and returns an APIWalletTransfer struct 41 | func (a *APIClient) ShowWithdrawal(id AccountId, wid WithdrawalId) (withdrawals APIWalletTransfer, err error) { 42 | path := pathHelper("/v2/accounts/%s/withdrawals/%s", id, wid) 43 | err = a.Fetch("GET", path, nil, &withdrawals) 44 | if err != nil { 45 | return 46 | } 47 | return 48 | } 49 | 50 | // WithdrawalFunds requires an account ID, APIWalletTransferOrder and returns an APIWalletTransfer struct 51 | func (a *APIClient) WithdrawalFunds(id AccountId, order APIWalletTransferOrder) (withdrawals APIWalletTransfer, err error) { 52 | path := pathHelper("/v2/accounts/%s/withdrawals", id) 53 | err = a.Fetch("POST", path, order, &withdrawals) 54 | if err != nil { 55 | return 56 | } 57 | return 58 | } 59 | 60 | // CommitWithdrawal requires an account ID, deposit ID and returns an APIWalletTransfer struct 61 | func (a *APIClient) CommitWithdrawal(id AccountId, wid WithdrawalId) (withdrawals APIWalletTransfer, err error) { 62 | path := pathHelper("/v2/accounts/%s/buys/%s/commit", id, wid) 63 | err = a.Fetch("POST", path, nil, &withdrawals) 64 | if err != nil { 65 | return 66 | } 67 | return 68 | } 69 | -------------------------------------------------------------------------------- /buys_test.go: -------------------------------------------------------------------------------- 1 | package coinbase 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestBuys(t *testing.T) { 8 | method := "GET" 9 | uri := "/v2/accounts/123/buys/456" 10 | body := `{ 11 | "data": { 12 | "id": "9e14d574-30fa-5d85-b02c-6be0d851d61d", 13 | "status": "created", 14 | "payment_method": { 15 | "id": "83562370-3e5c-51db-87da-752af5ab9559", 16 | "resource": "payment_method", 17 | "resource_path": "/v2/payment-methods/83562370-3e5c-51db-87da-752af5ab9559" 18 | }, 19 | "transaction": { 20 | "id": "4117f7d6-5694-5b36-bc8f-847509850ea4", 21 | "resource": "transaction", 22 | "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/transactions/441b9494-b3f0-5b98-b9b0-4d82c21c252a" 23 | }, 24 | "amount": { 25 | "amount": "10.00000000", 26 | "currency": "BTC" 27 | }, 28 | "total": { 29 | "amount": "102.01", 30 | "currency": "USD" 31 | }, 32 | "subtotal": { 33 | "amount": "101.00", 34 | "currency": "USD" 35 | }, 36 | "created_at": "2015-03-26T23:43:59-07:00", 37 | "updated_at": "2015-03-26T23:44:09-07:00", 38 | "resource": "buy", 39 | "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/buys/9e14d574-30fa-5d85-b02c-6be0d851d61d", 40 | "committed": true, 41 | "instant": false, 42 | "fee": { 43 | "amount": "1.01", 44 | "currency": "USD" 45 | }, 46 | "payout_at": "2015-04-01T23:43:59-07:00" 47 | } 48 | }` 49 | s := serverHelper(t, &method, &uri, &body) 50 | defer s.Close() 51 | 52 | a := APIClient{ 53 | Key: "123", 54 | Secret: "123456", 55 | Endpoint: s.URL, 56 | } 57 | 58 | buys, err := a.ShowBuy("123", "456") 59 | if err != nil { 60 | t.Error("Expected nil, got ", err.Error()) 61 | } 62 | if buys.Data.Id != "9e14d574-30fa-5d85-b02c-6be0d851d61d" { 63 | t.Error("Expected 9e14d574-30fa-5d85-b02c-6be0d851d61d, got ", 64 | buys.Data.Id) 65 | } 66 | 67 | wrapper := func(data interface{}) { 68 | switch r := data.(type) { 69 | case APIResource: 70 | case APIBalance: 71 | default: 72 | t.Error("Expected APIBalance or APIResource, got ", r) 73 | } 74 | } 75 | wrapper(buys.Data.Payment_method) 76 | wrapper(buys.Data.Transaction) 77 | wrapper(buys.Data.Amount) 78 | wrapper(buys.Data.Total) 79 | wrapper(buys.Data.Subtotal) 80 | 81 | if buys.Data.Created_at.Year() != 2015 { 82 | t.Error("Expected 2015, got ", buys.Data.Created_at.Year()) 83 | } 84 | if buys.Data.Updated_at.Year() != 2015 { 85 | t.Error("Expected 2015, got ", buys.Data.Created_at.Year()) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /addresses.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | import "time" 23 | 24 | /* 25 | 26 | Example Response: 27 | 28 | { 29 | "id": "dd3183eb-af1d-5f5d-a90d-cbff946435ff", 30 | "address": "mswUGcPHp1YnkLCgF1TtoryqSc5E9Q8xFa", 31 | "name": "One off payment", 32 | "created_at": "2015-01-31T20:49:02Z", 33 | "updated_at": "2015-03-31T17:25:29-07:00", 34 | "network": "bitcoin", 35 | "resource": "address", 36 | "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/addresses/dd3183eb-af1d-5f5d-a90d-cbff946435ff" 37 | } 38 | 39 | */ 40 | type APIAddressData struct { 41 | Id string 42 | Address string 43 | Name string 44 | Created_at *time.Time 45 | Updated_at *time.Time 46 | Network string 47 | Resource string 48 | Resource_path string 49 | } 50 | type APIAddresses struct { 51 | Pagination APIPagination 52 | Data []APIAddressData 53 | Errors []Error 54 | } 55 | type APIAddress struct { 56 | Data APIAddressData 57 | Errors []Error 58 | } 59 | // GetAddresses requires an address ID and returns an APIAddresses struct 60 | func (a *APIClient) GetAddresses(id string) (addresses APIAddresses, err error) { 61 | err = a.Fetch("GET", "/v2/accounts/" + id + "/addresses", nil, &addresses) 62 | if err != nil { 63 | return 64 | } 65 | return 66 | } 67 | 68 | // GetAddress requires an account ID and address ID. It will return an APIAddress struct 69 | func (a *APIClient) GetAddress(id, addressId string) (address APIAddress, err error) { 70 | err = a.Fetch("GET", "/v2/accounts/" + id + "/addresses/" + addressId, nil, &address) 71 | if err != nil { 72 | return 73 | } 74 | return 75 | } 76 | 77 | // ListAddressTransactions requires an account ID and address ID. It will return an APITransactions struct 78 | func (a *APIClient) ListAddressTransactions(id, address string) (trans APITransactions, err error) { 79 | path := "/v2/accounts/" + id + "/addresses/" + address + "/transactions" 80 | err = a.Fetch("GET", path, nil, &trans) 81 | if err != nil { 82 | return 83 | } 84 | return 85 | } 86 | 87 | // CreateAddress requires an account ID 88 | // and the address Name as parameter. 89 | // It will return an APIAddress struct 90 | func (a *APIClient) CreateAddress(id, name string) (address APIAddress, err error) { 91 | var body APIName 92 | body.Name = name 93 | err = a.Fetch("POST", "/v2/accounts/" + id + "/addresses", body, &address) 94 | if err != nil { 95 | return 96 | } 97 | return 98 | } 99 | -------------------------------------------------------------------------------- /transactions_test.go: -------------------------------------------------------------------------------- 1 | package coinbase 2 | 3 | import ( 4 | "testing" 5 | "net/http" 6 | "net/http/httptest" 7 | "fmt" 8 | ) 9 | 10 | var transactionTmpl = `{ 11 | "data": { 12 | "id": "8250fe29-f5ef-5fc5-8302-0fbacf6be51e", 13 | "type": "%s", 14 | "status": "pending", 15 | "amount": { 16 | "amount": "1.00000000", 17 | "currency": "BTC" 18 | }, 19 | "native_amount": { 20 | "amount": "10.00", 21 | "currency": "USD" 22 | }, 23 | "description": null, 24 | "created_at": "2015-03-26T13:42:00-07:00", 25 | "updated_at": "2015-03-26T15:55:45-07:00", 26 | "resource": "transaction", 27 | "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/transactions/8250fe29-f5ef-5fc5-8302-0fbacf6be51e", 28 | "%s": { 29 | "id": "5c8216e7-318a-50a5-91aa-2f2cfddfdaab", 30 | "resource": "%s", 31 | "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/%ss/5c8216e7-318a-50a5-91aa-2f2cfddfdaab" 32 | }, 33 | "instant_exchange": false, 34 | "details": { 35 | "title": "Bought/Sold bitcoin", 36 | "subtitle": "using Capital One Bank" 37 | } 38 | } 39 | }` 40 | 41 | func TestGetTransaction(t *testing.T) { 42 | var transactionTypes = []string{ 43 | "buy","sell","send","transfer","fiat_deposit", 44 | "fiat_withdrawal","exchange_deposit", 45 | "exchange_withdrawal","vault_withdrawal", 46 | } 47 | 48 | for i, transactionType := range transactionTypes { 49 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 50 | w.Header().Set("Content-Type", "application/json") 51 | fmt.Fprintln(w, fmt.Sprintf( 52 | transactionTmpl, transactionType, transactionType, 53 | transactionType, transactionType)) 54 | })) 55 | defer ts.Close() 56 | 57 | a := APIClient{ 58 | Key: "123", 59 | Secret: "123456", 60 | Endpoint: ts.URL, 61 | } 62 | 63 | transaction, err := a.GetTransaction("", "") 64 | if err != nil { 65 | t.Errorf("#%d: Expected nil, got '%+v'", i, err.Error()) 66 | } 67 | 68 | switch transactionType { 69 | case "buy": 70 | if transaction.Data.Buy == nil { 71 | t.Errorf("#%d: Expected not nil, got nil", i) 72 | } 73 | case "sell": 74 | if transaction.Data.Sell == nil { 75 | t.Errorf("#%d: Expected not nil, got nil", i) 76 | } 77 | case "send": 78 | if transaction.Data.Send == nil { 79 | t.Errorf("#%d: Expected not nil, got nil", i) 80 | } 81 | case "transfer": 82 | if transaction.Data.Transfer == nil { 83 | t.Errorf("#%d: Expected not nil, got nil", i) 84 | } 85 | case "fiat_deposit": 86 | if transaction.Data.Fiat_deposit == nil { 87 | t.Errorf("#%d: Expected not nil, got nil", i) 88 | } 89 | case "fiat_withdrawal": 90 | if transaction.Data.Fiat_withdrawal == nil { 91 | t.Errorf("#%d: Expected not nil, got nil", i) 92 | } 93 | case "exchange_deposit": 94 | if transaction.Data.Exchange_deposit == nil { 95 | t.Errorf("#%d: Expected not nil, got nil", i) 96 | } 97 | case "exchange_withdrawal": 98 | if transaction.Data.Exchange_withdrawal == nil { 99 | t.Errorf("#%d: Expected not nil, got nil", i) 100 | } 101 | case "vault_withdrawal": 102 | if transaction.Data.Vault_withdrawal == nil { 103 | t.Errorf("#%d: Expected not nil, got nil", i) 104 | } 105 | default: 106 | t.Errorf("#%d: Unknown test type", i) 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /users.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | 23 | /* 24 | 25 | Example Response: 26 | 27 | { 28 | "id": "9da7a204-544e-5fd1-9a12-61176c5d4cd8", 29 | "name": "User One", 30 | "username": "user1", 31 | "profile_location": null, 32 | "profile_bio": null, 33 | "profile_url": "https://coinbase.com/user1", 34 | "avatar_url": "https://images.coinbase.com/avatar?h=vR%2FY8igBoPwuwGren5JMwvDNGpURAY%2F0nRIOgH%2FY2Qh%2BQ6nomR3qusA%2Bh6o2%0Af9rH&s=128", 35 | "resource": "user", 36 | "resource_path": "/v2/user" 37 | } 38 | 39 | wallet:user:read permission 40 | 41 | { 42 | ... 43 | "time_zone": "Pacific Time (US & Canada)", 44 | "native_currency": "USD", 45 | "bitcoin_unit": "bits", 46 | "country": { 47 | "code": "US", 48 | "name": "United States" 49 | }, 50 | "created_at": "2015-01-31T20:49:02Z" 51 | } 52 | 53 | wallet:user:email permission 54 | 55 | { 56 | ... 57 | "email": "user1@example.com" 58 | } 59 | 60 | */ 61 | type APIUserCountry struct { 62 | Code string 63 | Name string 64 | } 65 | type APIUserData struct { 66 | Id string 67 | Name string 68 | Username string 69 | Profile_location string 70 | Profile_bio string 71 | Profile_url string 72 | Avatar_url string 73 | Resource string 74 | Resource_path string 75 | // wallet:user:read permission 76 | Time_zone string 77 | Native_currency string 78 | Bitcoin_unit string 79 | Country APIUserCountry 80 | Created_at string 81 | // wallet:user:email permission 82 | Email string 83 | } 84 | type APIUser struct { 85 | Data APIUserData 86 | Errors []Error 87 | } 88 | // GetUser requires a user ID and returns an APIUser struct 89 | func (a *APIClient) GetUser(id string) (user APIUser, err error) { 90 | err = a.Fetch("GET", "/v2/users/" + id, nil, &user) 91 | if err != nil { 92 | return 93 | } 94 | return 95 | } 96 | 97 | // GetCurrentUser returns an APIUser struct 98 | func (a *APIClient) GetCurrentUser() (user APIUser, err error) { 99 | err = a.Fetch("GET", "/v2/user", nil, &user) 100 | if err != nil { 101 | return 102 | } 103 | return 104 | } 105 | 106 | /* 107 | 108 | Example Response: 109 | 110 | { 111 | "data": { 112 | "method": "oauth", 113 | "scopes": [ 114 | "wallet:user:read", 115 | "wallet:user:email" 116 | ], 117 | "oauth_meta": {} 118 | } 119 | } 120 | 121 | */ 122 | type APIUserAuthData struct { 123 | Method string 124 | Scopes []string 125 | Oauth_meta interface{} 126 | } 127 | type APIUserAuth struct { 128 | Data APIUserAuthData 129 | } 130 | // GetCurrentUserAuth returns an APIUserAuth struct 131 | func (a *APIClient) GetCurrentUserAuth() (auth APIUserAuth, err error) { 132 | err = a.Fetch("GET", "/v2/user/auth", nil, &auth) 133 | if err != nil { 134 | return 135 | } 136 | return 137 | } 138 | 139 | // UpdateCurrentUser requires a new username and returns an APIUser struct 140 | func (a *APIClient) UpdateCurrentUser(name string) (user APIUser, err error) { 141 | var body APIName 142 | body.Name = name 143 | err = a.Fetch("PUT", "/v2/user", body, &user) 144 | if err != nil { 145 | return 146 | } 147 | return 148 | } 149 | -------------------------------------------------------------------------------- /accounts_test.go: -------------------------------------------------------------------------------- 1 | package coinbase 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestAccount(t *testing.T) { 8 | method := "GET" 9 | uri := "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede" 10 | body := `{ 11 | "data": { 12 | "id": "2bbf394c-193b-5b2a-9155-3b4732659ede", 13 | "name": "My Wallet", 14 | "primary": true, 15 | "type": "wallet", 16 | "currency": "BTC", 17 | "balance": { 18 | "amount": "39.59000000", 19 | "currency": "BTC" 20 | }, 21 | "native_balance": { 22 | "amount": "395.90", 23 | "currency": "USD" 24 | }, 25 | "created_at": "2015-01-31T20:49:02Z", 26 | "updated_at": "2015-01-31T20:49:02Z", 27 | "resource": "account", 28 | "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede" 29 | } 30 | }` 31 | s := serverHelper(t, &method, &uri, &body) 32 | defer s.Close() 33 | 34 | a := APIClient{ 35 | Key: "123", 36 | Secret: "123456", 37 | Endpoint: s.URL, 38 | } 39 | 40 | acc, err := a.Account("2bbf394c-193b-5b2a-9155-3b4732659ede") 41 | if err != nil { 42 | t.Error("Expected nil, got ", err.Error()) 43 | } 44 | account(t, acc.Data) 45 | 46 | method = "POST" 47 | uri = "/v2/accounts" 48 | acc, err = a.CreateAccount("My Wallet") 49 | if err != nil { 50 | t.Error("Expected nil, got ", err.Error()) 51 | } 52 | account(t, acc.Data) 53 | 54 | uri = "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/primary" 55 | acc, err = a.SetPrimaryAccount("2bbf394c-193b-5b2a-9155-3b4732659ede") 56 | if err != nil { 57 | t.Error("Expected nil, got ", err.Error()) 58 | } 59 | account(t, acc.Data) 60 | 61 | method = "PUT" 62 | uri = "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede" 63 | acc, err = a.UpdateAccount("2bbf394c-193b-5b2a-9155-3b4732659ede", "My Wallet") 64 | if err != nil { 65 | t.Error("Expected nil, got ", err.Error()) 66 | } 67 | account(t, acc.Data) 68 | 69 | method = "DELETE" 70 | acc, err = a.DeleteAccount("2bbf394c-193b-5b2a-9155-3b4732659ede") 71 | if err != nil { 72 | t.Error("Expected nil, got ", err.Error()) 73 | } 74 | account(t, acc.Data) 75 | } 76 | 77 | func TestAccounts(t *testing.T) { 78 | method := "GET" 79 | uri := "/v2/accounts" 80 | body := `{ 81 | "pagination": { 82 | "ending_before": null, 83 | "starting_after": null, 84 | "limit": 25, 85 | "order": "desc", 86 | "previous_uri": null, 87 | "next_uri": null 88 | }, 89 | "data": [ 90 | { 91 | "id": "2bbf394c-193b-5b2a-9155-3b4732659ede", 92 | "name": "My Vault", 93 | "primary": false, 94 | "type": "vault", 95 | "currency": "BTC", 96 | "balance": { 97 | "amount": "39.59000000", 98 | "currency": "BTC" 99 | }, 100 | "native_balance": { 101 | "amount": "395.90", 102 | "currency": "USD" 103 | }, 104 | "created_at": "2015-01-31T20:49:02Z", 105 | "updated_at": "2015-01-31T20:49:02Z", 106 | "resource": "account", 107 | "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede", 108 | "ready": true 109 | } 110 | ] 111 | }` 112 | s := serverHelper(t, &method, &uri, &body) 113 | defer s.Close() 114 | 115 | a := APIClient{ 116 | Key: "123", 117 | Secret: "123456", 118 | Endpoint: s.URL, 119 | } 120 | 121 | accs, err := a.Accounts() 122 | if err != nil { 123 | t.Error("Expected nil, got ", err.Error()) 124 | } 125 | 126 | if len(accs.Data) != 1 { 127 | t.Errorf("Expected len to be 1, got %d", len(accs.Data)) 128 | } 129 | 130 | for _, data := range accs.Data { 131 | account(t, data) 132 | } 133 | } 134 | 135 | func account(t *testing.T, acc APIAccountData) { 136 | if acc.Id != "2bbf394c-193b-5b2a-9155-3b4732659ede" { 137 | t.Error("Expected 2bbf394c-193b-5b2a-9155-3b4732659ede, got ", acc.Id) 138 | } 139 | if acc.Balance.Amount != 39.59 { 140 | t.Error("Expected 39.59, got ", acc.Balance.Amount) 141 | } 142 | if acc.Native_balance.Amount != 395.90 { 143 | t.Error("Expected 395.90, got ", acc.Native_balance.Amount) 144 | } 145 | if acc.Created_at.Year() != 2015 { 146 | t.Error("Expected 2015, got ", acc.Created_at.Year()) 147 | } 148 | if acc.Updated_at.Year() != 2015 { 149 | t.Error("Expected 2015, got ", acc.Created_at.Year()) 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /payment_methods.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | /* 23 | 24 | Example Response: 25 | 26 | { 27 | ... 28 | "limits": { 29 | "buy": [ 30 | { 31 | "period_in_days": 1, 32 | "total": { 33 | "amount": "3000.00", 34 | "currency": "USD" 35 | }, 36 | "remaining": { 37 | "amount": "3000.00", 38 | "currency": "USD" 39 | } 40 | } 41 | ], 42 | "instant_buy": [ 43 | { 44 | "period_in_days": 7, 45 | "total": { 46 | "amount": "0.00", 47 | "currency": "USD" 48 | }, 49 | "remaining": { 50 | "amount": "0.00", 51 | "currency": "USD" 52 | } 53 | } 54 | ], 55 | "sell": [ 56 | { 57 | "period_in_days": 1, 58 | "total": { 59 | "amount": "3000.00", 60 | "currency": "USD" 61 | }, 62 | "remaining": { 63 | "amount": "3000.00", 64 | "currency": "USD" 65 | } 66 | } 67 | ], 68 | "deposit": [ 69 | { 70 | "period_in_days": 1, 71 | "total": { 72 | "amount": "3000.00", 73 | "currency": "USD" 74 | }, 75 | "remaining": { 76 | "amount": "3000.00", 77 | "currency": "USD" 78 | } 79 | } 80 | ] 81 | }, 82 | } 83 | 84 | */ 85 | type APIPaymentMethodsLimitsData struct { 86 | Period_in_days int 87 | Total APIBalance 88 | Remaining APIBalance 89 | } 90 | type APIPaymentMethodsLimits struct { 91 | Buy []APIPaymentMethodsLimitsData 92 | Instant_buy []APIPaymentMethodsLimitsData 93 | Sell []APIPaymentMethodsLimitsData 94 | Deposit []APIPaymentMethodsLimitsData 95 | } 96 | 97 | /* 98 | 99 | Example Response: 100 | 101 | { 102 | "id": "83562370-3e5c-51db-87da-752af5ab9559", 103 | "type": "ach_bank_account", 104 | "name": "International Bank *****1111", 105 | "currency": "USD", 106 | "primary_buy": true, 107 | "primary_sell": true, 108 | "allow_buy": true, 109 | "allow_sell": true, 110 | "allow_deposit": true, 111 | "allow_withdraw": true, 112 | "instant_buy": false, 113 | "instant_sell": false, 114 | "created_at": "2015-01-31T20:49:02Z", 115 | "updated_at": "2015-02-11T16:53:57-08:00", 116 | "resource": "payment_method", 117 | "resource_path": "/v2/payment-methods/83562370-3e5c-51db-87da-752af5ab9559" 118 | } 119 | 120 | */ 121 | type APIPaymentMethodsData struct { 122 | ID string 123 | Type string 124 | Name string 125 | Currency string 126 | Primary_buy bool 127 | Primary_sell bool 128 | Allow_buy bool 129 | Allow_sell bool 130 | Allow_deposit bool 131 | Allow_withdraw bool 132 | Instant_buy bool 133 | Instant_sell bool 134 | Created_at string 135 | Updated_at string 136 | Resource string 137 | Resource_path string 138 | Limits APIPaymentMethodsLimits 139 | } 140 | type APIPaymentMethods struct { 141 | Pagination APIPagination 142 | Data []APIPaymentMethodsData 143 | Errors []Error 144 | } 145 | type APIPaymentMethod struct { 146 | Data APIPaymentMethodsData 147 | Errors []Error 148 | } 149 | 150 | // ListPaymentMethods returns an APIPaymentMethods struct 151 | func (a *APIClient) ListPaymentMethods() (methods APIPaymentMethods, err error) { 152 | err = a.Fetch("GET", "/v2/payment-methods", nil, &methods) 153 | if err != nil { 154 | return 155 | } 156 | return 157 | } 158 | 159 | /* 160 | 161 | Example: 162 | 83562370-3e5c-51db-87da-752af5ab9559 163 | 164 | */ 165 | type PaymentMethodId string 166 | 167 | // ListPaymentMethods returns an APIPaymentMethods struct 168 | func (a *APIClient) ShowPaymentMethod(id PaymentMethodId) (method APIPaymentMethod, err error) { 169 | path := pathHelper("/v2/payment-methods/%s", id) 170 | err = a.Fetch("GET", path, nil, &method) 171 | if err != nil { 172 | return 173 | } 174 | return 175 | } 176 | -------------------------------------------------------------------------------- /client.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | /* 21 | 22 | Package coinbase provides a simple user interface for API calls to coinbase.com. 23 | 24 | Example: 25 | 26 | c := coinbase.APIClient{ 27 | Key: "123", 28 | Secret: "123456", 29 | } 30 | acc, err := c.Accounts() 31 | if err != nil { 32 | fmt.Println(err) 33 | return 34 | } 35 | for i, acc := range accounts.Data { 36 | fmt.Printf("ID: %s\nName: %s\nType: %s\nAmount: %f\nCurrency: %s\n", 37 | acc.Id, acc.Name, acc.Type, 38 | acc.Balance.Amount, acc.Balance.Currency) 39 | } 40 | # sample output 41 | ID: 1234-12-1234-1232 42 | Name: Test Wallet 43 | Type: BTC 44 | Amount: 0.0 45 | Currency: EUR 46 | [...] 47 | 48 | */ 49 | package coinbase 50 | 51 | import ( 52 | "bytes" 53 | "fmt" 54 | "encoding/json" 55 | "net/http" 56 | "crypto/sha256" 57 | "crypto/hmac" 58 | "strconv" 59 | "io" 60 | ) 61 | 62 | const ( 63 | // ENDPOINT defaults to https://api.coinbase.com 64 | // but can be overridden for test purposes 65 | ENDPOINT = "https://api.coinbase.com" 66 | // API_VERSION since version two you have to 67 | // specify a API version in your http request headers 68 | API_VERSION = "2016-03-08" 69 | ) 70 | 71 | // APIClient is the interface for most of the API calls 72 | // If Endpoint or ApiVersion aren't defined the library 73 | // will use the default https://api.coinbase.com 74 | type APIClient struct { 75 | Key string 76 | Secret string 77 | Endpoint string 78 | ApiVersion string 79 | } 80 | 81 | // APIClientEpoch is used for decoding json "/v2/time" responses 82 | type APIClientEpoch struct { 83 | Data struct { 84 | Epoch int64 85 | } 86 | } 87 | 88 | // Fetch works as a wrapper for all kind of http requests. It requires a http method 89 | // and a relative path to the API endpoint. It will try to decode all results into 90 | // a single interface type which you can provide. 91 | func (a *APIClient) Fetch(method, path string, body interface{}, result interface{}) error { 92 | if a.Endpoint == "" { 93 | // use default endpoint 94 | a.Endpoint = ENDPOINT 95 | } 96 | if a.ApiVersion == "" { 97 | // use default api version 98 | a.ApiVersion = API_VERSION 99 | } 100 | 101 | client := &http.Client{} 102 | var bodyBuffered io.Reader 103 | if body != nil { 104 | data, err := json.Marshal(body) 105 | if err != nil { 106 | return err 107 | } 108 | bodyBuffered = bytes.NewBuffer([]byte(data)) 109 | } 110 | req, err := http.NewRequest(method, a.Endpoint + path, bodyBuffered) 111 | if err != nil { 112 | return err 113 | } 114 | 115 | req.Header.Set("Content-Type", "application/json") 116 | req.Header.Set("CB-VERSION", a.ApiVersion) 117 | // do not authenticate on public time api call 118 | if path[len(path)-4:] != "time" { 119 | err = a.Authenticate(path, req, body) 120 | if err != nil { 121 | return err 122 | } 123 | } 124 | resp, err := client.Do(req) 125 | if err != nil { 126 | return err 127 | } 128 | 129 | err = json.NewDecoder(resp.Body).Decode(result) 130 | if err != nil { 131 | return err 132 | } 133 | return nil 134 | } 135 | 136 | // Authenticate works with the Fetch call and adds certain Headers 137 | // to the http request. This includes the actual API key and the 138 | // timestamp of the request. Also a signature which is encoded 139 | // with hmac and the API secret key. 140 | func (a *APIClient) Authenticate(path string, req *http.Request, body interface{}) error { 141 | time, err := a.GetCurrentTime() 142 | if err != nil { 143 | return err 144 | } 145 | timestamp := strconv.FormatInt(time.Data.Epoch, 10) 146 | message := timestamp + req.Method + path 147 | if body != nil { 148 | bodyBytes, _ := json.Marshal(body) 149 | message += string(bodyBytes) 150 | } 151 | 152 | sha := sha256.New 153 | h := hmac.New(sha, []byte(a.Secret)) 154 | h.Write([]byte(message)) 155 | 156 | signature := fmt.Sprintf("%x", h.Sum(nil)) 157 | 158 | req.Header.Set("CB-ACCESS-KEY", a.Key) 159 | req.Header.Set("CB-ACCESS-SIGN", signature) 160 | req.Header.Set("CB-ACCESS-TIMESTAMP", timestamp) 161 | 162 | return nil 163 | } 164 | -------------------------------------------------------------------------------- /accounts.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | import "time" 23 | 24 | /* 25 | 26 | Example Response: 27 | 28 | { 29 | "id": "2bbf394c-193b-5b2a-9155-3b4732659ede", 30 | "name": "My Wallet", 31 | "primary": true, 32 | "type": "wallet", 33 | "currency": "BTC", 34 | "balance": { 35 | "amount": "39.59000000", 36 | "currency": "BTC" 37 | }, 38 | "native_balance": { 39 | "amount": "395.90", 40 | "currency": "USD" 41 | }, 42 | "created_at": "2015-01-31T20:49:02Z", 43 | "updated_at": "2015-01-31T20:49:02Z", 44 | "resource": "account", 45 | "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede" 46 | } 47 | 48 | */ 49 | type APIAccountData struct { 50 | Id string 51 | Name string 52 | Primary bool 53 | Type string 54 | Currency string 55 | Balance APIBalance 56 | Native_balance APIBalance 57 | Created_at *time.Time 58 | Updated_at *time.Time 59 | Resource string 60 | Resource_path string 61 | } 62 | type APIAccount struct { 63 | Data APIAccountData 64 | Errors []Error 65 | } 66 | // Account requires a account ID and returns and APIAccount struct 67 | func (a *APIClient) Account(id string) (account APIAccount, err error) { 68 | err = a.Fetch("GET", "/v2/accounts/" + id, nil, &account) 69 | if err != nil { 70 | return 71 | } 72 | return 73 | } 74 | 75 | /* 76 | 77 | Example Response: 78 | 79 | { 80 | "pagination": { 81 | "ending_before": null, 82 | "starting_after": null, 83 | "limit": 25, 84 | "order": "desc", 85 | "previous_uri": null, 86 | "next_uri": null 87 | }, 88 | "data": [ 89 | { 90 | "id": "58542935-67b5-56e1-a3f9-42686e07fa40", 91 | "name": "My Vault", 92 | "primary": false, 93 | "type": "vault", 94 | "currency": "BTC", 95 | "balance": { 96 | "amount": "4.00000000", 97 | "currency": "BTC" 98 | }, 99 | "native_balance": { 100 | "amount": "40.00", 101 | "currency": "USD" 102 | }, 103 | "created_at": "2015-01-31T20:49:02Z", 104 | "updated_at": "2015-01-31T20:49:02Z", 105 | "resource": "account", 106 | "resource_path": "/v2/accounts/58542935-67b5-56e1-a3f9-42686e07fa40", 107 | "ready": true 108 | }, 109 | [...] 110 | 111 | */ 112 | type APIAccounts struct { 113 | Pagination APIPagination 114 | Data []APIAccountData 115 | Errors []Error 116 | } 117 | 118 | // Accounts returns all known accounts as APIAccounts struct 119 | func (a *APIClient) Accounts() (accounts APIAccounts, err error) { 120 | err = a.Fetch("GET", "/v2/accounts", nil, &accounts) 121 | if err != nil { 122 | return 123 | } 124 | return 125 | } 126 | 127 | // CreateAccount requires an account name as parameter and returns an APIAccount struct 128 | func (a *APIClient) CreateAccount(name string) (account APIAccount, err error) { 129 | var body APIName 130 | body.Name = name 131 | err = a.Fetch("POST", "/v2/accounts", body, &account) 132 | if err != nil { 133 | return 134 | } 135 | return 136 | } 137 | 138 | // SetPrimaryAccount requires an account ID and returns an APIAccount struct 139 | func (a *APIClient) SetPrimaryAccount(id string) (account APIAccount, err error) { 140 | path := "/v2/accounts/" + id + "/primary" 141 | err = a.Fetch("POST", path, nil, &account) 142 | if err != nil { 143 | return 144 | } 145 | return 146 | } 147 | 148 | // UpdateAccount requires an account ID, Name 149 | // as parameter and returns an APIAccount struct 150 | func (a *APIClient) UpdateAccount(id, name string) (account APIAccount, err error) { 151 | path := "/v2/accounts/" + id 152 | var body APIName 153 | body.Name = name 154 | err = a.Fetch("PUT", path, body, &account) 155 | if err != nil { 156 | return 157 | } 158 | return 159 | } 160 | 161 | // DeleteAccount requires an account ID and returns an APIAccount struct 162 | func (a *APIClient) DeleteAccount(id string) (account APIAccount, err error) { 163 | path := "/v2/accounts/" + id 164 | err = a.Fetch("DELETE", path, nil, &account) 165 | if err != nil { 166 | return 167 | } 168 | return 169 | } 170 | -------------------------------------------------------------------------------- /global.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | import ( 23 | "fmt" 24 | "time" 25 | ) 26 | 27 | // AccountId is a unique ID for your wallet 28 | // 29 | // Example: 30 | // 2bbf394c-193b-5b2a-9155-3b4732659ede 31 | type AccountId string 32 | 33 | //// API Structs ///////////////// 34 | 35 | type Error struct { 36 | Id string `json:"id"` 37 | Message string `json:"message"` 38 | } 39 | 40 | type APIName struct { 41 | Name string `json:"name"` 42 | } 43 | 44 | /* 45 | 46 | Example Response: 47 | 48 | "pagination": { 49 | "ending_before": null, 50 | "starting_after": null, 51 | "limit": 25, 52 | "order": "desc", 53 | "previous_uri": null, 54 | "next_uri": null 55 | }, 56 | 57 | */ 58 | type APIPagination struct { 59 | Ending_before string 60 | Starting_after string 61 | Limit int 62 | Order string 63 | Previous_uri string 64 | Next_uri string 65 | } 66 | 67 | /* 68 | 69 | Example Response: 70 | 71 | "balance": { 72 | "amount": "39.59000000", 73 | "currency": "BTC" 74 | }, 75 | 76 | */ 77 | type APIBalance struct { 78 | Amount float64 `json:",string"` 79 | Currency string 80 | } 81 | 82 | /* 83 | 84 | Example Response: 85 | 86 | "to": { 87 | "id": "a6b4c2df-a62c-5d68-822a-dd4e2102e703", 88 | "resource": "user", 89 | "resource_path": "/v2/users/a6b4c2df-a62c-5d68-822a-dd4e2102e703" 90 | }, 91 | 92 | */ 93 | type APIResource struct { 94 | Id string 95 | Resource string 96 | Resource_path string 97 | } 98 | 99 | /* 100 | 101 | Example Response: 102 | 103 | { 104 | "id": "67e0eaec-07d7-54c4-a72c-2e92826897df", 105 | "status": "completed", 106 | "payment_method": { 107 | "id": "83562370-3e5c-51db-87da-752af5ab9559", 108 | "resource": "payment_method", 109 | "resource_path": "/v2/payment-methods/83562370-3e5c-51db-87da-752af5ab9559" 110 | }, 111 | "transaction": { 112 | "id": "441b9494-b3f0-5b98-b9b0-4d82c21c252a", 113 | "resource": "transaction", 114 | "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/transactions/441b9494-b3f0-5b98-b9b0-4d82c21c252a" 115 | }, 116 | "amount": { 117 | "amount": "1.00000000", 118 | "currency": "BTC" 119 | }, 120 | "total": { 121 | "amount": "10.25", 122 | "currency": "USD" 123 | }, 124 | "subtotal": { 125 | "amount": "10.10", 126 | "currency": "USD" 127 | }, 128 | "created_at": "2015-01-31T20:49:02Z", 129 | "updated_at": "2015-02-11T16:54:02-08:00", 130 | "resource": "buy", 131 | "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/buys/67e0eaec-07d7-54c4-a72c-2e92826897df", 132 | "committed": true, 133 | "instant": false, 134 | "fee": { 135 | "amount": "0.15", 136 | "currency": "USD" 137 | }, 138 | "payout_at": "2015-02-18T16:54:00-08:00" 139 | } 140 | 141 | */ 142 | type APIWalletTransferData struct { 143 | Id string 144 | Status string 145 | Payment_method APIResource 146 | Transaction APIResource 147 | Amount APIBalance 148 | Total APIBalance 149 | Subtotal APIBalance 150 | Created_at *time.Time 151 | Updated_at *time.Time 152 | Resource string 153 | Resource_path string 154 | Committed bool 155 | Instant bool 156 | Fee APIBalance 157 | Payout_at string 158 | } 159 | type APIWalletTransferList struct { 160 | Pagination APIPagination 161 | Data []APIWalletTransferData 162 | Errors []Error 163 | } 164 | type APIWalletTransfer struct { 165 | Data APIWalletTransferData 166 | Errors []Error 167 | } 168 | 169 | /* 170 | 171 | Example request: 172 | 173 | { 174 | "amount": "10", 175 | "currency": "BTC", 176 | "payment_method": "83562370-3e5c-51db-87da-752af5ab9559" 177 | } 178 | 179 | */ 180 | type APIWalletTransferOrder struct { 181 | Amount *float64 `json:"amount"` 182 | Total *float64 `json:"total"` 183 | Currency string `json:"currency"` 184 | Payment_method string `json:"payment_method"` 185 | Agree_btc_amount_varies bool `json:"agree_btc_amount_varies"` 186 | Commit bool `json:"commit"` 187 | Quote bool `json:"quote"` 188 | } 189 | 190 | //// Configuration Structs // 191 | 192 | type ConfigPrice struct{ 193 | From string 194 | To string 195 | Date time.Time 196 | } 197 | 198 | //// Helper Functions /////// 199 | 200 | // pathHelper is a simple wrapper for Sprintf 201 | // and exists only to reduce import expressions 202 | func pathHelper(f string, p... interface{}) string { 203 | return fmt.Sprintf(f, p...) 204 | } 205 | -------------------------------------------------------------------------------- /transactions.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Coinbase Golang API Library 3 | * 4 | * Copyright (C) 2017 Lukas Matt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | */ 19 | 20 | package coinbase 21 | 22 | /* 23 | 24 | Example Response: 25 | 26 | { 27 | "id": "57ffb4ae-0c59-5430-bcd3-3f98f797a66c", 28 | "type": "send", 29 | "status": "completed", 30 | "amount": { 31 | "amount": "-0.00100000", 32 | "currency": "BTC" 33 | }, 34 | "native_amount": { 35 | "amount": "-0.01", 36 | "currency": "USD" 37 | }, 38 | "description": null, 39 | "created_at": "2015-03-11T13:13:35-07:00", 40 | "updated_at": "2015-03-26T15:55:43-07:00", 41 | "resource": "transaction", 42 | "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/transactions/57ffb4ae-0c59-5430-bcd3-3f98f797a66c", 43 | "network": { 44 | "status": "off_blockchain", 45 | "name": "bitcoin" 46 | }, 47 | "to": { 48 | "id": "a6b4c2df-a62c-5d68-822a-dd4e2102e703", 49 | "resource": "user", 50 | "resource_path": "/v2/users/a6b4c2df-a62c-5d68-822a-dd4e2102e703" 51 | }, 52 | "instant_exchange": false, 53 | "details": { 54 | "title": "Sent bitcoin", 55 | "subtitle": "to User 2" 56 | } 57 | } 58 | 59 | */ 60 | type APITransactionsDataDetails struct { 61 | Title string 62 | Subtitle string 63 | } 64 | type APITransactionsDataNetwork struct { 65 | Status string 66 | Name string 67 | } 68 | type APITransactionsData struct { 69 | Id string 70 | Type string 71 | Status string 72 | Amount APIBalance 73 | Native_amount APIBalance 74 | Description string 75 | Created_at string 76 | Updated_at string 77 | Resource string 78 | Resource_path string 79 | Network APITransactionsDataNetwork 80 | To APIResource 81 | Buy *APIResource `json:"buy,omitempty"` 82 | Sell *APIResource `json:"sell,omitempty"` 83 | Send *APIResource `json:"send,omitempty"` 84 | Request *APIResource `json:"request,omitempty"` 85 | Transfer *APIResource `json:"transfer,omitempty"` 86 | Fiat_deposit *APIResource `json:"fiat_deposit,omitempty"` 87 | Fiat_withdrawal *APIResource `json:"fiat_withdrawal,omitempty"` 88 | Exchange_deposit *APIResource `json:"exchange_deposit,omitempty"` 89 | Exchange_withdrawal *APIResource `json:"exchange_withdrawal,omitempty"` 90 | Vault_withdrawal *APIResource `json:"vault_withdrawal,omitempty"` 91 | Instant_exchange bool 92 | Details APITransactionsDataDetails 93 | } 94 | type APITransactions struct { 95 | Pagination APIPagination 96 | Data []APITransactionsData 97 | Errors []Error 98 | } 99 | type APITransaction struct { 100 | Data APITransactionsData 101 | Errors []Error 102 | } 103 | // GetTransactions requires an account ID and returns an APITransactions struct 104 | func (a *APIClient) GetTransactions(id string) (trans APITransactions, err error) { 105 | err = a.Fetch("GET", "/v2/accounts/" + id + "/transactions", nil, &trans) 106 | if err != nil { 107 | return 108 | } 109 | return 110 | } 111 | 112 | // GetTransaction requires an account ID, transaction ID and returns an APITransaction struct 113 | func (a *APIClient) GetTransaction(id, transId string) (trans APITransaction, err error) { 114 | path := "/v2/accounts/" + id + "/transactions/" + transId 115 | err = a.Fetch("GET", path, nil, &trans) 116 | if err != nil { 117 | return 118 | } 119 | return 120 | } 121 | 122 | type APITransactionsSend struct { 123 | Type string `json:"type"` 124 | To string `json:"to"` 125 | Amount float64 `json:"amount"` 126 | Currency string `json:"currency"` 127 | Fee string `json:"fee"` 128 | } 129 | 130 | 131 | // SendTransferRequestMoney requires an account ID, APITransactionsSend struct 132 | // and returns am APITransaction struct 133 | // TODO move account ID into the APITransactionsSend struct 134 | func (a *APIClient) SendTransferRequestMoney(id string, send APITransactionsSend) (trans APITransaction, err error) { 135 | // TODO implement idem 136 | err = a.Fetch("POST", "/v2/accounts/" + id + "/transactions", send, &trans) 137 | if err != nil { 138 | return 139 | } 140 | return 141 | } 142 | 143 | // CompleteRequestMoney requires an account ID, transaction ID 144 | func (a *APIClient) CompleteRequestMoney(id, transId string) (err error) { 145 | path := "/v2/accounts/" + id + "/transactions/" + transId + "/complete" 146 | err = a.Fetch("GET", path, nil, nil) 147 | if err != nil { 148 | return 149 | } 150 | return 151 | } 152 | 153 | // ResendRequestMoney requires an account ID, transaction ID 154 | func (a *APIClient) ResendRequestMoney(id, transId string) (err error) { 155 | path := "/v2/accounts/" + id + "/transactions/" + transId + "/resend" 156 | err = a.Fetch("GET", path, nil, nil) 157 | if err != nil { 158 | return 159 | } 160 | return 161 | } 162 | 163 | // CancelRequestMoney requires an account ID, transaction ID 164 | func (a *APIClient) CancelRequestMoney(id, transId string) (err error) { 165 | path := "/v2/accounts/" + id + "/transactions/" + transId 166 | err = a.Fetch("DELETE", path, nil, nil) 167 | if err != nil { 168 | return 169 | } 170 | return 171 | } 172 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | 675 | --------------------------------------------------------------------------------