Categorygithub.com/FlipTheDream/goinsapi
modulepackage
0.0.0-20211107171518-0fb3c45f0c0f
Repository: https://github.com/flipthedream/goinsapi.git
Documentation: pkg.go.dev

# README

Go Coin API

goinsapi modue

This module provides a basic api module for for gathering coinbase information. The initial idea is to add coinbase support and build it up to pull from additional REST/API end points.

TODO:
[X] - Pull data from https://api.ethplorer.io/ to grap coin balances
[X] - Create a service that utilized goapi and refreshes prices and gets balances on demand
[X] - Implement a API server to return portfolio balance based on POST addx
[ ] - Create a containerized microservice
[ ] - Setup a database backend
[X] - Refactor the Token struct to include the getters into the struct ( Not going to add redundant functions for each function. Marking as done.)
[ ] - Update preceision by utilizing a decimal library such as https://github.com/shopspring/decimal.

It utilizes a yaml config file that constains the following:

Configuration for Coinmarketcap

api: url: "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest" tokenheader: "X-CMC_PRO_API_KEY" token: "YOUR-API-TOKEN-HERE" walletaddress: "0xBB980a1Bf6eCaaA49A6901302E97DA2C6B9dCDbe"

Update config.yml.sample with YOUR-API-TOKEN as needed and rename it to config.yml.

The following functions are provided

  • As part of initialization you should set a config variable ex: var CMCApi = goapi.GetConfigData() it returns a yamlConfig type for using when pulling data.
  • PullCoinData(yamlConfig Config) is the call to pull data from coinmarketcap.
  • GetPrice(sym string) - Accepts a ticker symbol and returns the current price as a float64.
  • GetHourChange(sym string) Accepts a ticker symbol and returns the 1 hour percent change as a float64.
  • Get24HourChange(sym string) Accepts a ticker symbol and returns the 24 hour percent change as a float64.

Example usage

package main

import (
	"fmt"
	//"goapi"
	"git.local.jnet/wendell/goapi"
)

func main() {
	// Initialize the application with configuration data
	var CMCApi = goapi.GetConfigData()

	// Call to Pull Coin Data from API servers
	goapi.PullCoinData(CMCApi)

    // Call to get tokens associated with the provided ETH addx
	goapi.GetAddressData(CMCApi)

    // Assign the array of ticker symbols assocated with the tokens in the ETH addx records
	var tokens []string = goapi.GetTokenList()

License: GPL v3 GitHub all releases GitHub release (latest by date including pre-releases) GitHub go.mod Go version GitHub last commit GitHub issues Go Report Card

# Functions

Get24HourChange returns the 24 hour change of a coin given its ticker symbol.
GetAddressBalance tracks the balance of coins associated with an address In the future a map can be created to track each balance per address .
GetAddressData is a call to get all ERC-20 coins assocated with a specific ERC-20 address provided in the config file.
GetConfigData Reads the API configuration from a config yaml file.
GetHourChange returns the 1 hour change of a coin given its ticker symbol.
GetPrice returns the price of a coin given its ticket symbol.
GetTokenBalance returns the balance of a coin given its ticker symbol.
GetTokenChange returns the 1 hour price difference of a coin given its ticker symbol.
GetTokenImageUrl returns the url to the token image .
GetTokenList returns a string array of the current tokens associated with a provided ERC-20 address.
GetTokenName returns the friendly name of a coin given its ticker symbol.
GetTokenUrl returns the website of a coin given its ticker symbol.
PullCoinData accepts a basic API url/token config structure.
RefreshPrice is used to refresh token prices in the background.

# Variables

ActiveTokenList contains the tokens found under a provided ETH address.

# Structs

Config structure provides a simple structure for the CMC API url - The url for the API tokenheader - The API token header syntax used to authenticate token - The actual secret token (This should be protected!).