Documentation
¶
Index ¶
- Constants
- func AfterDay(date1, date2 time.Time) bool
- func Average(series []float64) (average float64)
- func CheckDuplicates(arr []string) bool
- func CheckWeekDay(date time.Time) bool
- func CloseHTTPResp(resp *http.Response)
- func ComputeMedian(samples []float64) (median float64)
- func Contains(s *[]string, str string) bool
- func ContainsDay(s []time.Time, date time.Time) bool
- func CopyBytes(data []byte) []byte
- func CountDays(dateInit, dateFinal time.Time, business bool) (days int, err error)
- func DiscardOutliers(prices []float64, volumes []float64, basispoints float64) (newPrices []float64, newVolumes []float64, discarded []int, err error)
- func DownloadResource(path, url string) (err error)
- func GenerateAutoname(delimiter string) string
- func GetCoinPrice(coin string) (float64, error)
- func GetGraphqlAssetQuotationFromDia(blockchain, address string, blockDuration int) (float64, error)
- func GetHolidays(workdays []time.Time, dateInit, dateFinal time.Time) []time.Time
- func GetRequest(url string) ([]byte, int, error)
- func GetRequestWithStatus(url string) ([]byte, int, error)
- func GetSigner(chainID, creator, oracleaddress, message, signed string) (common.Address, error)
- func GetTimeDurationFromIntAsMilliseconds(input int) time.Duration
- func GetTomorrow(date, layout string) string
- func GetYesterday(date, layout string) string
- func Getenv(key, fallback string) string
- func GetenvBool(key string, fallback bool) bool
- func GetenvInt(key string, fallback int) int
- func GetenvUint(key string, fallback uint) uint
- func GraphQLGet(url string, query []byte, bearer string) ([]byte, int, error)
- func HTTPRequest(request *http.Request) (body []byte, statusCode int, err error)
- func Has0xPrefix(str string) bool
- func HexDecode(s string) ([]byte, error)
- func IsEnvExist(key string) bool
- func IsInBin(timestamp time.Time, bin TimeBin) bool
- func MakeTimeRanges(timeInit, timeFinal time.Time, numRanges int) (starttimes, endtimes []time.Time)
- func MakeTimerange(starttimeString string, endtimeString string, timeRange time.Duration) (starttime time.Time, endtime time.Time, err error)
- func MaxString(sl []string) (string, int64)
- func Min(n1 uint64, n2 uint64) uint64
- func MinString(sl []string) (string, int64)
- func NewKeyPair() (publickey, privatekey string)
- func OpenseaGetRequest(OpenseaURL string) ([]byte, int, error)
- func PostRequest(url string, body io.Reader) ([]byte, error)
- func SameDays(date1, date2 time.Time) bool
- func SliceDifference(slice1, slice2 []string) []string
- func StandardDeviation(series []float64) float64
- func StrToUnixtime(s string) (t time.Time, err error)
- func StringToFloat64(value string, decimals int64) (float64, bool)
- func TypedDataAndHash(typedData TypedData) ([]byte, string, error)
- func UniV2AmountOut(amountIn float64, reserveIn float64, reserveOut float64) (float64, error)
- func UniV2PriceAfterTrade(amountIn float64, reserveIn float64, reserveOut float64) (price float64, err error)
- func UniV2PriceReserveIn(reserveIn float64, reserveOut float64) (float64, error)
- func UniqueStrings(s []string) []string
- func ValidTimeRange(starttime time.Time, endtime time.Time, maxDuration time.Duration) (ok bool)
- func Variance(series []float64) (variance float64)
- func VerifyTypedData(primaryType string, domain TypedDataDomain, types Types, ...) (common.Address, error)
- func Vwap(prices []float64, volumes []float64) (float64, error)
- type ArgsortableSlice
- type AssetQuotationSigner
- type CoinMarketCap
- type Coingecko
- type EthFilteredTx
- type EthTxFilterCriteria
- type EthTxFilterResult
- type ExternalDataSoure
- type NameValueType
- type RandomnessSigner
- type TimeBin
- type Type
- type TypePriority
- type TypedData
- func (typedData *TypedData) Dependencies(primaryType string, found []string) []string
- func (typedData *TypedData) EncodeData(primaryType string, data map[string]interface{}, depth int) (hexutil.Bytes, error)
- func (typedData *TypedData) EncodePrimitiveValue(encType string, encValue interface{}, depth int) ([]byte, error)
- func (typedData *TypedData) EncodeType(primaryType string) hexutil.Bytes
- func (typedData *TypedData) Format() ([]*NameValueType, error)
- func (typedData *TypedData) HashStruct(primaryType string, data TypedDataMessage) (hexutil.Bytes, error)
- func (typedData *TypedData) Map() map[string]interface{}
- func (typedData *TypedData) TypeHash(primaryType string) hexutil.Bytes
- type TypedDataDomain
- type TypedDataMessage
- type Types
Constants ¶
const (
UNIV2_FEE_FACTOR = 997
UNIV2_FACTOR = 1000
)
Variables ¶
This section is empty.
Functions ¶
func AfterDay ¶
func AfterDay(date1, date2 time.Time) bool
AfterDay returns true if date1 is a date after date2, irrespective of the daytime. The go method "After" respects daytime.
func Average ¶ added in v1.4.2
func Average(series []float64) (average float64)
Average returns the average of @samples.
func CheckDuplicates ¶ added in v1.4.224
func CheckDuplicates(arr []string) bool
func CheckWeekDay ¶
func CheckWeekDay(date time.Time) bool
CheckWeekDay returns true if @date is not weekend and false otherwise.
func CloseHTTPResp ¶ added in v1.2.0
func CloseHTTPResp(resp *http.Response)
CloseHTTPResp is a wrapper for closing http response bodies while complying with the linter.
func ComputeMedian ¶ added in v1.4.2
func ComputeMedian(samples []float64) (median float64)
ComputeMedian returns the median of @samples.
func Contains ¶
func Contains(s *[]string, str string) bool
Contains takes a slice of strings and a string and checks if it is contained in the slice.
func ContainsDay ¶
func ContainsDay(s []time.Time, date time.Time) bool
ContainsDay returns true if day @date is contained in slice @s, independent of the daytime. As a consequence, be cautious when comparing days in different timezones.
func CountDays ¶
func CountDays(dateInit, dateFinal time.Time, business bool) (days int, err error)
CountDays returns the number of days between @dateInit and @dateFinal, both given as converted from a string in the format yyyy-mm-dd, excluding the last day. @bool If true only business days are counted.
func DiscardOutliers ¶ added in v1.4.2
func DiscardOutliers(prices []float64, volumes []float64, basispoints float64) (newPrices []float64, newVolumes []float64, discarded []int, err error)
DiscardOutliers discards every data point from @prices and @volumes that deviates from the price median by more than @basispoints basis points.
func DownloadResource ¶
func DownloadResource(path, url string) (err error)
DownloadResource is a simple utility that downloads a resource from @url and stores it into @filepath.
func GenerateAutoname ¶ added in v1.4.94
func GenerateAutoname(delimiter string) string
Generate returns a random name from the list of adjectives, colors and surnames.
func GetCoinPrice ¶
func GetCoinPrice(coin string) (float64, error)
GetCoinPrice Gets the price in USD of coin through our API. Looks it up on coingecko in case it doesn't find it there.
func GetGraphqlAssetQuotationFromDia ¶ added in v1.4.488
func GetGraphqlAssetQuotationFromDia(blockchain, address string, blockDuration int) (float64, error)
func GetHolidays ¶
func GetHolidays(workdays []time.Time, dateInit, dateFinal time.Time) []time.Time
GetHolidays returns "holidays" as non-weekend complement of given days @workdays
func GetRequest ¶
func GetRequest(url string) ([]byte, int, error)
GetRequest performs a get request on @url and returns the response body as a slice of byte data.
func GetRequestWithStatus ¶ added in v1.2.0
func GetRequestWithStatus(url string) ([]byte, int, error)
GetRequest performs a get request on @url and returns the response body as a slice of byte data.
func GetSigner ¶ added in v1.4.46
func GetSigner(chainID, creator, oracleaddress, message, signed string) (common.Address, error)
func GetTimeDurationFromIntAsMilliseconds ¶ added in v1.4.504
func GetTimeDurationFromIntAsMilliseconds(input int) time.Duration
func GetTomorrow ¶
func GetTomorrow(date, layout string) string
GetTomorrow returns the day before @date in the world of strings, formatted as @layout
func GetYesterday ¶
func GetYesterday(date, layout string) string
GetYesterday returns the day before @date in the world of strings, formatted as @layout
func GetenvBool ¶ added in v1.4.504
func GetenvBool(key string, fallback bool) bool
func GetenvUint ¶ added in v1.4.504
func GetenvUint(key string, fallback uint) uint
func GraphQLGet ¶
func GraphQLGet(url string, query []byte, bearer string) ([]byte, int, error)
GraphQLGet returns the body of the result of a graphQL GET query. @url is the base url of the graphQL API @query is a byte slice representing the graphQL query message @bearer contains the API key if present
func HTTPRequest ¶ added in v1.2.0
func HTTPRequest(request *http.Request) (body []byte, statusCode int, err error)
HTTPRequest returns the request body and defers the closing compliant to linting.
func Has0xPrefix ¶ added in v1.4.43
func Has0xPrefix(str string) bool
func IsEnvExist ¶ added in v1.2.0
func IsEnvExist(key string) bool
func IsInBin ¶ added in v1.4.113
func IsInBin(timestamp time.Time, bin TimeBin) bool
IsInBin returns true in case @timestamp is in half-open interval @bin.
func MakeTimeRanges ¶ added in v1.4.2
func MakeTimeRanges(timeInit, timeFinal time.Time, numRanges int) (starttimes, endtimes []time.Time)
MakeTimeRanges returns @numRanges start- and endtimes partitioning [@timeInit, @timeFinal] in intervals of identical size.
func MakeTimerange ¶ added in v1.4.2
func MakeTimerange(starttimeString string, endtimeString string, timeRange time.Duration) (starttime time.Time, endtime time.Time, err error)
MakeTimerange parses Unix timestamps given as strings. In case one of the two is empty, it returns a time-range based on @timeRange. Default is a 24h window ending now.
func MaxString ¶
func MaxString(sl []string) (string, int64)
MaxString return the maximum of a slice of strings along with its index
func MinString ¶
func MinString(sl []string) (string, int64)
MinString return the maximum of a slice of strings along with its index
func NewKeyPair ¶ added in v1.4.43
func NewKeyPair() (publickey, privatekey string)
func OpenseaGetRequest ¶ added in v1.2.0
func OpenseaGetRequest(OpenseaURL string) ([]byte, int, error)
OpenseaGetRequest returns the data for a get request on @url with an Opensea API key.
func PostRequest ¶
func PostRequest(url string, body io.Reader) ([]byte, error)
PostRequest performs a POST request on @url and returns the response body as a slice of byte data.
func SameDays ¶
func SameDays(date1, date2 time.Time) bool
SameDays returns true if @date1 is the same date as @date2, independent of the daytime.
func SliceDifference ¶
func SliceDifference(slice1, slice2 []string) []string
SliceDifference returns the elements in @slice1 that aren't in @slice2.
func StandardDeviation ¶ added in v1.4.2
func StandardDeviation(series []float64) float64
func StrToUnixtime ¶
func StrToUnixtime(s string) (t time.Time, err error)
StrToUnixtime converts a string corresponding to an int to Unix time
func StringToFloat64 ¶ added in v1.4.504
func StringToFloat64(value string, decimals int64) (float64, bool)
func TypedDataAndHash ¶ added in v1.4.43
func TypedDataAndHash(typedData TypedData) ([]byte, string, error)
TypedDataAndHash is a helper function that calculates a hash for typed data conforming to EIP-712. This hash can then be safely used to calculate a signature.
See https://eips.ethereum.org/EIPS/eip-712 for the full specification.
This gives context to the signed typed data and prevents signing of transactions.
func UniV2AmountOut ¶ added in v1.4.65
func UniV2AmountOut(amountIn float64, reserveIn float64, reserveOut float64) (float64, error)
func UniV2PriceAfterTrade ¶ added in v1.4.65
func UniV2PriceAfterTrade(amountIn float64, reserveIn float64, reserveOut float64) (price float64, err error)
func UniV2PriceReserveIn ¶ added in v1.4.65
func UniV2PriceReserveIn(reserveIn float64, reserveOut float64) (float64, error)
func UniqueStrings ¶
func UniqueStrings(s []string) []string
UniqueStrings returns a subslice of @s such that each entry only appears once
func ValidTimeRange ¶ added in v1.4.138
func ValidTimeRange(starttime time.Time, endtime time.Time, maxDuration time.Duration) (ok bool)
ValidTimeRange returns true if the interval [@starttime, @endtime] is at most @maxDuration.
func VerifyTypedData ¶ added in v1.4.43
func VerifyTypedData(primaryType string, domain TypedDataDomain, types Types, message TypedDataMessage, signature []byte) (common.Address, error)
Types ¶
type ArgsortableSlice ¶ added in v1.2.0
type ArgsortableSlice struct {
sort.Interface
// contains filtered or unexported fields
}
ArgsortableSlice is a wrapper struct around the sort interface. It allows for implemetation of argsort for all sortable types.
func NewFloat64Slice ¶ added in v1.2.0
func NewFloat64Slice(sf sort.Float64Slice) *ArgsortableSlice
NewFloat64Slice returns the wrapped float64slice that can be argsorted.
type AssetQuotationSigner ¶ added in v1.4.171
type AssetQuotationSigner struct {
// contains filtered or unexported fields
}
func NewAssetQuotationSigner ¶ added in v1.4.171
func NewAssetQuotationSigner(privateKey string) *AssetQuotationSigner
type CoinMarketCap ¶ added in v1.4.414
type CoinMarketCap struct {
// contains filtered or unexported fields
}
func NewCoinMarketCapProvider ¶ added in v1.4.414
func NewCoinMarketCapProvider(apiKey string, assetsMapping map[string]string) *CoinMarketCap
type Coingecko ¶ added in v1.4.414
type Coingecko struct {
// contains filtered or unexported fields
}
func NewCoinGeckoProvider ¶ added in v1.4.414
func NewCoinGeckoProvider(apiKey string, assetsMapping map[string]string) *Coingecko
type EthFilteredTx ¶ added in v1.2.0
type EthFilteredTx struct {
BlockNum uint64
BlockHash common.Hash
TXIndex uint
TXHash common.Hash
Logs []types.Log // list of matched log records if Events or EvAddrs were used, otherwise all logs of the transaction
}
EthFilteredTx holds limited info for found transactions
type EthTxFilterCriteria ¶ added in v1.2.0
type EthTxFilterCriteria struct {
StartBlockNum uint64 // inclusive. filter transactions from the specific block
StartTxIndex uint // inclusive. filter transactions from specific index in the given StartBlockNum
LimitBlocks int // filter transactions in the specific number of blocks, zero means up to highest possible block
BehindHighestBlock int // stay behind the highest synched block if StartBlockNum+LimitBlocks in excess of the head
EvAddrs []common.Address // list of addresses from which transaction events should originate
Events []common.Hash // list of events from which transactions should contain
}
EthTxFilterCriteria used for filtering transaction records
type EthTxFilterResult ¶ added in v1.2.0
type EthTxFilterResult struct {
Synced bool // it means the most recent inspected block matches the highest known block (see BehindHighestBlock)
NumBlocks int // number of blocks found
NumTXs int // number of transactions found
NumLogs int // number of log records found
TXs []*EthFilteredTx // list of found transactions
LastBlockNum uint64 // block number of most recent transaction inspected
}
EthTxFilterResult describes filter results and holds found transactions
func EthFilterTXs ¶ added in v1.2.0
func EthFilterTXs(ctx context.Context, ethClient *ethclient.Client, filter EthTxFilterCriteria) (*EthTxFilterResult, error)
EthFilterTXs returns transactions filtered by log records
type ExternalDataSoure ¶ added in v1.4.414
type ExternalDataSoure interface {
Price(string) (float64, error)
}
type NameValueType ¶ added in v1.4.43
type NameValueType struct {
Name string `json:"name"`
Value interface{} `json:"value"`
Typ string `json:"type"`
}
NameValueType is a very simple struct with Name, Value and Type. It's meant for simple json structures used to communicate signing-info about typed data with the UI
type RandomnessSigner ¶ added in v1.4.411
type RandomnessSigner struct {
// contains filtered or unexported fields
}
func NewRandomnessSigner ¶ added in v1.4.411
func NewRandomnessSigner(privateKey string) *RandomnessSigner
type Type ¶ added in v1.4.43
type Type struct {
Name string `json:"name"`
Type string `json:"type"`
}
Type is the inner type of an EIP-712 message
type TypePriority ¶ added in v1.4.43
type TypePriority struct {
Type string
Value uint
}
type TypedData ¶ added in v1.4.43
type TypedData struct {
Types Types `json:"types"`
PrimaryType string `json:"primaryType"`
Domain TypedDataDomain `json:"domain"`
Message TypedDataMessage `json:"message"`
}
func (*TypedData) Dependencies ¶ added in v1.4.43
func (typedData *TypedData) Dependencies(primaryType string, found []string) []string
Dependencies returns an array of custom types ordered by their hierarchical reference tree
func (*TypedData) EncodeData ¶ added in v1.4.43
func (typedData *TypedData) EncodeData(primaryType string, data map[string]interface{}, depth int) (hexutil.Bytes, error)
EncodeData generates the following encoding: `enc(value₁) ‖ enc(value₂) ‖ … ‖ enc(valueₙ)`
each encoded member is 32-byte long
func (*TypedData) EncodePrimitiveValue ¶ added in v1.4.43
func (typedData *TypedData) EncodePrimitiveValue(encType string, encValue interface{}, depth int) ([]byte, error)
EncodePrimitiveValue deals with the primitive values found while searching through the typed data
func (*TypedData) EncodeType ¶ added in v1.4.43
func (typedData *TypedData) EncodeType(primaryType string) hexutil.Bytes
EncodeType generates the following encoding: `name ‖ "(" ‖ member₁ ‖ "," ‖ member₂ ‖ "," ‖ … ‖ memberₙ ")"`
each member is written as `type ‖ " " ‖ name` encodings cascade down and are sorted by name
func (*TypedData) Format ¶ added in v1.4.43
func (typedData *TypedData) Format() ([]*NameValueType, error)
Format returns a representation of typedData, which can be easily displayed by a user-interface without in-depth knowledge about 712 rules
func (*TypedData) HashStruct ¶ added in v1.4.43
func (typedData *TypedData) HashStruct(primaryType string, data TypedDataMessage) (hexutil.Bytes, error)
HashStruct generates a keccak256 hash of the encoding of the provided data
type TypedDataDomain ¶ added in v1.4.43
type TypedDataDomain struct {
Name string `json:"name"`
Version string `json:"version"`
ChainId *math.HexOrDecimal256 `json:"chainId"`
VerifyingContract string `json:"verifyingContract"`
Salt string `json:"salt"`
}
TypedDataDomain represents the domain part of an EIP-712 message.
type TypedDataMessage ¶ added in v1.4.43
type TypedDataMessage = map[string]interface{}