goinsapi

package module
v0.0.0-...-0fb3c45 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

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()

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActiveTokenList []string

ActiveTokenList contains the tokens found under a provided ETH address

Functions

func Get24HourChange

func Get24HourChange(sym string) float64

Get24HourChange returns the 24 hour change of a coin given its ticker symbol

func GetAddressBalance

func GetAddressBalance() float32

GetAddressBalance tracks the balance of coins associated with an address In the future a map can be created to track each balance per address

func GetAddressData

func GetAddressData(addx string)

GetAddressData is a call to get all ERC-20 coins assocated with a specific ERC-20 address provided in the config file.

func GetHourChange

func GetHourChange(sym string) float64

GetHourChange returns the 1 hour change of a coin given its ticker symbol

func GetPrice

func GetPrice(sym string) float64

GetPrice returns the price of a coin given its ticket symbol

func GetTokenBalance

func GetTokenBalance(sym string) float32

GetTokenBalance returns the balance of a coin given its ticker symbol

func GetTokenChange

func GetTokenChange(sym string) float32

GetTokenChange returns the 1 hour price difference of a coin given its ticker symbol

func GetTokenImageUrl

func GetTokenImageUrl(sym string) string

GetTokenImageUrl returns the url to the token image

func GetTokenList

func GetTokenList() []string

GetTokenList returns a string array of the current tokens associated with a provided ERC-20 address

func GetTokenName

func GetTokenName(sym string) string

GetTokenName returns the friendly name of a coin given its ticker symbol

func GetTokenUrl

func GetTokenUrl(sym string) string

GetTokenUrl returns the website of a coin given its ticker symbol

func PullCoinData

func PullCoinData(yamlConfig Config)

PullCoinData accepts a basic API url/token config structure

func RefreshPrice

func RefreshPrice()

RefreshPrice is used to refresh token prices in the background

Types

type Config

type Config struct {
	Api struct {
		ApiUrl         string `yaml:"url"`
		ApiTokenHeader string `yaml:"tokenheader"`
		ApiToken       string `yaml:"token"`
		ApiAddress     string `yaml:"walletaddress"`
		ApiPort        string `yaml:"port"`
	} `yaml:"api"`
}

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!)

func GetConfigData

func GetConfigData() Config

GetConfigData Reads the API configuration from a config yaml file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL