Skip to content

A client library for interacting with the coincap.io V2 api

License

Notifications You must be signed in to change notification settings

solipsis/coincapV2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

coincapV2 api golang

coincapV2

GoDoc Go Report Card

client library for interacting with the coincap.io V2 api

Installation

go get -u github.com/solipsis/coincapV2/...

Usage

import "github.com/solipsis/coincapV2/pkg/coincap"

GoDoc: https://godoc.org/github.com/solipsis/coincapV2/pkg/coincap

Official API Docs

https://docs.coincap.io/

Examples

Get Market Data

client := coincap.NewClient(nil)

params := &MarketsRequest{
	ExchangeID:  "binance",
	BaseSymbol:  "ETH",
	QuoteSymbol: "BTC",
	Limit:       100,
	Offset:      0,
}
markets, timestamp, err := client.Markets(params)

Get Data for an Asset

client := coincap.NewClient(nil)

params := &AssetsRequest{
	Search: "BTC",
	Limit:  4,
	Offset: 1,
}
assets, timestamp, err := client.Assets(params)

Get Historical Data for an Asset

client := coincap.NewClient(nil)

// setup the time range
end := time.Now()
start := now.Add(-time.Hour * 2)

params := &coincap.AssetHistoryRequest{
	Interval: coincap.FifteenMinutes,
	Start:    &coincap.Timestamp{Time: start},
	End:      &coincap.Timestamp{Time: end},
}
history, timestamp, err := client.AssetHistoryByID("bitcoin", params)
if err != nil {
	log.Fatal(err)
}

Get Rates of Various Currencies to USD

client := coincap.NewClient(nil)

rates, timestamp, err := client.Rates()
if err != nil {
	t.Fatal(err)
}

/*
Example response
{
  "data": [
    {
      "id": "barbadian-dollar",
      "symbol": "BBD",
      "currencySymbol": "$",
      "type": "fiat",
      "rateUsd": "0.5000000000000000"
    },
    {
      "id": "malawian-kwacha",
      "symbol": "MWK",
      "currencySymbol": "MK",
      "type": "fiat",
      "rateUsd": "0.0013750106599420"
    },
    {
      "id": "south-african-rand",
      "symbol": "ZAR",
      "currencySymbol": "R",
      "type": "fiat",
      "rateUsd": "0.0657544075508153"
    }],
}

Get USD Rates by Asset ID

client := coincap.NewClient(nil)

rate, timestamp, err := client.RateByID("bitcoin")

Get Information on Exchanges

client := coincap.NewClient(nil)

exchanges, timestamp, err := client.Exchanges()
if err != nil {
	t.Fatal(err)
}

Get Exchange Information by ID

client := coincap.NewClient(nil)

exchange, timestamp, err := client.ExchangeByID("gdax")
if err != nil {
	t.Fatal(err)
}

Get Candle Data

client := coincap.NewClient(nil)

params := &CandlesRequest{
	ExchangeID: "poloniex",
	BaseID:     "ethereum",
	QuoteID:    "bitcoin",
	Limit:      100,
	Offset:     1,
	Interval:   coincap.FiveMinutes,
}
candles, timestamp, err := client.Candles(params)
if err != nil {
	t.Fatal(err)
}

TODO

  • Implement websocket endpoints

Contributing

Contributions and pull requests welcome

About

A client library for interacting with the coincap.io V2 api

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages