https://github.com/grinply/cryptoapi
implementation of a universal interface providing seamless access to trade on cryptocurrency exchanges
https://github.com/grinply/cryptoapi
crypto cryptocurrency cryptocurrency-exchanges cryptocurrency-prices golang golang-crypto trading-api
Last synced: 3 months ago
JSON representation
implementation of a universal interface providing seamless access to trade on cryptocurrency exchanges
- Host: GitHub
- URL: https://github.com/grinply/cryptoapi
- Owner: grinply
- License: mit
- Created: 2021-06-20T00:18:26.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-03-07T01:20:38.000Z (over 4 years ago)
- Last Synced: 2024-06-20T22:33:39.257Z (almost 2 years ago)
- Topics: crypto, cryptocurrency, cryptocurrency-exchanges, cryptocurrency-prices, golang, golang-crypto, trading-api
- Language: Go
- Homepage:
- Size: 99.6 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://goreportcard.com/report/github.com/grinply/universal-crypto-api)
[](/LICENSE.md)
[](https://pkg.go.dev/github.com/victorl2/kate-backtester)
# CryptoAPI
**CryptoAPI** is a interface in Golang that aims to abstract the connection with [cryptocurrency exchanges](https://coinmarketcap.com/rankings/exchanges/). The API supports both **spot** and **derivative** markets.
# Usage
First you need to install the **CryptoAPI** in your project, run `go get github.com/grinply/cryptoapi` to add the dependency.
Three main interfaces are provided with abstractions to access exchanges in a unified way. [**OrderConnector**](pkg/trade/order_connector.go) allows users to execute [**orders**](https://www.tradingpedia.com/bitcoin-guide/what-types-of-orders-to-trade-bitcoin-on-crypto-exchanges-are-there/) and access private information _(such as asset balances)_:
```go
package trade
type OrderConnector interface {
FindOrderByID(tradingPair CurrencyPair, orderID string) (Order, error)
OpenOrders(tradingPair CurrencyPair) ([]Order, error)
NewOpenOrder(orderToOpen Order) (string, error)
CancelOrder(tradingPair CurrencyPair, orderID string) error
CancelOpenOrders(tradingPair CurrencyPair) error
}
```
The [**PriceConnector**](pkg/trade/price_connector.go) provides access to **price data** without the need for authentication:
```go
type PriceConnector interface {
LatestPrice(tradingPair CurrencyPair) (string, error)
Candles(tradingPair CurrencyPair, qty int, interval CandleInterval)
([]CandleStick, error)
PriceFeed(tradingPair CurrencyPair) <-chan CandleStick
}
```
The [**InfoConnector**](pkg/trade/info_connector.go) provides access to **general exchange information** about what is avaliable
```go
type InfoConnector interface {
TradingPairs() ([]CurrencyPair, error)
TradingRules(tradingPair CurrencyPair) (Rule, error)
CoinsBalance() ([]Asset, error)
}
```
To make use of both connectors you just need to provide the required information to a function, a implementation for the requested exchange will be provided for your use:
```go
package main
import (
"fmt"
"github.com/grinply/cryptoapi"
)
func main() {
//replace the keys with your own values.
var apiKey = "my_api_key"
var secretKey = "my_secret_key"
var exchange = "binance"
connector, err := cryptoapi.OrderConnector(exchange, apiKey, secretKey, false)
if err != nil {
fmt.Printf("Connector failed with the provided credentials.%v\n", err.Error())
return
}
//Print the amount of each asset present in the exchange wallet
if assetsBalance, err := connector.WalletBalances(); err == nil {
for _, asset := range assetsBalance {
fmt.Printf("%s - available: %s | locked: %s\n",
asset.Name, asset.FreeQty, asset.LockedQty)
}
}
}
```
[_More info about **examples** using the CryptoAPI_](docs/)