{"id":13723804,"url":"https://github.com/preichenberger/go-coinbasepro","last_synced_at":"2025-04-12T18:53:32.512Z","repository":{"id":29551344,"uuid":"33090508","full_name":"preichenberger/go-coinbasepro","owner":"preichenberger","description":"Go (golang) Client for the Coinbase Pro API https://docs.pro.coinbase.com","archived":false,"fork":false,"pushed_at":"2022-06-05T17:59:27.000Z","size":130,"stargazers_count":349,"open_issues_count":7,"forks_count":143,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-03T22:07:52.519Z","etag":null,"topics":["bitcoin","coinbase","go","trading"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/preichenberger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-29T21:40:55.000Z","updated_at":"2025-03-05T16:34:08.000Z","dependencies_parsed_at":"2022-09-07T09:10:47.628Z","dependency_job_id":null,"html_url":"https://github.com/preichenberger/go-coinbasepro","commit_stats":null,"previous_names":["preichenberger/go-coinbase-exchange","preichenberger/go-gdax"],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preichenberger%2Fgo-coinbasepro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preichenberger%2Fgo-coinbasepro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preichenberger%2Fgo-coinbasepro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preichenberger%2Fgo-coinbasepro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/preichenberger","download_url":"https://codeload.github.com/preichenberger/go-coinbasepro/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618260,"owners_count":21134200,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","coinbase","go","trading"],"created_at":"2024-08-03T01:01:45.823Z","updated_at":"2025-04-12T18:53:32.495Z","avatar_url":"https://github.com/preichenberger.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"Go Coinbase Pro [![GoDoc](http://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/preichenberger/go-coinbasepro) [![Build Status](https://travis-ci.org/preichenberger/go-coinbasepro.svg?branch=master)](https://travis-ci.org/preichenberger/go-coinbasepro)\n========\n\n## Summary\n\nGo client for [CoinBase Pro](https://pro.coinbase.com) formerly known as gdax\n\n## Installation\nIf using Go modules (Go version \u003e= 11.1) simply import as needed.\n```sh\ngo mod init github.com/yourusername/yourprojectname\n```\n\n### Older Go versions\n```sh\ngo get github.com/preichenberger/go-coinbasepro\n```\n\n### Significant releases\nUse [dep](https://github.com/golang/dep) to install previous releases\n```sh\ndep ensure --add github.com/preichenberger/go-gdax@0.5.7\n```\n\n- 0.5.7, last release before rename package to: coinbasepro\n- 0.5, as of 0.5 this library uses strings and is not backwards compatible\n\n## Documentation\nFor full details on functionality, see [GoDoc](http://godoc.org/github.com/preichenberger/go-coinbasepro) documentation.\n\n### Setup\nClient will respect environment variables: COINBASE_PRO_BASEURL, COINBASE_PRO_PASSPHRASE, COINBASE_PRO_KEY, COINBASE_PRO_SECRET by default\n\n```go\nimport (\n  coinbasepro \"github.com/preichenberger/go-coinbasepro/v2\"\n)\n\nclient := coinbasepro.NewClient()\n\n// optional, configuration can be updated with ClientConfig\nclient.UpdateConfig(\u0026coinbasepro.ClientConfig{\n  BaseURL: \"https://api.pro.coinbase.com\",\n  Key: \"coinbase pro key\",\n  Passphrase: \"coinbase pro passphrase\",\n  Secret: \"coinbase pro secret\",\n})\n```\n\n### Sandbox\nYou can switch to the sandbox URL by setting environment variable: COINBASE_PRO_SANDBOX\n\nEnable sandbox\n```sh\nexport COINBASE_PRO_SANDBOX=1\n```\n\nDisable sandbox\n```sh\nexport COINBASE_PRO_SANDBOX=0\n```\n\n\n### HTTP Settings\n```go\nimport (\n  \"net/http\"\n  \"time\"\n)\n\nclient.HTTPClient = \u0026http.Client {\n  Timeout: 15 * time.Second,\n}\n```\n\n### Decimals\nTo manage precision correctly, this library sends all price values as strings. It is recommended to use a decimal library\nlike Spring's [Decimal](https://github.com/shopspring/decimal) if you are doing any manipulation of prices.\n\nExample:\n```go\nimport (\n  \"github.com/shopspring/decimal\"\n)\n\nbook, err := client.GetBook(\"BTC-USD\", 1)\nif err != nil {\n    println(err.Error())  \n}\n\nlastPrice, err := decimal.NewFromString(book.Bids[0].Price)\nif err != nil {\n    println(err.Error())  \n}\n\norder := coinbasepro.Order{\n  Price: lastPrice.Add(decimal.NewFromFloat(1.00)).String(),\n  Size: \"2.00\",\n  Side: \"buy\",\n  ProductID: \"BTC-USD\",\n}\n\nsavedOrder, err := client.CreateOrder(\u0026order)\nif err != nil {\n  println(err.Error())\n}\n\nprintln(savedOrder.ID)\n```\n\n### Retry\nYou can set a retry count which uses exponential backoff: (2^(retry_attempt) - 1) / 2 * 1000 * milliseconds\n```\nclient.RetryCount = 3 # 500ms, 1500ms, 3500ms\n```\n\n### Cursor\nThis library uses a cursor pattern so you don't have to keep track of pagination.\n\n```go\nvar orders []coinbasepro.Order\ncursor = client.ListOrders()\n\nfor cursor.HasMore {\n  if err := cursor.NextPage(\u0026orders); err != nil {\n    println(err.Error())\n    return\n  }\n\n  for _, o := range orders {\n    println(o.ID)\n  }\n}\n\n```\n\n### Websockets\nListen for websocket messages\n\n```go\n  import(\n    ws \"github.com/gorilla/websocket\"\n  )\n\n  var wsDialer ws.Dialer\n  wsConn, _, err := wsDialer.Dial(\"wss://ws-feed.pro.coinbase.com\", nil)\n  if err != nil {\n    println(err.Error())\n  }\n\n  subscribe := coinbasepro.Message{\n    Type:      \"subscribe\",\n    Channels: []coinbasepro.MessageChannel{\n      coinbasepro.MessageChannel{\n        Name: \"heartbeat\",\n        ProductIds: []string{\n          \"BTC-USD\",\n        },\n      },\n      coinbasepro.MessageChannel{\n        Name: \"level2\",\n        ProductIds: []string{\n          \"BTC-USD\",\n        },\n      },\n    },\n  }\n  if err := wsConn.WriteJSON(subscribe); err != nil {\n    println(err.Error())\n  }\n\n  for true {\n    message := coinbasepro.Message{}\n    if err := wsConn.ReadJSON(\u0026message); err != nil {\n      println(err.Error())\n      break\n    }\n\n    println(message.Type)\n  }\n\n```\n\n### Time\nResults return coinbase time type which handles different types of time parsing that coinbasepro returns. This wraps the native go time type\n\n```go\n  import(\n    \"time\"\n    coinbasepro \"github.com/preichenberger/go-coinbasepro/v2\"\n  )\n\n  coinbaseTime := coinbasepro.Time{}\n  println(time.Time(coinbaseTime).Day())\n```\n\n### Examples\nThis library supports all public and private endpoints\n\nGet Accounts:\n```go\n  accounts, err := client.GetAccounts()\n  if err != nil {\n    println(err.Error())\n  }\n\n  for _, a := range accounts {\n    println(a.Balance)\n  }\n```\n\nList Account Ledger:\n```go\n  var ledgers []coinbasepro.LedgerEntry\n\n  accounts, err := client.GetAccounts()\n  if err != nil {\n    println(err.Error())\n  }\n\n  for _, a := range accounts {\n    cursor := client.ListAccountLedger(a.ID)\n    for cursor.HasMore {\n      if err := cursor.NextPage(\u0026ledgers); err != nil {\n        println(err.Error())\n      }\n\n      for _, e := range ledgers {\n        println(e.Amount)\n      }\n    }\n  }\n```\n\nCreate an Order:\n```go\n  order := coinbasepro.Order{\n    Price: \"1.00\",\n    Size: \"1.00\",\n    Side: \"buy\",\n    ProductID: \"BTC-USD\",\n  }\n\n  savedOrder, err := client.CreateOrder(\u0026order)\n  if err != nil {\n    println(err.Error())\n  }\n\n  println(savedOrder.ID)\n```\n\nTransfer funds:\n```go\n  transfer := coinbasepro.Transfer {\n    Type: \"deposit\",\n    Amount: \"1.00\",\n  }\n\n  savedTransfer, err := client.CreateTransfer(\u0026transfer)\n  if err != nil {\n    println(err.Error())\n  }\n```\n\nGet Trade history:\n```go\n  var trades []coinbasepro.Trade\n  cursor := client.ListTrades(\"BTC-USD\")\n\n  for cursor.HasMore {\n    if err := cursor.NextPage(\u0026trades); err != nil {\n      for _, t := range trades {\n        println(trade.CoinbaseID)\n      }\n    }\n  }\n```\n\n### Testing\nTo test with Coinbase's public sandbox set the following environment variables:\n```sh\nexport COINBASE_PRO_KEY=\"sandbox key\"\nexport COINBASE_PRO_PASSPHRASE=\"sandbox passphrase\"\nexport COINBASE_PRO_SECRET=\"sandbox secret\"\n```\n\nThen run `go test`\n```sh\ngo test\n```\n\nNote that your sandbox account will need at least 2,000 USD and 2 BTC to run the tests.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpreichenberger%2Fgo-coinbasepro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpreichenberger%2Fgo-coinbasepro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpreichenberger%2Fgo-coinbasepro/lists"}