Giter Club home page Giter Club logo

go-xrate's Introduction

Go-xrate (Unmaintained!!!)

Go Report Card

Small Golang implementation for fetching cryptocurrency rates from several Exchanges around the world.

Released under the terms of the MIT LICENSE.

Installation

To install, just run

go get github.com/swipecoin/go-xrate

Usage

BTC -> USDT (Binance)

crawler, _ := xrate.NewBTCCrawler(
    currency.Real(), 
    exchanges.Binance(),
)
	
// Here we are fetching the rates with a 5 second timeout for each request 
r := crawler.Rates(time.Second * 5)

// r[0] -> response from Binance
fmt.Println(
    r[0].Exchange,
    r[0].CryptoCurrency,
    r[0].FiatCurrency,
    r[0].Last,
    r[0].High24h,
    r[0].Low24h,
    r[0].Volume24h,
    r[0].VolumeFiat24h,
    r[0].MostRecentBidOrder,
    r[0].MostRecentAskOrder,
    r[0].CreatedAt,
)

BTC -> BRL (BitcoinTrade + Foxbit + Mercado Bitcoin)

crawler, _ := xrate.NewBTCCrawler(
    currency.Real(), 
    exchanges.BitcoinTrade(),
    exchanges.Foxbit(),
    exchanges.MercadoBitcoin(),
)
	
// Here we are fetching the rates with a 5 second timeout for each request 
r := crawler.Rates(time.Second * 5)

// r[0] -> response from BitcoinTrade
fmt.Println(
    r[0].Exchange,
    r[0].CryptoCurrency,
    r[0].FiatCurrency,
    r[0].Last,
    r[0].High24h,
    r[0].Low24h,
    r[0].Volume24h,
    r[0].VolumeFiat24h,
    r[0].MostRecentBidOrder,
    r[0].MostRecentAskOrder,
    r[0].CreatedAt,
    r[0].Error,
)

// r[1] -> response from Foxbit
fmt.Println(
    r[1].Exchange,
    r[1].CryptoCurrency,
    r[1].FiatCurrency,
    r[1].Last,
    r[1].High24h,
    r[1].Low24h,
    r[1].Volume24h,
    r[1].VolumeFiat24h,
    r[1].MostRecentBidOrder,
    r[1].MostRecentAskOrder,
    r[1].CreatedAt,
    r[1].Error,
)

// r[2] -> response from Mercado Bitcoin
fmt.Println(
    r[2].Exchange,
    r[2].CryptoCurrency,
    r[2].FiatCurrency,
    r[2].Last,
    r[2].High24h,
    r[2].Low24h,
    r[2].Volume24h,
    r[2].VolumeFiat24h,
    r[2].MostRecentBidOrder,
    r[2].MostRecentAskOrder,
    r[2].CreatedAt,
    r[2].Error,
)

API

NewBTCCrawler(currency.Currency, ...exchanges.Exchange) (exchanges.Crawler, error)

This is used to create new crypto crawler. It expects a fiatCurrency and the exchanges you want to fetch.

PS: It will return a error if you pass it a exchange that does not support Bitcoin or the given fiat currency.

(exchanges.Crawler) Rates(time.Duration) ([]CrawlerResponse)

This is the method used to fetch the rates for the exchanges passed on the previous method. It receives a timeout and returns a list of responses, one for each exchange.

The library uses goroutines for every api call. So the total duration is equal to the slowest Exchange API response time at that moment.

PS: If a specific exchange does not support some field, it will return -1 instead.

Supported Exchanges

As of now, only a few exchanges are supported. But the code is prepared to work with multiple countries, fiat currencies and cryptocurrencies.

Here's the currently supported list:

Foxbit - CURRENTLY NOT WORKING (Due to new API)

Fiat currencies:

  • Real

Cryptocurrencies:

  • BTC

Fiat currencies:

  • Real

Cryptocurrencies:

  • BTC

Fiat currencies:

  • Real

Cryptocurrencies:

  • BTC

Fiat currencies:

  • Real

Cryptocurrencies:

  • BTC

Fiat currencies:

  • Tether

Cryptocurrencies:

  • BTC

TODO

  • Report badge
  • Implement Foxbit new API
  • Improve unit tests
  • Support more Exchanges
  • Better error handling
  • Other useful statistics from a specific cryptocurrency and/or exchange

Contribution

Please feel free to contribute with both suggestions and pull requests :D

go-xrate's People

Contributors

edunuzzi avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

simhaonline

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.