common

package
v0.0.0-...-4c12c4a Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2019 License: MIT Imports: 28 Imported by: 0

README

GoCryptoTrader package Common

Build Status Software License GoDoc Coverage Status Go Report Card

This common package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progresss on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Current Features for common

This package collates basic broad functions that are used throughout this codebase.
  • Coding example
import "github.com/thrasher-corp/gocryptotrader/common"

testString := "aAaAa"

upper := common.StringToUpper(testString)

// upper == "AAAAA"
Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB

Documentation

Index

Constants

View Source
const (
	HashSHA1 = iota
	HashSHA256
	HashSHA512
	HashSHA512_384
	HashMD5
	SatoshisPerBTC = 100000000
	SatoshisPerLTC = 100000000
	WeiPerEther    = 1000000000000000000
)

Const declarations for common.go operations

Variables

View Source
var (
	HTTPClient *http.Client

	// ErrNotYetImplemented defines a common error across the code base that
	// alerts of a function that has not been completed or tied into main code
	ErrNotYetImplemented = errors.New("not yet implemented")

	// ErrFunctionNotSupported defines a standardised error for an unsupported
	// wrapper function by an API
	ErrFunctionNotSupported = errors.New("unsupported wrapper function")
)

Vars for common.go operations

Functions

func Base64Decode

func Base64Decode(input string) ([]byte, error)

Base64Decode takes in a Base64 string and returns a byte array and an error

func Base64Encode

func Base64Encode(input []byte) string

Base64Encode takes in a byte array then returns an encoded base64 string

func CalculateAmountWithFee

func CalculateAmountWithFee(amount, fee float64) float64

CalculateAmountWithFee returns a calculated fee included amount on fee

func CalculateFee

func CalculateFee(amount, fee float64) float64

CalculateFee returns a simple fee on amount

func CalculateNetProfit

func CalculateNetProfit(amount, priceThen, priceNow, costs float64) float64

CalculateNetProfit returns net profit

func CalculatePercentageDifference

func CalculatePercentageDifference(amount, secondAmount float64) float64

CalculatePercentageDifference returns the percentage of difference between multiple time periods

func CalculatePercentageGainOrLoss

func CalculatePercentageGainOrLoss(priceNow, priceThen float64) float64

CalculatePercentageGainOrLoss returns the percentage rise over a certain period

func ChangePerm

func ChangePerm(directory string) error

ChangePerm lists all the directories and files in an array

func CreateDir

func CreateDir(dir string) error

CreateDir creates a directory based on the supplied parameter

func EncodeURLValues

func EncodeURLValues(urlPath string, values url.Values) string

EncodeURLValues concatenates url values onto a url string and returns a string

func ExtractHost

func ExtractHost(address string) string

ExtractHost returns the hostname out of a string

func ExtractPort

func ExtractPort(host string) int

ExtractPort returns the port name out of a string

func FloatFromString

func FloatFromString(raw interface{}) (float64, error)

FloatFromString format

func GetDefaultDataDir

func GetDefaultDataDir(env string) string

GetDefaultDataDir returns the default data directory Windows - C:\Users\%USER%\AppData\Roaming\GoCryptoTrader Linux/Unix or OSX - $HOME/.gocryptotrader

func GetExecutablePath

func GetExecutablePath() (string, error)

GetExecutablePath returns the executables launch path

func GetHMAC

func GetHMAC(hashType int, input, key []byte) []byte

GetHMAC returns a keyed-hash message authentication code using the desired hashtype

func GetMD5

func GetMD5(input []byte) []byte

GetMD5 returns a MD5 hash of a byte array

func GetOSPathSlash

func GetOSPathSlash() string

GetOSPathSlash returns the slash used by the operating systems file system

func GetRandomSalt

func GetRandomSalt(input []byte, saltLen int) ([]byte, error)

GetRandomSalt returns a random salt

func GetSHA256

func GetSHA256(input []byte) []byte

GetSHA256 returns a SHA256 hash of a byte array

func GetSHA512

func GetSHA512(input []byte) []byte

GetSHA512 returns a SHA512 hash of a byte array

func GetURIPath

func GetURIPath(uri string) string

GetURIPath returns the path of a URL given a URI

func HexEncodeToString

func HexEncodeToString(input []byte) string

HexEncodeToString takes in a hexadecimal byte array and returns a string

func Int64FromString

func Int64FromString(raw interface{}) (int64, error)

Int64FromString format

func IntFromString

func IntFromString(raw interface{}) (int, error)

IntFromString format

func IsEnabled

func IsEnabled(isEnabled bool) string

IsEnabled takes in a boolean param and returns a string if it is enabled or disabled

func IsValidCryptoAddress

func IsValidCryptoAddress(address, crypto string) (bool, error)

IsValidCryptoAddress validates your cryptocurrency address string using the regexp package // Validation issues occurring because "3" is contained in litecoin and Bitcoin addresses - non-fatal

func JSONDecode

func JSONDecode(data []byte, to interface{}) error

JSONDecode decodes JSON data into a structure

func JSONEncode

func JSONEncode(v interface{}) ([]byte, error)

JSONEncode encodes structure data into JSON

func JoinStrings

func JoinStrings(input []string, separator string) string

JoinStrings joins an array together with the required separator and returns it as a string

func NewHTTPClientWithTimeout

func NewHTTPClientWithTimeout(t time.Duration) *http.Client

NewHTTPClientWithTimeout initialises a new HTTP client with the specified timeout duration

func OutputCSV

func OutputCSV(filePath string, data [][]string) error

OutputCSV dumps data into a file as comma-separated values

func ReadFile

func ReadFile(file string) ([]byte, error)

ReadFile reads a file and returns read data as byte array.

func RecvWindow

func RecvWindow(d time.Duration) int64

RecvWindow converts a supplied time.Duration to milliseconds

func RemoveFile

func RemoveFile(file string) error

RemoveFile removes a file

func ReplaceString

func ReplaceString(input, old, newStr string, n int) string

ReplaceString replaces a string with another

func RoundFloat

func RoundFloat(x float64, prec int) float64

RoundFloat rounds your floating point number to the desired decimal place

func SendHTTPGetRequest

func SendHTTPGetRequest(urlPath string, jsonDecode, isVerbose bool, result interface{}) error

SendHTTPGetRequest sends a simple get request using a url string & JSON decodes the response into a struct pointer you have supplied. Returns an error on failure.

func SendHTTPRequest

func SendHTTPRequest(method, urlPath string, headers map[string]string, body io.Reader) (string, error)

SendHTTPRequest sends a request using the http package and returns a response as a string and an error

func Sha1ToHex

func Sha1ToHex(data string) string

Sha1ToHex takes a string, sha1 hashes it and return a hex string of the result

func SplitStrings

func SplitStrings(input, separator string) []string

SplitStrings splits blocks of strings from string into a string array using a separator ie "," or "_"

func StringContains

func StringContains(input, substring string) bool

StringContains checks a substring if it contains your input then returns a bool

func StringDataCompare

func StringDataCompare(haystack []string, needle string) bool

StringDataCompare data checks the substring array with an input and returns a bool

func StringDataCompareInsensitive

func StringDataCompareInsensitive(haystack []string, needle string) bool

StringDataCompareInsensitive data checks the substring array with an input and returns a bool irrespective of lower or upper case strings

func StringDataContains

func StringDataContains(haystack []string, needle string) bool

StringDataContains checks the substring array with an input and returns a bool

func StringDataContainsInsensitive

func StringDataContainsInsensitive(haystack []string, needle string) bool

StringDataContainsInsensitive checks the substring array with an input and returns a bool irrespective of lower or upper case strings

func StringSliceDifference

func StringSliceDifference(slice1, slice2 []string) []string

StringSliceDifference concatenates slices together based on its index and returns an individual string array

func StringToLower

func StringToLower(input string) string

StringToLower changes strings to lowercase

func StringToUpper

func StringToUpper(input string) string

StringToUpper changes strings to uppercase

func TimeFromUnixTimestampFloat

func TimeFromUnixTimestampFloat(raw interface{}) (time.Time, error)

TimeFromUnixTimestampFloat format

func TrimString

func TrimString(input, cutset string) string

TrimString trims unwanted prefixes or postfixes

func UnixMillis

func UnixMillis(t time.Time) int64

UnixMillis converts a UnixNano timestamp to milliseconds

func UnixTimestampStrToTime

func UnixTimestampStrToTime(timeStr string) (time.Time, error)

UnixTimestampStrToTime returns a time.time and an error

func UnixTimestampToTime

func UnixTimestampToTime(timeint64 int64) time.Time

UnixTimestampToTime returns time.time

func WriteFile

func WriteFile(file string, data []byte) error

WriteFile writes selected data to a file and returns an error

func YesOrNo

func YesOrNo(input string) bool

YesOrNo returns a boolean variable to check if input is "y" or "yes"

Types

This section is empty.

Jump to

Keyboard shortcuts

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