exchange

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MarginTypeIsolated MarginType = "ISOLATED"
	MarginTypeCrossed  MarginType = "CROSSED"

	ErrNoNeedChangeMarginType int64 = -4046
)
View Source
var (
	ErrInvalidQuantity   = errors.New("invalid quantity")
	ErrInsufficientFunds = errors.New("insufficient funds or locked")
	ErrInvalidAsset      = errors.New("invalid asset")
)
View Source
var ErrInsufficientData = errors.New("insufficient data")

Functions

func CandleFromKline

func CandleFromKline(pair string, k binance.Kline) model.Candle

func CandleFromWsKline

func CandleFromWsKline(pair string, k binance.WsKline) model.Candle

func FutureCandleFromKline

func FutureCandleFromKline(pair string, k futures.Kline) model.Candle

func FutureCandleFromWsKline

func FutureCandleFromWsKline(pair string, k futures.WsKline) model.Candle

func SplitAssetQuote

func SplitAssetQuote(pair string) (asset string, quote string)

Types

type AssetQuote

type AssetQuote struct {
	Quote string
	Asset string
}

type AssetValue

type AssetValue struct {
	Time  time.Time
	Value float64
}

type Binance

type Binance struct {
	HeikinAshi bool
	Testnet    bool

	APIKey    string
	APISecret string

	MetadataFetchers []MetadataFetchers
	// contains filtered or unexported fields
}

func NewBinance

func NewBinance(ctx context.Context, options ...BinanceOption) (*Binance, error)

NewBinance create a new Binance exchange instance

func (*Binance) Account

func (b *Binance) Account() (model.Account, error)

func (*Binance) AssetsInfo

func (b *Binance) AssetsInfo(pair string) model.AssetInfo

func (*Binance) Cancel

func (b *Binance) Cancel(order model.Order) error

func (*Binance) CandlesByLimit

func (b *Binance) CandlesByLimit(ctx context.Context, pair, period string, limit int) ([]model.Candle, error)

func (*Binance) CandlesByPeriod

func (b *Binance) CandlesByPeriod(ctx context.Context, pair, period string,
	start, end time.Time,
) ([]model.Candle, error)

func (*Binance) CandlesSubscription

func (b *Binance) CandlesSubscription(ctx context.Context, pair, period string) (chan model.Candle, chan error)

func (*Binance) CreateOrderLimit

func (b *Binance) CreateOrderLimit(side model.SideType, pair string,
	quantity float64, limit float64,
) (model.Order, error)

func (*Binance) CreateOrderMarket

func (b *Binance) CreateOrderMarket(side model.SideType, pair string, quantity float64) (model.Order, error)

func (*Binance) CreateOrderMarketQuote

func (b *Binance) CreateOrderMarketQuote(side model.SideType, pair string, quantity float64) (model.Order, error)

func (*Binance) CreateOrderOCO

func (b *Binance) CreateOrderOCO(side model.SideType, pair string,
	quantity, price, stop, stopLimit float64,
) ([]model.Order, error)

func (*Binance) CreateOrderStop

func (b *Binance) CreateOrderStop(pair string, quantity float64, limit float64) (model.Order, error)

func (*Binance) LastQuote

func (b *Binance) LastQuote(ctx context.Context, pair string) (float64, error)

func (*Binance) Order

func (b *Binance) Order(pair string, id int64) (model.Order, error)

func (*Binance) Orders

func (b *Binance) Orders(pair string, limit int) ([]model.Order, error)

func (*Binance) Position

func (b *Binance) Position(pair string) (asset, quote float64, err error)

type BinanceFuture

type BinanceFuture struct {
	HeikinAshi bool
	Testnet    bool

	APIKey    string
	APISecret string

	MetadataFetchers []MetadataFetchers
	PairOptions      []PairOption
	// contains filtered or unexported fields
}

func NewBinanceFuture

func NewBinanceFuture(ctx context.Context, options ...BinanceFutureOption) (*BinanceFuture, error)

NewBinanceFuture will create a new BinanceFuture instance

func (*BinanceFuture) Account

func (b *BinanceFuture) Account() (model.Account, error)

func (*BinanceFuture) AssetsInfo

func (b *BinanceFuture) AssetsInfo(pair string) model.AssetInfo

func (*BinanceFuture) Cancel

func (b *BinanceFuture) Cancel(order model.Order) error

func (*BinanceFuture) CandlesByLimit

func (b *BinanceFuture) CandlesByLimit(ctx context.Context, pair, period string, limit int) ([]model.Candle, error)

func (*BinanceFuture) CandlesByPeriod

func (b *BinanceFuture) CandlesByPeriod(ctx context.Context, pair, period string,
	start, end time.Time,
) ([]model.Candle, error)

func (*BinanceFuture) CandlesSubscription

func (b *BinanceFuture) CandlesSubscription(ctx context.Context, pair, period string) (chan model.Candle, chan error)

func (*BinanceFuture) CreateOrderLimit

func (b *BinanceFuture) CreateOrderLimit(side model.SideType, pair string,
	quantity float64, limit float64,
) (model.Order, error)

func (*BinanceFuture) CreateOrderMarket

func (b *BinanceFuture) CreateOrderMarket(side model.SideType, pair string, quantity float64) (model.Order, error)

func (*BinanceFuture) CreateOrderMarketQuote

func (b *BinanceFuture) CreateOrderMarketQuote(_ model.SideType, _ string, _ float64) (model.Order, error)

func (*BinanceFuture) CreateOrderOCO

func (b *BinanceFuture) CreateOrderOCO(_ model.SideType, _ string,
	_, _, _, _ float64,
) ([]model.Order, error)

func (*BinanceFuture) CreateOrderStop

func (b *BinanceFuture) CreateOrderStop(pair string, quantity float64, limit float64) (model.Order, error)

func (*BinanceFuture) LastQuote

func (b *BinanceFuture) LastQuote(ctx context.Context, pair string) (float64, error)

func (*BinanceFuture) Order

func (b *BinanceFuture) Order(pair string, id int64) (model.Order, error)

func (*BinanceFuture) Orders

func (b *BinanceFuture) Orders(pair string, limit int) ([]model.Order, error)

func (*BinanceFuture) Position

func (b *BinanceFuture) Position(pair string) (asset, quote float64, err error)

type BinanceFutureOption

type BinanceFutureOption func(*BinanceFuture)

func WithBinanceFutureCredentials

func WithBinanceFutureCredentials(key, secret string) BinanceFutureOption

WithBinanceFutureCredentials will set the credentials for Binance Futures

func WithBinanceFutureLeverage

func WithBinanceFutureLeverage(pair string, leverage int, marginType MarginType) BinanceFutureOption

WithBinanceFutureLeverage will set the leverage for a pair

func WithBinanceFuturesHeikinAshiCandle

func WithBinanceFuturesHeikinAshiCandle() BinanceFutureOption

WithBinanceFuturesHeikinAshiCandle will use Heikin Ashi candle instead of regular candle

type BinanceOption

type BinanceOption func(*Binance)

func WithBinanceCredentials

func WithBinanceCredentials(key, secret string) BinanceOption

WithBinanceCredentials will set Binance credentials

func WithBinanceHeikinAshiCandle

func WithBinanceHeikinAshiCandle() BinanceOption

WithBinanceHeikinAshiCandle will convert candle to Heikin Ashi

func WithMetadataFetcher

func WithMetadataFetcher(fetcher MetadataFetchers) BinanceOption

WithMetadataFetcher will execute a function after receive a new candle and include additional information to candle's metadata

func WithTestNet

func WithTestNet() BinanceOption

WithTestNet activate Bianance testnet

type CSVFeed

type CSVFeed struct {
	Feeds               map[string]PairFeed
	CandlePairTimeFrame map[string][]model.Candle
}

func NewCSVFeed

func NewCSVFeed(targetTimeframe string, feeds ...PairFeed) (*CSVFeed, error)

NewCSVFeed creates a new data feed from CSV files and resample

func (CSVFeed) AssetsInfo

func (c CSVFeed) AssetsInfo(pair string) model.AssetInfo

func (*CSVFeed) CandlesByLimit

func (c *CSVFeed) CandlesByLimit(_ context.Context, pair, timeframe string, limit int) ([]model.Candle, error)

func (CSVFeed) CandlesByPeriod

func (c CSVFeed) CandlesByPeriod(_ context.Context, pair, timeframe string,
	start, end time.Time,
) ([]model.Candle, error)

func (CSVFeed) CandlesSubscription

func (c CSVFeed) CandlesSubscription(_ context.Context, pair, timeframe string) (chan model.Candle, chan error)

func (CSVFeed) LastQuote

func (c CSVFeed) LastQuote(_ context.Context, _ string) (float64, error)

func (*CSVFeed) Limit

func (c *CSVFeed) Limit(duration time.Duration) *CSVFeed

type DataFeed

type DataFeed struct {
	Data chan model.Candle
	Err  chan error
}

type DataFeedConsumer

type DataFeedConsumer func(model.Candle)

type DataFeedSubscription

type DataFeedSubscription struct {
	Feeds                   *set.LinkedHashSetString
	DataFeeds               map[string]*DataFeed
	SubscriptionsByDataFeed map[string][]Subscription
	// contains filtered or unexported fields
}

func NewDataFeed

func NewDataFeed(exchange service.Exchange) *DataFeedSubscription

func (*DataFeedSubscription) Connect

func (d *DataFeedSubscription) Connect()

func (*DataFeedSubscription) Preload

func (d *DataFeedSubscription) Preload(pair, timeframe string, candles []model.Candle)

func (*DataFeedSubscription) Start

func (d *DataFeedSubscription) Start(loadSync bool)

func (*DataFeedSubscription) Subscribe

func (d *DataFeedSubscription) Subscribe(pair, timeframe string, consumer DataFeedConsumer, onCandleClose bool)

type MarginType

type MarginType = futures.MarginType

type MetadataFetchers

type MetadataFetchers func(pair string, t time.Time) (string, float64)

type OrderError

type OrderError struct {
	Err      error
	Pair     string
	Quantity float64
}

func (*OrderError) Error

func (o *OrderError) Error() string

type PairFeed

type PairFeed struct {
	Pair       string
	File       string
	Timeframe  string
	HeikinAshi bool
}

type PairOption

type PairOption struct {
	Pair       string
	Leverage   int
	MarginType futures.MarginType
}

type PaperWallet

type PaperWallet struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewPaperWallet

func NewPaperWallet(ctx context.Context, baseCoin string, options ...PaperWalletOption) *PaperWallet

func (*PaperWallet) Account

func (p *PaperWallet) Account() (model.Account, error)

func (*PaperWallet) AssetValues

func (p *PaperWallet) AssetValues(pair string) []AssetValue

func (*PaperWallet) AssetsInfo

func (p *PaperWallet) AssetsInfo(pair string) model.AssetInfo

func (*PaperWallet) Cancel

func (p *PaperWallet) Cancel(order model.Order) error

func (*PaperWallet) CandlesByLimit

func (p *PaperWallet) CandlesByLimit(ctx context.Context, pair, period string, limit int) ([]model.Candle, error)

func (*PaperWallet) CandlesByPeriod

func (p *PaperWallet) CandlesByPeriod(ctx context.Context, pair, period string,
	start, end time.Time,
) ([]model.Candle, error)

func (*PaperWallet) CandlesSubscription

func (p *PaperWallet) CandlesSubscription(ctx context.Context, pair, timeframe string) (chan model.Candle, chan error)

func (*PaperWallet) CreateOrderLimit

func (p *PaperWallet) CreateOrderLimit(side model.SideType, pair string,
	size float64, limit float64,
) (model.Order, error)

func (*PaperWallet) CreateOrderMarket

func (p *PaperWallet) CreateOrderMarket(side model.SideType, pair string, size float64) (model.Order, error)

func (*PaperWallet) CreateOrderMarketQuote

func (p *PaperWallet) CreateOrderMarketQuote(side model.SideType, pair string,
	quoteQuantity float64,
) (model.Order, error)

func (*PaperWallet) CreateOrderOCO

func (p *PaperWallet) CreateOrderOCO(side model.SideType, pair string,
	size, price, stop, stopLimit float64,
) ([]model.Order, error)

func (*PaperWallet) CreateOrderStop

func (p *PaperWallet) CreateOrderStop(pair string, size float64, limit float64) (model.Order, error)

func (*PaperWallet) EquityValues

func (p *PaperWallet) EquityValues() []AssetValue

func (*PaperWallet) ID

func (p *PaperWallet) ID() int64

func (*PaperWallet) LastQuote

func (p *PaperWallet) LastQuote(ctx context.Context, pair string) (float64, error)

func (*PaperWallet) MaxDrawdown

func (p *PaperWallet) MaxDrawdown() (float64, time.Time, time.Time)

func (*PaperWallet) OnCandle

func (p *PaperWallet) OnCandle(candle model.Candle)

func (*PaperWallet) Order

func (p *PaperWallet) Order(_ string, id int64) (model.Order, error)

func (*PaperWallet) Pairs

func (p *PaperWallet) Pairs() []string

func (*PaperWallet) Position

func (p *PaperWallet) Position(pair string) (asset, quote float64, err error)

func (*PaperWallet) Summary

func (p *PaperWallet) Summary()

type PaperWalletOption

type PaperWalletOption func(*PaperWallet)

func WithDataFeed

func WithDataFeed(feeder service.Feeder) PaperWalletOption

func WithPaperAsset

func WithPaperAsset(pair string, amount float64) PaperWalletOption

func WithPaperFee

func WithPaperFee(maker, taker float64) PaperWalletOption

type Subscription

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

Jump to

Keyboard shortcuts

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