Documentation
¶
Index ¶
- Constants
- Variables
- func Close() error
- func ExactBuyTrigger(price, target *big.Int, stopLoss bool) bool
- func ExactSellTrigger(price, target *big.Int, stopLoss bool) bool
- func FetchBalanceByContractAndNetworkID(contract string, networkID uint) (*big.Int, error)
- func InitDB() error
- func LoadAllAmountModes() error
- func LoadAllTargetTypes() error
- func LoadAllTradeTypes() error
- func SaveTokenUniqueByContractAndNetworkID(token *Token) error
- func SaveTrade(t *Trade) error
- func UpdateBalanceByContractAndNetworkID(contract string, networkID uint, balance *big.Int) error
- type AmountMode
- type AmountModes
- type Dex
- type Endpoint
- type Endpoints
- type Misc
- type Network
- func (n *Network) Connectors() []*Token
- func (n *Network) CreateCustomEndpoint(endpointURL string) error
- func (n *Network) Get() *Network
- func (n *Network) GetChainID() uint32
- func (n *Network) GetCustomEndpoint() (*Endpoint, bool)
- func (n *Network) GetDexes() []*Dex
- func (n *Network) GetEndpoints() Endpoints
- func (n *Network) GetFullName() string
- func (n *Network) GetGasLimit() uint64
- func (n *Network) GetID() uint
- func (n *Network) GetMulticall() string
- func (n *Network) GetName() string
- func (n *Network) GetNativeCurrency() string
- func (n *Network) GetTokens() []*Token
- func (n *Network) GetWETH() string
- func (n *Network) IsNativeCurrency(currency string) bool
- func (n *Network) NewNativeCurrencyToken() *Token
- func (n *Network) RemoveCustomEndpoint() error
- func (n *Network) Testnet() bool
- type Networks
- type RawTarget
- type Target
- func NewExactTarget(price string, priceDecimals uint8, amount string, amountDecimals uint8, ...) *Target
- func NewPercentageAmountTarget(price string, priceDecimals uint8, percentageAmount float64, ...) *Target
- func NewPercentagePriceAndAmountTarget(percentagePrice float64, priceDecimals uint8, percentageAmount float64, ...) *Target
- func NewPercentagePriceTarget(percentage float64, priceDecimals uint8, amount string, amountDecimals uint8, ...) *Target
- func NewTargetWithDefaults() *Target
- func (t *Target) GetActualAmount() *big.Int
- func (t *Target) GetActualAmountDecimals() uint8
- func (t *Target) GetAmount() *big.Int
- func (t *Target) GetAmountDecimals() uint8
- func (t *Target) GetAmountMinMax() *big.Int
- func (t *Target) GetAmountMode() *AmountMode
- func (t *Target) GetConfirmed() bool
- func (t *Target) GetDeadline() *time.Duration
- func (t *Target) GetExecutionPrice() decimal.Decimal
- func (t *Target) GetFailed() bool
- func (t *Target) GetGasLimit() *uint64
- func (t *Target) GetGasPrice() *big.Int
- func (t *Target) GetHit() bool
- func (t *Target) GetPath() []common.Address
- func (t *Target) GetPercentageAmount() float64
- func (t *Target) GetPercentagePrice() float64
- func (t *Target) GetPrice() *big.Int
- func (t *Target) GetPriceDecimals() uint8
- func (t *Target) GetSlippage() float64
- func (t *Target) GetStopLoss() bool
- func (t *Target) GetTargetType() *TargetType
- func (t *Target) GetTxHash() string
- func (t *Target) InvertAmountMode()
- func (t *Target) MarkStopLoss()
- func (t *Target) MarketSwapPossible(tradeInfo *uniswap.Trade, token *Token) bool
- func (t *Target) SetActualAmount(actualAmount *big.Int)
- func (t *Target) SetActualAmountDecimals(actualAmountDecimals uint8)
- func (t *Target) SetAmountMinMax(amountMinMax string)
- func (t *Target) SetAmountMode(amountMode *AmountMode)
- func (t *Target) SetConfirmed(confirmed bool)
- func (t *Target) SetDeadline(deadline *time.Duration)
- func (t *Target) SetDefaults()
- func (t *Target) SetExecutionPrice(executionPrice decimal.Decimal)
- func (t *Target) SetFailed()
- func (t *Target) SetGasLimit(gasLimit *uint64)
- func (t *Target) SetGasPrice(gasPrice *big.Int)
- func (t *Target) SetHit(hit bool)
- func (t *Target) SetPath(path []common.Address)
- func (t *Target) SetPercentageAmount(percentageAmount float64)
- func (t *Target) SetPrice(target string)
- func (t *Target) SetPriceDecimals(decimals uint8)
- func (t *Target) SetSlippage(slippage *float64)
- func (t *Target) SetTargetType(targetType *TargetType)
- func (t *Target) SetTxHash(txHash string)
- func (t *Target) ViewAmount() string
- func (t *Target) ViewPrice() string
- type TargetType
- type TargetTypes
- type Targets
- type Token
- func (t *Token) Get() *Token
- func (t *Token) GetBalance() *big.Int
- func (t *Token) GetBalanceDecimal(decimals uint8) decimal.Decimal
- func (t *Token) GetContract() string
- func (t *Token) GetDecimals() uint8
- func (t *Token) GetNative() bool
- func (t *Token) GetPredefined() bool
- func (t *Token) GetSymbol() string
- func (t *Token) IsConnector() bool
- func (t *Token) SetBalance(value *big.Int)
- func (t *Token) SetDecimals(decimals uint8)
- func (t *Token) SetNative(native bool)
- func (t *Token) SetNetworkID(networkID uint)
- func (t *Token) SetPredefined(predefined bool)
- func (t *Token) SetSymbol(symbol string)
- func (t *Token) ToUniswap(weth string) (*uniswap.Token, error)
- type Trade
- func (t *Trade) AmountInTrade() *big.Int
- func (t *Trade) AverageBuyPrice() decimal.Decimal
- func (t *Trade) GetBuyTargetHit() int
- func (t *Trade) GetBuyTargets() []*Target
- func (t *Trade) GetDex() *Dex
- func (t *Trade) GetEndpoint() *Endpoint
- func (t *Trade) GetInitPrice() *big.Int
- func (t *Trade) GetNetwork() *Network
- func (t *Trade) GetNextBuyTarget() *Target
- func (t *Trade) GetNextSellTarget() *Target
- func (t *Trade) GetSellTargetHit() int
- func (t *Trade) GetSellTargets() []*Target
- func (t *Trade) GetToken0() *Token
- func (t *Trade) GetToken1() *Token
- func (t *Trade) HasStoploss() bool
- func (t *Trade) IncrBuyTargetHit()
- func (t *Trade) IncrSellTargetHit()
- func (t *Trade) InvertTokens()
- func (t *Trade) SetBuyTargets(targets []*Target)
- func (t *Trade) SetInitPrice(price string)
- func (t *Trade) SetToken0(token *Token)
- func (t *Trade) SetToken1(token *Token)
- func (t *Trade) TotalBought() *big.Int
- type TradeType
- type TradeTypes
- type Wallet
- func (w *Wallet) GetNonce() int64
- func (w *Wallet) GetPrivateKey() *ecdsa.PrivateKey
- func (w *Wallet) GetWallet() string
- func (w *Wallet) GetWalletIndex() uint
- func (w *Wallet) IncrementNonce()
- func (w *Wallet) LastNonceUpdate() time.Time
- func (w *Wallet) NewWallet(walletAddr string, walletIndex uint, label string) error
- func (w *Wallet) SetNonce(nonce uint64)
- func (w *Wallet) SetPrivateKey(key *ecdsa.PrivateKey)
Constants ¶
const MaxSlippage = 10000
Variables ¶
var ( ConfigDBFile string ConfigDir string )
var ( ErrNoNetworksFound = errors.New("no networks found") ErrNetworkNotFound = errors.New("network not found") ErrNoCustomEndpoint = errors.New("no custom endpoints found") )
var (
DefaultSlippage = float64(100) // 1% (support up to 2 decimals)
)
var ErrNoAmountModeFound = errors.New("no amount mode found")
var ErrNoEndpointsFound = errors.New("no endpoints found")
var ErrNoMiscFound = errors.New("no misc found")
var ErrNoTargetTypesFound = errors.New("no target types found")
var ErrNoTradeTypesFound = errors.New("no trade types found")
var ErrWalletNotFound = errors.New("wallet not found")
Functions ¶
func Close ¶
func Close() error
Close closes the database connection. Use only when shutting down the program.
func ExactBuyTrigger ¶
ExactBuyTrigger is the function used to trigger a buy.
func ExactSellTrigger ¶
ExactSellTrigger is the function used to trigger a sell.
func FetchBalanceByContractAndNetworkID ¶
FetchBalance returns the balance of the token by the contract address and network id. The network id is the internal database id of the network. It's not related to the chain id.
func LoadAllAmountModes ¶
func LoadAllAmountModes() error
LoadAllAmountModes fetches all amount modes from the database and sets them as a global variable..
func LoadAllTargetTypes ¶
func LoadAllTargetTypes() error
LoadAllTargetTypes fetches all trade types from the database and sets them as a global variable.
func LoadAllTradeTypes ¶
func LoadAllTradeTypes() error
LoadAllTradeTypes fetches all trade types from the database and sets them as a global variable..
func SaveTokenUniqueByContractAndNetworkID ¶
SaveTokenUniqueByContractAndNetworkID saves the token in the database. The contract and network id are used to identify the token. If a token with the same contract and network id exists, nothing happens.
func UpdateBalanceByContractAndNetworkID ¶
UpdateBalanceByContractAndNetworkID updates the balance of the token by the contract address and network id. The network id is the internal database id of the network. It's not related to the chain id.
Types ¶
type AmountMode ¶
type AmountMode struct {
gorm.Model `yaml:"-"`
Type string `yaml:"type"`
// contains filtered or unexported fields
}
func (*AmountMode) GetName ¶
func (a *AmountMode) GetName() string
GetName returns the name of the AmountMode.
type AmountModes ¶
type AmountModes []*AmountMode
var DefaultAmountModes AmountModes
func (AmountModes) GetAmountIn ¶
func (a AmountModes) GetAmountIn() *AmountMode
GetAmountIn returns the amountIn database object.
func (AmountModes) GetAmountOut ¶
func (a AmountModes) GetAmountOut() *AmountMode
GetAmountOut returns the amountOut database object.
type Dex ¶
type Dex struct {
gorm.Model `yaml:"-"`
Name string `yaml:"name"`
Router string `yaml:"router"`
Factory string `yaml:"factory"`
Fee int64 `yaml:"fee"`
Predefined bool `yaml:"-"`
// Trades []*Trade `yaml:"-"`
NetworkID uint `yaml:"-"`
// contains filtered or unexported fields
}
Dex is the database model for a decentralized exchange.
func (*Dex) GetFactory ¶
GetFactory returns the factory contract of the dex.
func (*Dex) GetFeeBigInt ¶
GetFeeBigInt returns the fee of the dex as a *big.Int.
func (*Dex) GetPredefined ¶
GetPredefined returns whether the dex is predefined.
func (*Dex) SetPredefined ¶
SetPredefined sets whether the dex is predefined.
type Endpoint ¶
type Endpoint struct {
gorm.Model `yaml:"-"`
URL string `yaml:"url"`
Custom bool `yaml:"-"`
NetworkID uint `yaml:"-"`
// contains filtered or unexported fields
}
Endpoint represents a node endpoint, either http or ws.
func NewEndpoint ¶
NewEndpoint creates a new endpoint.
type Endpoints ¶
type Endpoints []*Endpoint
func (Endpoints) GetEndpointByURL ¶
GetEndpointByURL returns the endpoint with the given url.
type Misc ¶
func (*Misc) CreateTermsAndConditions ¶
CreateTermsAndConditions sets the terms and conditions in the database.
func (*Misc) GetTermsAndConditions ¶
GetTermsAndConditions returns where the terms and conditions are accepted or not.
type Network ¶
type Network struct {
gorm.Model `yaml:"-"`
Endpoints Endpoints `yaml:"endpoints" gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
Tokens []*Token `yaml:"tokens" gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
Dexes []*Dex `yaml:"dexes" gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
Name string `yaml:"name" gorm:"unique"`
FullName string `yaml:"fullName"`
Multicall string `yaml:"multicall"`
NativeCurrency string `yaml:"nativeCurrency"`
WETH string `yaml:"weth"` // represents the native currency as token
GasLimit uint64 `yaml:"gasLimit"`
ChainID uint32 `yaml:"chainId"`
IsTestnet bool `yaml:"isTestnet"`
EIP1559Enabled bool `yaml:"eip1559Enabled"`
Predefined bool `yaml:"-"`
// contains filtered or unexported fields
}
func FetchAllNetworks ¶
FetchAllNetworks fetches all networks from the database.
func (*Network) Connectors ¶
func (*Network) CreateCustomEndpoint ¶
func (*Network) GetChainID ¶
func (*Network) GetCustomEndpoint ¶
GetCustomEndpoint returns the custom endpoint for the given network.
func (*Network) GetEndpoints ¶
func (*Network) GetFullName ¶
func (*Network) GetGasLimit ¶
func (*Network) GetMulticall ¶
func (*Network) GetNativeCurrency ¶
func (*Network) IsNativeCurrency ¶
IsNativeCurrency returns true if the given currency is native to the chain.
func (*Network) NewNativeCurrencyToken ¶
func (*Network) RemoveCustomEndpoint ¶
type RawTarget ¶
type RawTarget struct {
gorm.Model
Price string
Amount string
Slippage float64
GasPrice *big.Int `gorm:"-"`
ExactPrice bool
ExactAmount bool
Stoploss bool
Skip bool // Skip is true, if the raw target has been converted to a database.Target already by calling Target()
TradeID uint
// contains filtered or unexported fields
}
RawTarget is a struct that contains the raw values of the price and amount of a target Currently the price and amount bust be a decimal string.
func NewRawTarget ¶
func NewRawTarget(price, amount string, exactPrice, exactAmount bool, slippage float64, gasPrice *big.Int, stoploss bool) *RawTarget
NewRawTarget creates a new raw target.
func (*RawTarget) Target ¶
func (t *RawTarget) Target(baseToken *Token, actualToken *Token, amountMode *AmountMode, targetType *TargetType, tradeID uint) *Target
Target turns a raw target into a target.
type Target ¶
type Target struct {
gorm.Model
// The trading path of the target.
Path []common.Address `gorm:"-"`
// The price of the target. Convert to *big.Int, normalized with decimals.
Price string
// The amount of the target. Convert to *big.Int, normalized with decimals.
// The amount is always in the base currency of the trade.
Amount string
// Either the minAmountOut of maxAmountIn which is required in order to complete the trade.
// This value is only known when the trigger price has been hit and must be set then.
AmountMinMax string
TxHash string
// The actual amount of the target.
// This value is used for the swap.
// For a sell target, this amount is only know when the trigger price has been hit.
ActualAmount *big.Int `gorm:"-"`
PercentageAmount float64 `gorm:"-"`
PercentagePrice float64 `gorm:"-"`
TargetTypeID uint
AmountModeID uint
AmountMode *AmountMode `gorm:"foreignkey:AmountModeID"`
// Slippage in percent muliplied by 100 to support up to 2 decimals.
Slippage *float64
TargetType *TargetType `gorm:"foreignkey:TargetTypeID"`
TradeID uint
Deadline *time.Duration `gorm:"-"` // TODO: replace with unix timestamp and store in database
GasLimit *uint64
// In WEI
GasPrice *big.Int `gorm:"-"`
Hit bool
Confirmed bool
Failed bool
AmountDecimals uint8
ActualAmountDecimals uint8
PriceDecimals uint8
IsStopLoss bool
TriggerFunc func(*big.Int, *big.Int, bool) bool `gorm:"-"`
ExecutionPrice decimal.Decimal `gorm:"-"`
// contains filtered or unexported fields
}
Target is the database model for a target.
func NewExactTarget ¶
func NewExactTarget( price string, priceDecimals uint8, amount string, amountDecimals uint8, actualAmount *big.Int, actualAmountDecimals uint8, amountMode *AmountMode, targetType *TargetType, slippage float64, gasPrice *big.Int, stoploss bool, tradeID uint, triggerFunc func(*big.Int, *big.Int, bool) bool, ) *Target
NewExactTarget creates a new target. The price and the amount must be an exact value and covertable to a *big.Int. The amount is always in the base currency of the trade. It is possible to set the actual amount to nil, as it will be calculated when the trigger price is hit.
func NewPercentageAmountTarget ¶
func NewPercentageAmountTarget( price string, priceDecimals uint8, percentageAmount float64, amountDecimals uint8, actualAmountDecimals uint8, amountMode *AmountMode, targetType *TargetType, slippage float64, gasPrice *big.Int, stoploss bool, tradeID uint, triggerFunc func(*big.Int, *big.Int, bool) bool, ) *Target
NewPercentageAmountTarget create a new target where the amount is a percentage of the total amount of the trade.
func NewPercentagePriceAndAmountTarget ¶
func NewPercentagePriceAndAmountTarget( percentagePrice float64, priceDecimals uint8, percentageAmount float64, amountDecimals uint8, actualAmountDecimals uint8, amountMode *AmountMode, targetType *TargetType, slippage float64, gasPrice *big.Int, stoploss bool, tradeID uint, triggerFunc func(*big.Int, *big.Int, bool) bool, ) *Target
NewPercentagePriceAndAmountTarget creates a new target where the trade is triggered as soon as the price changes by a certain percentage and the amount is a percentage of the total amount of the trade.
func NewPercentagePriceTarget ¶
func NewPercentagePriceTarget( percentage float64, priceDecimals uint8, amount string, amountDecimals uint8, actualAmount *big.Int, actualAmountDecimals uint8, amountMode *AmountMode, targetType *TargetType, slippage float64, gasPrice *big.Int, stoploss bool, tradeID uint, triggerFunc func(*big.Int, *big.Int, bool) bool, ) *Target
NewPercentagePriceTarget create a new target where the trade is triggered as soon as the price changes by a certain percentage.
func NewTargetWithDefaults ¶
func NewTargetWithDefaults() *Target
NewTargetWithDefaults creates a new target with default values.
func (*Target) GetActualAmount ¶
GetActualAmount returns the actual amount.
func (*Target) GetActualAmountDecimals ¶
GetActualAmountDecimals returns the actual amount decimals.
func (*Target) GetAmountDecimals ¶
GetAmountDecimals returns the amount decimals.
func (*Target) GetAmountMinMax ¶
GetAmountMinMax returns the amount min/max.
func (*Target) GetAmountMode ¶
func (t *Target) GetAmountMode() *AmountMode
GetAmountMode returns the amount mode.
func (*Target) GetConfirmed ¶
GetConfirmed returns whether the target transaction has been confirmed.
func (*Target) GetDeadline ¶
GetDeadline returns the deadline.
func (*Target) GetExecutionPrice ¶
GetExecutionPrice returns the execution price.
func (*Target) GetGasLimit ¶
GetGasLimit returns the gas limit.
func (*Target) GetGasPrice ¶
GetGasPrice returns the gas price.
func (*Target) GetPercentageAmount ¶
GetPercentageAmount returns the percentage amount.
func (*Target) GetPercentagePrice ¶
GetPercentagePrice returns the percentage price.
func (*Target) GetPriceDecimals ¶
GetPriceDecimals returns the price decimals.
func (*Target) GetSlippage ¶
GetSlippage returns the slippage.
func (*Target) GetStopLoss ¶
GetStopLoss returns whether the target is a stop loss.
func (*Target) GetTargetType ¶
func (t *Target) GetTargetType() *TargetType
GetTargetType returns the target type.
func (*Target) InvertAmountMode ¶
func (t *Target) InvertAmountMode()
func (*Target) MarkStopLoss ¶
func (t *Target) MarkStopLoss()
MarkStopLoss marks the target as a stop loss.
func (*Target) MarketSwapPossible ¶
SwapPossible returns whether a swap is possible.
func (*Target) SetActualAmount ¶
SetActualAmount sets the actual amount.
func (*Target) SetActualAmountDecimals ¶
SetActualAmountDecimals sets the actual amount decimals.
func (*Target) SetAmountMinMax ¶
SetAmountMinMaxx sets the amount min/max.
func (*Target) SetAmountMode ¶
func (t *Target) SetAmountMode(amountMode *AmountMode)
SetAmountMode sets the amount mode.
func (*Target) SetConfirmed ¶
SetConfirmed sets whether the target transaction has been confirmed.
func (*Target) SetDeadline ¶
SetDeadline sets the deadline.
func (*Target) SetDefaults ¶
func (t *Target) SetDefaults()
func (*Target) SetExecutionPrice ¶
SetExecutionPrice sets the execution price.
func (*Target) SetGasLimit ¶
SetGasLimit sets the gas limit.
func (*Target) SetGasPrice ¶
SetGasPrice sets the gas price.
func (*Target) SetPercentageAmount ¶
SetPercentageAmount sets the percentage amount.
func (*Target) SetPriceDecimals ¶
SetPriceDecimals sets the target decimals.
func (*Target) SetSlippage ¶
SetSlippage sets the slippage.
func (*Target) SetTargetType ¶
func (t *Target) SetTargetType(targetType *TargetType)
SetTargetType sets the target type.
func (*Target) ViewAmount ¶
ViewAmount returns the amount as a string showing significant figures or a percentage value.
type TargetType ¶
type TargetType struct {
gorm.Model `yaml:"-"`
Type string `yaml:"type"`
// contains filtered or unexported fields
}
func (*TargetType) GetType ¶
func (t *TargetType) GetType() string
GetType returns the type of the TargetType.
func (*TargetType) Is ¶
func (t *TargetType) Is(other *TargetType) bool
Is helps to compare two target types. // TODO: implement that method for trade types and amount modes too.
type TargetTypes ¶
type TargetTypes []*TargetType
var DefaultTargetTypes TargetTypes
func (TargetTypes) GetBuy ¶
func (t TargetTypes) GetBuy() *TargetType
GetBuy returns the buyTarget database object.
func (TargetTypes) GetSell ¶
func (t TargetTypes) GetSell() *TargetType
GetSell returns the sellTarget database object.
type Token ¶
type Token struct {
gorm.Model `yaml:"-"`
Contract string `yaml:"contract"`
Symbol string `yaml:"symbol"`
Balance string `yaml:"-"` // converted to big.Int
NetworkID uint `yaml:"-"`
Decimals uint8 `yaml:"decimals"`
Connector bool `yaml:"connector"`
Predefined bool `yaml:"-"`
Native bool `yaml:"native"`
// contains filtered or unexported fields
}
Token represents a token with some basic informations must be identical to the struct internal/blockchain/multicall/token.
func (*Token) GetBalance ¶
GetBalance returns the balance of the token.
func (*Token) GetBalanceDecimal ¶
GetBalanceDecimal returns the balance of the token as a decimal.
func (*Token) GetContract ¶
GetContract returns the contract address.
func (*Token) GetDecimals ¶
GetDecimals returns the decimals of the token.
func (*Token) GetPredefined ¶
GetPredefined returns whether the token is predefined or not.
func (*Token) IsConnector ¶
Connector returns whether the token is a connector token or not. Connector tokens are used in the path finding.
func (*Token) SetBalance ¶
SetBalance sets the balance of the tokn.
func (*Token) SetDecimals ¶
SetDecimals sets the decimals of the token.
func (*Token) SetNetworkID ¶
SetNetworkID sets the network id of the token.
func (*Token) SetPredefined ¶
SetPredefined sets the predefined flag of the token.
type Trade ¶
type Trade struct {
gorm.Model
RawBuyTargets []*RawTarget `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
RawSellTargets []*RawTarget `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
BuyTargets Targets `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
SellTargets Targets `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
InitPrice string // convert to *big.Int, normalized with decimals
Token0 *Token `gorm:"foreignkey:Token0ID"`
Token0ID uint
Token1 *Token `gorm:"foreignkey:Token1ID"`
Token1ID uint
TradeType *TradeType `gorm:"foreignkey:TradeTypeID"`
TradeTypeID uint
Endpoint *Endpoint `gorm:"foreignkey:EndpointID"`
EndpointID uint
Network *Network `gorm:"foreignkey:NetworkID"`
NetworkID uint
Dex *Dex `gorm:"foreignkey:DexID"`
DexID uint
Failed bool
// contains filtered or unexported fields
}
Trade is the database model for a trade.
func NewTrade ¶
func NewTrade(token0, token1 *Token, buyTargets, sellTargets Targets, tradeType *TradeType, endpoint *Endpoint, network *Network, dex *Dex) *Trade
NewTrade creates a new trade.
func (*Trade) AmountInTrade ¶
AmountInTrade returns the amount in trade for the trade.
func (*Trade) AverageBuyPrice ¶
AverageBuyPrice returns the average buy price for the trade.
func (*Trade) GetBuyTargetHit ¶
GetBuyTargetHit returns the buy target hit counter.
func (*Trade) GetBuyTargets ¶
GetBuyTargets returns the buy targets for the trade.
func (*Trade) GetEndpoint ¶
GetEndpoint returns the endpoint for the trade.
func (*Trade) GetInitPrice ¶
GetInitPrice returns the init price for the trade.
func (*Trade) GetNetwork ¶
GetNetwork returns the network for the trade.
func (*Trade) GetNextBuyTarget ¶
GetNextBuyTarget returns the first buy target that has not been hit. If all buy targets have been hit, it returns nil.
func (*Trade) GetNextSellTarget ¶
GetNextSellTarget returns the first sell target that has not been hit. If all sell targets have been hit, it returns it returns nil.
func (*Trade) GetSellTargetHit ¶
GetSellTargetHit returns the sell target hit counter.
func (*Trade) GetSellTargets ¶
GetSellTargets returns the sell targets for the trade.
func (*Trade) HasStoploss ¶
HasStoploss returns whether the trade has a stoploss target.
func (*Trade) IncrBuyTargetHit ¶
func (t *Trade) IncrBuyTargetHit()
IncrBuyTargetHit increments the buy target hit counter.
func (*Trade) IncrSellTargetHit ¶
func (t *Trade) IncrSellTargetHit()
IncrSellTargetHit increments the sell target hit counter.
func (*Trade) InvertTokens ¶
func (t *Trade) InvertTokens()
InvertTokens inverts the tokens for the trade.
func (*Trade) SetBuyTargets ¶
SetTargets sets the targets for the trade. Required for the market trades, otherwise not.
func (*Trade) SetInitPrice ¶
SetInitPrice sets the init price for the trade.
func (*Trade) TotalBought ¶
TotalBought returns the total amount that has been bought.
type TradeType ¶
type TradeType struct {
gorm.Model `yaml:"-"`
Type string `yaml:"type"`
// contains filtered or unexported fields
}
type TradeTypes ¶
type TradeTypes []*TradeType
var DefaultTradeTypes TradeTypes
func (TradeTypes) GetMarket ¶
func (t TradeTypes) GetMarket() *TradeType
GetMarketTrade returns the marketTrade database object.
func (TradeTypes) GetOrder ¶
func (t TradeTypes) GetOrder() *TradeType
GetOrderTrade returns the orderTrade database object.
func (TradeTypes) GetSnipe ¶
func (t TradeTypes) GetSnipe() *TradeType
GetSnipeTrade returns the snipeTrade database object.
type Wallet ¶
type Wallet struct {
gorm.Model
FirstUse bool `gorm:"-"`
Wallet string
WalletIndex uint
Label string // label is either "trade" for wallets used for trading or "unlock" for wallets used to unlock the bot
// contains filtered or unexported fields
}
func FetchWallet ¶
func (*Wallet) GetPrivateKey ¶
func (w *Wallet) GetPrivateKey() *ecdsa.PrivateKey
GetPrivateKey returns the private key for the wallet, make sure to load it first with wallet.Load().
func (*Wallet) GetWalletIndex ¶
func (*Wallet) IncrementNonce ¶
func (w *Wallet) IncrementNonce()
IncrementNonce increments the nonce.
func (*Wallet) LastNonceUpdate ¶
LastNonceUpdate returns the time of the last nonce update.
func (*Wallet) SetPrivateKey ¶
func (w *Wallet) SetPrivateKey(key *ecdsa.PrivateKey)