common

package
v0.0.0-...-8bcfbc3 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: MIT Imports: 26 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.
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
	SatoshisPerBTC = 100000000
	SatoshisPerLTC = 100000000
	WeiPerEther    = 1000000000000000000
)

Const declarations for common.go operations

Variables

This section is empty.

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 EncodeURLValues

func EncodeURLValues(url 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 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 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 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 OutputCSV

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

OutputCSV dumps data into a file as comma-separated values

func ReadFile

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

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

func RemoveFile

func RemoveFile(file string) error

RemoveFile removes a file

func ReplaceString

func ReplaceString(input, old, new 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(url 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, path 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 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 StringDataContains

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

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

func StringDataContainsUpper

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

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

func StringSliceDifference

func StringSliceDifference(slice1 []string, 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 TrimString

func TrimString(input, cutset string) string

TrimString trims unwanted prefixes or postfixes

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