txhistory

package
v0.0.0-...-f545d20 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetTranslation

type AssetTranslation map[string]parsers.ResolverExpression

AssetTranslation is keyed with the `common.AssetType` and a translation expression.

type ExchangeAssetTranslation

type ExchangeAssetTranslation map[string]AssetTranslation

ExchangeAssetTranslation is keyed with exchange or _all_ and then the `common.AssetType` and the expression.

type ExchangeOHCEntries

type ExchangeOHCEntries struct {
	// contains filtered or unexported fields
}

type ResolveAcceptFunction

type ResolveAcceptFunction func(
	path parsers.ResolverExpressionPathItem,
	entry *common.TxOHCHistory,
) ResolveAcceptResult

ResolveAcceptFunction is called each time it has found a match and query if it should continue or stop searching.

NOTE: Both _path_ and _entry_ is *guaranteed* to be valid.

type ResolveAcceptResult

type ResolveAcceptResult int
const (
	// ResolveAcceptResultContinue denotes that it should continue it search and add the entry to
	// the search result.
	ResolveAcceptResultContinue ResolveAcceptResult = 0
	// ResolveAcceptResultFail specifies that the search is over and no result should be yielded
	ResolveAcceptResultFail ResolveAcceptResult = -1
	// ResolveAcceptResultAccept denotes that the search is over and the result is ready
	ResolveAcceptResultAccept ResolveAcceptResult = 1
)

type ResolvedOHCEntry

type ResolvedOHCEntry struct {
	Entry    common.TxOHCHistoryEntry
	Exchange string

	AssetPair common.AssetPair
	// contains filtered or unexported fields
}

type TxOHCCache

type TxOHCCache struct {
	// contains filtered or unexported fields
}

TxOHCCache keeps OHC entries in a cache.

`common.ExchangeAll` can used when global rates is accepted.

func NewTxOHCCache

func NewTxOHCCache() *TxOHCCache

func (*TxOHCCache) Add

func (cache *TxOHCCache) Add(entries []common.TxOHCHistory, exchange ...string) *TxOHCCache

func (*TxOHCCache) Clear

func (cache *TxOHCCache) Clear(path string, except ...string) *TxOHCCache

func (*TxOHCCache) FindEntry

func (cache *TxOHCCache) FindEntry(
	entries []common.TxOHCHistory,
	at time.Time,
) (*common.TxOHCHistory, bool)

func (*TxOHCCache) GetEntryForAssset

func (cache *TxOHCCache) GetEntryForAssset(
	assetPair common.AssetPair,
	at time.Time,
	exchange ...string,
) (*common.TxOHCHistory, string)

func (*TxOHCCache) GetExchanges

func (cache *TxOHCCache) GetExchanges(except ...string) []string

func (*TxOHCCache) Load

func (cache *TxOHCCache) Load(
	path string,
	addFunc func(cache *TxOHCCache, exchange string, entries []common.TxOHCHistory),
	exchange ...string) *TxOHCCache

func (*TxOHCCache) Store

func (cache *TxOHCCache) Store(path string, exchange ...string) *TxOHCCache

type TxOHCReader

type TxOHCReader struct {
	// contains filtered or unexported fields
}

func NewTxOHCReader

func NewTxOHCReader() *TxOHCReader

func (*TxOHCReader) Read

func (txr *TxOHCReader) Read(
	pair common.AssetPair,
	since time.Time,
	interval time.Duration,
	reader ...string,
) []common.TxOHCHistory

func (*TxOHCReader) Register

func (txr *TxOHCReader) Register(name string, reader common.TxOHCReader) *TxOHCReader

type TxOHCResolver

type TxOHCResolver struct {
	// contains filtered or unexported fields
}

TxOHCResolver resolves a assetType to a another one possibly by one or more indirections.

.Wanted behavior ==== 1. Bittrex: BTC-USDT -> USDT-USD -> USD-EUR -> EUR (btx) 2. All: BTC-EUR -> EUR 3. All: LTC-BTC -> BTC-EUR -> EUR (cbx) 4. Bittrex: LTC-BTC -> BTC-USDT -> USDT-USD -> USD-EUR -> EUR (btx) ====

.Resolver Expressions ==== 1. btx:USDT = btx,all:USD -> ofx,all:EUR 2. N/A 3. all:BTC = cbx,all:EUR 4. btx:BTC = btx,all:USDT ====

NOTE: That the above expressions expands, e..g. expression 1 will be expanded to btx:USDT = btx,all:USDT-USD -> ofx,all:USD-EUR.

Since last expression (4) is translated to USDT and it do exist, it will continue to expand using (1) until a _FIAT_ is reached.

Where prefix before equal sign means exchange. When it is _all_, it will try to use the submitted exchange first, if miss, it will try `common.ExchangeAll` in cache before giving up (if _all_ is submitted).

TIP: If prefix is omitted, _all_ is automatically added e.g. it is possible to rewrite (3) from _all:BTC = cbx,all:EUR_ to _BTC = cbx,all:EUR_.

Prefix Resolve Order

1. explicit first 2. all by the submitted exchange (if any) 3. all by `common.ExchangeAll`

Prefix after equal sign is resolved in stated order where again _all_ is first tried with the submitted _exchange_ parameter, if fails, it will try `common.ExchangeAll` (if _all_ is submitted).

All patterns are terminated with a new-line.

func NewTxOHCResolver

func NewTxOHCResolver(cache *TxOHCCache) *TxOHCResolver

func (*TxOHCResolver) AddTranslations

func (resolver *TxOHCResolver) AddTranslations(expr ...parsers.ResolverExpression) *TxOHCResolver

func (*TxOHCResolver) Resolve

func (resolver *TxOHCResolver) Resolve(
	at time.Time,
	asset common.AssetType,
	accept ResolveAcceptFunction,
	exchange ...string,
) ([]ResolvedOHCEntry, bool)

ResolveTarget will search beginning with _asset_ and path down until _accept_ function is stating `ResolveAcceptResultContinue` by adding resolved entries in path (excluding _asset_) _at_ the time.

If succeeds to find it will return `true`, otherwise `false`.

func (*TxOHCResolver) ResolveToFIAT

func (resolver *TxOHCResolver) ResolveToFIAT(
	at time.Time,
	asset common.AssetType,
	fiat int,
	exchange ...string,
) ([]ResolvedOHCEntry, bool)

ResolveTarget will search beginning with _asset_ and path down to _fiat_ by adding resolved entries in path (excluding _asset_) _at_ the time.

If succeeds to find _fiat_ (as _CostUnit_ on resolved path elements) it will return `true`, otherwise `false`.

The _fiat_ parameter specifies how may times it should encounter a _FIAT_ as _CostUnit_ until declaring success.

This could be used to resolve the following: 1. USDT = USD -> EUR (fiat = 2) 2. EUR = SEK (fiat 1)

Or if _fiat_ is set to 3 and _USDT_ it could resolve to UST -> SEK.

func (*TxOHCResolver) ResolveToTarget

func (resolver *TxOHCResolver) ResolveToTarget(
	at time.Time,
	asset common.AssetType,
	target common.AssetType,
	exchange ...string,
) ([]ResolvedOHCEntry, bool)

ResolveTarget will search beginning with _asset_ and path down to _target_ by adding resolved entries in path (excluding _asset_) _at_ the time.

If succeeds to find _target_ (as _CostUnit_ on resolved path elements) it will return `true`, otherwise `false`.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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