account

package
v0.0.0-...-0658b27 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 14 Imported by: 141

Documentation

Index

Constants

View Source
const (
	// ContextCredentialsFlag used for retrieving api credentials from context
	ContextCredentialsFlag contextCredential = "apicredentials"
	// ContextSubAccountFlag used for retrieving just the sub account from
	// context, when the default config credentials sub account needs to be
	// changed while the same keys can be used.
	ContextSubAccountFlag contextCredential = "subaccountoverride"
)
View Source
const (
	Key             = "key"
	Secret          = "secret"
	SubAccountSTR   = "subaccount"
	ClientID        = "clientid"
	OneTimePassword = "otp"
	PEMKey          = "pemkey"
)

Default credential values

Variables

This section is empty.

Functions

func DeployCredentialsToContext

func DeployCredentialsToContext(ctx context.Context, creds *Credentials) context.Context

DeployCredentialsToContext sets credentials for internal use to context which can override default credential values.

func DeploySubAccountOverrideToContext

func DeploySubAccountOverrideToContext(ctx context.Context, subAccount string) context.Context

DeploySubAccountOverrideToContext sets subaccount as override to credentials as a separate flag.

func ParseCredentialsMetadata

func ParseCredentialsMetadata(ctx context.Context, md metadata.MD) (context.Context, error)

ParseCredentialsMetadata intercepts and converts credentials metadata to a static type for authentication processing and protection.

func Process

func Process(h *Holdings, c *Credentials) error

Process processes new account holdings updates

func SubscribeToExchangeAccount

func SubscribeToExchangeAccount(exchange string) (dispatch.Pipe, error)

SubscribeToExchangeAccount subscribes to your exchange account

Types

type Accounts

type Accounts struct {
	ID uuid.UUID
	// NOTE: Credentials is a place holder for a future interface type, which
	// will need -
	// TODO: Credential tracker to match to keys that are managed and return
	// pointer.
	// TODO: Have different cred struct for centralized verse DEFI exchanges.
	SubAccounts map[Credentials]map[key.SubAccountCurrencyAsset]*ProtectedBalance
}

Accounts holds a stream ID and a map to the exchange holdings

type Balance

type Balance struct {
	Currency               currency.Code
	Total                  float64
	Hold                   float64
	Free                   float64
	AvailableWithoutBorrow float64
	Borrowed               float64
}

Balance is a sub-type to store currency name and individual totals

type Change

type Change struct {
	Exchange string
	Currency currency.Code
	Asset    asset.Item
	Amount   float64
	Account  string
}

Change defines incoming balance change on currency holdings

type ContextCredentialsStore

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

ContextCredentialsStore protects the stored credentials for use in a context

func (*ContextCredentialsStore) Get

Get returns the full credentials from the store

func (*ContextCredentialsStore) Load

func (c *ContextCredentialsStore) Load(creds *Credentials)

Load stores provided credentials

type Credentials

type Credentials struct {
	Key                 string
	Secret              string
	ClientID            string // TODO: Implement with exchange orders functionality
	PEMKey              string
	SubAccount          string
	OneTimePassword     string
	SecretBase64Decoded bool
}

Credentials define parameters that allow for an authenticated request.

func (*Credentials) Equal

func (c *Credentials) Equal(other *Credentials) bool

Equal determines if the keys are the same. OTP omitted because it's generated per request. PEMKey and Secret omitted because of direct correlation with api key.

func (*Credentials) GetMetaData

func (c *Credentials) GetMetaData() (flag, values string)

GetMetaData returns the credentials for metadata context deployment

func (*Credentials) IsEmpty

func (c *Credentials) IsEmpty() bool

IsEmpty return true if the underlying credentials type has not been filled with at least one item.

func (*Credentials) String

func (c *Credentials) String() string

String prints out basic credential info (obfuscated) to track key instances associated with exchanges.

type Holdings

type Holdings struct {
	Exchange string
	Accounts []SubAccount
}

Holdings is a generic type to hold each exchange's holdings for all enabled currencies

func GetHoldings

func GetHoldings(exch string, creds *Credentials, assetType asset.Item) (Holdings, error)

GetHoldings returns full holdings for an exchange. NOTE: Due to credentials these amounts could be N*APIKEY actual holdings. TODO: Add jurisdiction and differentiation between APIKEY holdings.

type Protected

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

Protected limits the access to the underlying credentials outside of this package.

func (*Protected) Equal

func (p *Protected) Equal(other *Credentials) bool

Equal determines if the keys are the same

func (*Protected) String

func (p *Protected) String() string

String strings the credentials in a protected way.

type ProtectedBalance

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

ProtectedBalance stores the full balance information for that specific asset

func GetBalance

func GetBalance(exch, subAccount string, creds *Credentials, ai asset.Item, c currency.Code) (*ProtectedBalance, error)

GetBalance returns the internal balance for that asset item.

func (*ProtectedBalance) GetFree

func (b *ProtectedBalance) GetFree() float64

GetFree returns the current free balance for the exchange

func (*ProtectedBalance) Wait

func (b *ProtectedBalance) Wait(maxWait time.Duration) (wait <-chan bool, cancel chan<- struct{}, err error)

Wait waits for a change in amounts for an asset type. This will pause indefinitely if no change ever occurs. Max wait will return true if it failed to achieve a state change in the time specified. If Max wait is not specified it will default to a minute wait time.

type Service

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

Service holds ticker information for each individual exchange

func (*Service) Update

func (s *Service) Update(incoming *Holdings, creds *Credentials) error

Update updates holdings with new account info

type SubAccount

type SubAccount struct {
	Credentials Protected
	ID          string
	AssetType   asset.Item
	Currencies  []Balance
}

SubAccount defines a singular account type with associated currency balances

func CollectBalances

func CollectBalances(accountBalances map[string][]Balance, assetType asset.Item) (accounts []SubAccount, err error)

CollectBalances converts a map of sub-account balances into a slice

Jump to

Keyboard shortcuts

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