trade

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNullAddress ...
	ErrNullAddress = errors.New("address must not be null")
	// ErrInvalidAsset ...
	ErrInvalidAsset = errors.New("asset must be a 32-byte array in hex format")
	// ErrInvalidAddress ...
	ErrInvalidAddress = errors.New("address is not valid")
	// ErrNullPrivateKey ...
	ErrNullPrivateKey = errors.New("private key must not be null")
	// ErrNullBlindingKey ...
	ErrNullBlindingKey = errors.New("blinding key must not be null")
	// ErrInvalidFeeAmount ...
	ErrInvalidFeeAmount = errors.New("fee amount must be a positive satoshi amount")
	// ErrInvalidFeeAsset ...
	ErrInvalidFeeAsset = errors.New("fee asset must be a 32-byte array in hex format")
)
View Source
var (
	// ErrInvalidMarket ...
	ErrInvalidMarket = errors.New(
		"market must be a pair of valid 32-bytes assets encoded in hex format",
	)
	// ErrInvalidTradeType ...
	ErrInvalidTradeType = errors.New("trade type must be either BUY or SELL")
	// ErrInvalidAmount ...
	ErrInvalidAmount = errors.New("amount must be a positive satoshi amount")
)
View Source
var (
	// ErrInvalidChain ...
	ErrInvalidChain = fmt.Errorf(
		"chain must be either '%s' or '%s", network.Liquid.Name, network.Regtest.Name,
	)
	// ErrInvalidProviderURL ...
	ErrInvalidProviderURL = fmt.Errorf(
		"provider url must be a valid url in the form 'host:port'",
	)
	// ErrNullExplorer ...
	ErrNullExplorer = fmt.Errorf("explorer must not be null")
	// ErrNullClient ...
	ErrNullClient = fmt.Errorf("client must not be null")
)

Functions

func NewSwapTx

func NewSwapTx(
	utxos []explorer.Utxo, inAsset, outAsset string,
	inAmount, outAmount uint64, outScript, outBlindingKey []byte,
) (string, error)

Types

type BuyOrSellAndCompleteOpts

type BuyOrSellAndCompleteOpts struct {
	Market      trademarket.Market
	Amount      uint64
	Asset       string
	PrivateKey  []byte
	BlindingKey []byte
	FeeAsset    string
}

BuyOrSellAndCompleteOpts is the struct given to Buy method

type BuyOrSellOpts

type BuyOrSellOpts struct {
	Market      trademarket.Market
	Amount      uint64
	Asset       string
	Address     string
	BlindingKey []byte
	FeeAsset    string
}

BuyOrSellOpts is the struct given to Buy/Sell method

type NewTradeOpts

type NewTradeOpts struct {
	Chain           string
	ExplorerService explorer.Service
	Client          *tradeclient.Client
}

NewTradeOpts is the struct given to NewTrade method

type PreviewOpts

type PreviewOpts struct {
	Market    trademarket.Market
	TradeType int
	Amount    uint64
	Asset     string
	FeeAsset  string
}

PreviewOpts is the struct given to Preview method

type PreviewResult

type PreviewResult struct {
	AssetToSend     string
	AmountToSend    uint64
	AssetToReceive  string
	AmountToReceive uint64
	FeeAmount       uint64
	FeeAsset        string
}

PreviewResult is the struct returned by Preview method

type Trade

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

func NewTrade

func NewTrade(opts NewTradeOpts) (*Trade, error)

NewTrade returns a new trade initialized with the given arguments

func (*Trade) Buy

func (t *Trade) Buy(opts BuyOrSellOpts) ([]byte, error)

Buy creates a new trade proposal with the given arguments and sends it to the server which the inner client is connected to. This method returns the SwapAccept serialized message eventually returned by the counter-party.

func (*Trade) BuyAndComplete

func (t *Trade) BuyAndComplete(opts BuyOrSellAndCompleteOpts) (string, error)

BuyAndComplete creates a new trade proposal with the give arguments. The transaction of the resulting SwapAccept message is then signed with the provided private key, and sent back again to the connected server, which will take care of finalizing and broadcasting it.

func (*Trade) Preview

func (t *Trade) Preview(opts PreviewOpts) (*PreviewResult, error)

Preview queries the gRPC server to get the latest price for the given market, then calculates the amount to send or to receive depending on the given type.

func (*Trade) Sell

func (t *Trade) Sell(opts BuyOrSellOpts) ([]byte, error)

Sell creates a new trade proposal with the given arguments for selling a certain amount of base asset of the provided market pair. This proposal is then sent to the server which the inner client is connected to and, eventually, the resulting SwapAccept serialized message returned by the counter-party is returned to the caller.

func (*Trade) SellAndComplete

func (t *Trade) SellAndComplete(opts BuyOrSellAndCompleteOpts) (string, error)

SellAndComplete creates a new trade proposal with the given arguments for selling a certain amount of base asset of the provided market pair. If the proposal is accepted, it's then counter-signed with the provided private key and sent back again to the server that will take care of finalizing and broadcasting the transaction

type Wallet

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

func NewRandomWallet

func NewRandomWallet(net *network.Network) (*Wallet, error)

func NewWalletFromKey

func NewWalletFromKey(privateKey, blindingKey []byte, net *network.Network) *Wallet

func (*Wallet) Address

func (w *Wallet) Address() string

func (*Wallet) BlindingKey

func (w *Wallet) BlindingKey() []byte

func (*Wallet) PrivateKey added in v0.3.2

func (w *Wallet) PrivateKey() []byte

func (*Wallet) Script

func (w *Wallet) Script() ([]byte, []byte)

func (*Wallet) Sign

func (w *Wallet) Sign(psetBase64 string) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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