order

package
v0.0.0-...-24518c4 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The interval to check the price in Milliseconds
	CheckIntervalMil time.Duration = 500
	// The deadline for completing the swap in Minutes
	SwapDeadlineMin  time.Duration = 20
	PriceChannelSize int           = 100
)

Variables

View Source
var (
	ErrConv        = errors.New("could not convert amount to big int")
	ErrInvalidType = errors.New("invalid type value")
	ErrCanContinue = errors.New("can continue execution")
)

Functions

This section is empty.

Types

type Order

type Order struct {
	ID           uint     `json:"id"`
	Type         Type     `json:"type"`
	Path         []string `json:"path"`
	SellAmount   string   `json:"sell_amount"`
	BuyAmount    string   `json:"buy_amount"`
	Slippage     float64  `json:"slippage"`
	GasPriceMult float64  `json:"gas_price_multiplier"`
	GasLimit     uint64   `json:"gas_limit"`
	UserID       uint
	// contains filtered or unexported fields
}

func (*Order) Approve

func (o *Order) Approve(c *blockclient.Client, wallet *wallet.Wallet, ammount *big.Int) (*types.Receipt, error)

Executes the approve transaction if not already approved Returns the transaction or nil if the token is already approved

func (*Order) ApproveAmount

func (o *Order) ApproveAmount(c *blockclient.Client, wallet *wallet.Wallet) (*types.Receipt, error)

Executes the approve transaction with the exact order sell amount

func (*Order) ApproveMax

func (o *Order) ApproveMax(c *blockclient.Client, wallet *wallet.Wallet) (*types.Receipt, error)

Executes the approve transaction with the maximum amount

func (*Order) CompAndSwap

func (o *Order) CompAndSwap(c *blockclient.Client, wallet *wallet.Wallet, amount *big.Int) (*types.Receipt, error)

Compares the given amount with the wanted amount and returns the transaction or nil if no transaction has been made

func (*Order) GetAddreses

func (o *Order) GetAddreses() []common.Address

Returns the addresses of the path

func (*Order) GetBuyAmount

func (o *Order) GetBuyAmount() (*big.Int, error)

Calls get amounts out contract and returns the buy amount

func (*Order) GetBuyToken

func (o *Order) GetBuyToken() *Token

Returns the address of the token which will be bought

func (*Order) GetPriceStream

func (o *Order) GetPriceStream(c bind.ContractBackend, done <-chan bool) (chan *big.Int, chan error)

Returns a price channel for receiving a stream of prices and a channel for error. Stops only when it receives from the done channel

func (*Order) GetSellToken

func (o *Order) GetSellToken() *Token

Returns the address of the token which will be sold

func (*Order) Init

func (o *Order) Init(client bind.ContractBackend, routerHex string, chainID int64) error

Initializes the Order

func (*Order) Swap

func (o *Order) Swap(c *blockclient.Client, wallet *wallet.Wallet, amountOut *big.Int) (*types.Receipt, error)

Executes the swap transaction

type Router

type Router struct {
	Address  common.Address
	Instance *router.Router
}

type Token

type Token struct {
	Address  common.Address
	Decimals *big.Int
	Amount   *big.Int
	Instance *bep20_token.Bep20Token
}

type Type

type Type int
const (
	Limit Type = iota
	StopLimit
)

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

Custom json unmarshal for Type

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(b []byte) error

Custom json unmarshal for Type

Jump to

Keyboard shortcuts

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