Skip to content

implementation of a universal interface providing seamless access to trade on cryptocurrency exchanges

License

Notifications You must be signed in to change notification settings

grinply/cryptoapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Report Card Software License Go Reference

CryptoAPI

CryptoAPI is a interface in Golang that aims to abstract the connection with cryptocurrency 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 allows users to execute orders and access private information (such as asset balances):

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 provides access to price data without the need for authentication:

type PriceConnector interface {
	LatestPrice(tradingPair CurrencyPair) (string, error)

	Candles(tradingPair CurrencyPair, qty int, interval CandleInterval) 
        ([]CandleStick, error)

	PriceFeed(tradingPair CurrencyPair) <-chan CandleStick
}

The InfoConnector provides access to general exchange information about what is avaliable

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:

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

About

implementation of a universal interface providing seamless access to trade on cryptocurrency exchanges

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages