exchange

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 23 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) AccountSubscription added in v0.3.9

func (b *Binance) AccountSubscription(ctx context.Context) (chan model.Order, chan 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) CancelOpenOrders added in v0.1.9

func (b *Binance) CancelOpenOrders(pair string) 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, reduceOnly bool) (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) CreateOrderTrailingStop added in v0.3.6

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

func (*Binance) LastQuote

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

func (*Binance) OpenOrders added in v0.2.3

func (b *Binance) OpenOrders(pair string) ([]model.Order, 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)

func (*Binance) TakeProfit added in v0.2.1

func (b *Binance) TakeProfit(side model.SideType, pair string, quantity float64, limit float64) (model.Order, 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) AccountSubscription added in v0.3.9

func (b *BinanceFuture) AccountSubscription(ctx context.Context) (chan model.Order, chan 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) CancelOpenOrders added in v0.1.9

func (b *BinanceFuture) CancelOpenOrders(pair string) 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) Client added in v0.2.4

func (b *BinanceFuture) Client() *futures.Client

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, reduceOnly bool) (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) CreateOrderTrailingStop added in v0.3.6

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

func (*BinanceFuture) LastQuote

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

func (*BinanceFuture) OpenOrders added in v0.2.3

func (b *BinanceFuture) OpenOrders(pair string) ([]model.Order, 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)

func (*BinanceFuture) TakeProfit added in v0.2.1

func (b *BinanceFuture) TakeProfit(side model.SideType, pair string, quantity float64, limit float64) (model.Order, 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 WithCustomMainAPIEndpoint added in v0.3.8

func WithCustomMainAPIEndpoint(apiURL, wsURL, combinedURL string) BinanceOption

WithCustomMainAPIEndpoint will set custom endpoints for the Binance Main API

func WithCustomTestnetAPIEndpoint added in v0.3.8

func WithCustomTestnetAPIEndpoint(apiURL, wsURL, combinedURL string) BinanceOption

WithCustomTestnetAPIEndpoint will set custom endpoints for the Binance Testnet API

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) AccountSubscription added in v0.3.9

func (c CSVFeed) AccountSubscription(ctx context.Context) (chan model.Order, chan error)

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) AccountSubscription added in v0.3.9

func (p *PaperWallet) AccountSubscription(ctx context.Context) (chan model.Order, chan 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) CancelOpenOrders added in v0.1.9

func (p *PaperWallet) CancelOpenOrders(pair string) 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, reduceOnly bool) (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) CreateOrderTrailingStop added in v0.3.6

func (p *PaperWallet) CreateOrderTrailingStop(pair string, side model.SideType, limit float64, quantity float64, callBackRate string) (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) OpenOrders added in v0.2.3

func (p *PaperWallet) OpenOrders(pair string) ([]model.Order, error)

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()

func (*PaperWallet) TakeProfit added in v0.2.1

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

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