Documentation
¶
Overview ¶
Package exchange provides implementations for various data exchange mechanisms
Package exchange provides functionality for interacting with cryptocurrency exchanges and subscribing to data feeds for market information.
Package exchange provides functionality for interacting with cryptocurrency exchanges and managing trading pair information.
Package exchange provides functionality for interacting with cryptocurrency exchanges and simulating trading activities.
Index ¶
- Variables
- func SavePairsToFile(filename string) error
- func SplitAssetQuote(pair string) (asset string, quote string)
- func UpdateAndSavePairs(ctx context.Context, filename string) error
- func UpdatePairs(ctx context.Context) error
- type AssetQuote
- type AssetValue
- type CSVFeed
- func (c CSVFeed) AssetsInfo(pair string) (core.AssetInfo, error)
- func (c *CSVFeed) CandlesByLimit(_ context.Context, pair, timeframe string, limit int) ([]core.Candle, error)
- func (c CSVFeed) CandlesByPeriod(_ context.Context, pair, timeframe string, start, end time.Time) ([]core.Candle, error)
- func (c CSVFeed) CandlesSubscription(_ context.Context, pair, timeframe string) (chan core.Candle, chan error)
- func (c CSVFeed) LastQuote(_ context.Context, _ string) (float64, error)
- func (c *CSVFeed) Limit(duration time.Duration) *CSVFeed
- type DataFeed
- type DataFeedConsumer
- type DataFeedSubscription
- func (d *DataFeedSubscription) Connect()
- func (d *DataFeedSubscription) Preload(ctx context.Context, pair, timeframe string, candles []core.Candle)
- func (d *DataFeedSubscription) Start(ctx context.Context, waitForCompletion bool)
- func (d *DataFeedSubscription) Subscribe(pair, timeframe string, consumer DataFeedConsumer, onCandleClose bool)
- type OrderError
- type PairFeed
- type PairService
- type PaperWallet
- func (p *PaperWallet) Account(_ context.Context) (core.Account, error)
- func (p *PaperWallet) AssetValues(pair string) []AssetValue
- func (p *PaperWallet) AssetsInfo(pair string) (core.AssetInfo, error)
- func (p *PaperWallet) Cancel(_ context.Context, order core.Order) error
- func (p *PaperWallet) CandlesByLimit(ctx context.Context, pair, period string, limit int) ([]core.Candle, error)
- func (p *PaperWallet) CandlesByPeriod(ctx context.Context, pair, period string, start, end time.Time) ([]core.Candle, error)
- func (p *PaperWallet) CandlesSubscription(ctx context.Context, pair, timeframe string) (chan core.Candle, chan error)
- func (p *PaperWallet) CreateOrderLimit(_ context.Context, side core.SideType, pair string, size float64, ...) (core.Order, error)
- func (p *PaperWallet) CreateOrderMarket(ctx context.Context, side core.SideType, pair string, size float64) (core.Order, error)
- func (p *PaperWallet) CreateOrderMarketQuote(ctx context.Context, side core.SideType, pair string, quoteQuantity float64) (core.Order, error)
- func (p *PaperWallet) CreateOrderOCO(_ context.Context, side core.SideType, pair string, ...) ([]core.Order, error)
- func (p *PaperWallet) CreateOrderStop(_ context.Context, pair string, size float64, limit float64) (core.Order, error)
- func (p *PaperWallet) EquityValues() []AssetValue
- func (p *PaperWallet) ID() int64
- func (p *PaperWallet) LastQuote(ctx context.Context, pair string) (float64, error)
- func (p *PaperWallet) MaxDrawdown() (float64, time.Time, time.Time)
- func (p *PaperWallet) OnCandle(candle core.Candle)
- func (p *PaperWallet) Order(_ context.Context, _ string, id int64) (core.Order, error)
- func (p *PaperWallet) Pairs() []string
- func (p *PaperWallet) Position(ctx context.Context, pair string) (asset, quote float64, err error)
- func (p *PaperWallet) Summary()
- type PaperWalletOption
- type PeriodBoundaryCheck
- type Subscription
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidQuantity = errors.New("invalid quantity") ErrInsufficientFunds = errors.New("insufficient funds or locked") ErrInvalidAsset = errors.New("invalid asset") )
Common errors that can occur during exchange operations
var ( // ErrInsufficientData is returned when there is not enough data to fulfill a request ErrInsufficientData = errors.New("insufficient data") )
Functions ¶
func SavePairsToFile ¶
SavePairsToFile saves the pair map to a file
func SplitAssetQuote ¶
SplitAssetQuote splits a pair into its asset and quote components
func UpdateAndSavePairs ¶
UpdateAndSavePairs updates and saves the pair map to a file
func UpdatePairs ¶
UpdatePairs updates the pair map from the Binance API
Types ¶
type AssetQuote ¶
AssetQuote represents a trading pair (base asset and quote currency)
func GetPair ¶
func GetPair(pair string) (AssetQuote, bool)
GetPair returns the AssetQuote information for a pair
type AssetValue ¶
AssetValue represents the value of an asset at a specific time
type CSVFeed ¶
CSVFeed represents a data feed from CSV files
func NewCSVFeed ¶
NewCSVFeed creates a new CSV feed and resamples data to the target timeframe
func (CSVFeed) AssetsInfo ¶
AssetsInfo returns information about a trading pair's assets
func (*CSVFeed) CandlesByLimit ¶
func (c *CSVFeed) CandlesByLimit(_ context.Context, pair, timeframe string, limit int) ([]core.Candle, error)
CandlesByLimit returns a limited number of candles and removes them from the feed
func (CSVFeed) CandlesByPeriod ¶
func (c CSVFeed) CandlesByPeriod(_ context.Context, pair, timeframe string, start, end time.Time) ([]core.Candle, error)
CandlesByPeriod returns candles within a specific time period
func (CSVFeed) CandlesSubscription ¶
func (c CSVFeed) CandlesSubscription(_ context.Context, pair, timeframe string) (chan core.Candle, chan error)
CandlesSubscription returns a channel to receive candles
type DataFeedConsumer ¶
DataFeedConsumer is a function type that processes candle data
type DataFeedSubscription ¶
type DataFeedSubscription struct {
// contains filtered or unexported fields
}
DataFeedSubscription manages subscriptions to data feeds
func NewDataFeed ¶
func NewDataFeed(exchange core.Exchange, log core.Logger) *DataFeedSubscription
NewDataFeed creates a new instance of DataFeedSubscription
func (*DataFeedSubscription) Connect ¶
func (d *DataFeedSubscription) Connect()
Connect establishes connections to the exchange and initializes feeds
func (*DataFeedSubscription) Preload ¶
func (d *DataFeedSubscription) Preload(ctx context.Context, pair, timeframe string, candles []core.Candle)
Preload loads historical candles for a specific subscription
func (*DataFeedSubscription) Start ¶
func (d *DataFeedSubscription) Start(ctx context.Context, waitForCompletion bool)
Start begins processing all feeds
func (*DataFeedSubscription) Subscribe ¶
func (d *DataFeedSubscription) Subscribe(pair, timeframe string, consumer DataFeedConsumer, onCandleClose bool)
Subscribe adds a new subscription for a pair and timeframe
type OrderError ¶
OrderError encapsulates an error related to an order
type PairService ¶
type PairService struct {
// contains filtered or unexported fields
}
PairService manages information about trading pairs
func NewPairService ¶
func NewPairService(pairsData []byte) (*PairService, error)
NewPairService creates a new instance of the pair service
type PaperWallet ¶
type PaperWallet struct {
// contains filtered or unexported fields
}
PaperWallet implements a simulated wallet for backtesting
func NewPaperWallet ¶
func NewPaperWallet(ctx context.Context, baseCoin string, log core.Logger, options ...PaperWalletOption) *PaperWallet
NewPaperWallet creates a new simulated wallet
func (*PaperWallet) AssetValues ¶
func (p *PaperWallet) AssetValues(pair string) []AssetValue
AssetValues returns the value history of an asset
func (*PaperWallet) AssetsInfo ¶
func (p *PaperWallet) AssetsInfo(pair string) (core.AssetInfo, error)
AssetsInfo returns information about the assets of a pair
func (*PaperWallet) CandlesByLimit ¶
func (p *PaperWallet) CandlesByLimit(ctx context.Context, pair, period string, limit int) ([]core.Candle, error)
CandlesByLimit returns a limited number of candles
func (*PaperWallet) CandlesByPeriod ¶
func (p *PaperWallet) CandlesByPeriod(ctx context.Context, pair, period string, start, end time.Time) ([]core.Candle, error)
CandlesByPeriod returns candles within a period
func (*PaperWallet) CandlesSubscription ¶
func (p *PaperWallet) CandlesSubscription(ctx context.Context, pair, timeframe string) (chan core.Candle, chan error)
CandlesSubscription returns a channel to receive candles
func (*PaperWallet) CreateOrderLimit ¶
func (p *PaperWallet) CreateOrderLimit(_ context.Context, side core.SideType, pair string, size float64, limit float64) (core.Order, error)
CreateOrderLimit creates a limit order
func (*PaperWallet) CreateOrderMarket ¶
func (p *PaperWallet) CreateOrderMarket(ctx context.Context, side core.SideType, pair string, size float64) (core.Order, error)
CreateOrderMarket creates a market order
func (*PaperWallet) CreateOrderMarketQuote ¶
func (p *PaperWallet) CreateOrderMarketQuote( ctx context.Context, side core.SideType, pair string, quoteQuantity float64, ) (core.Order, error)
CreateOrderMarketQuote creates a market order with a quantity in quote currency
func (*PaperWallet) CreateOrderOCO ¶
func (p *PaperWallet) CreateOrderOCO(_ context.Context, side core.SideType, pair string, size, price, stop, stopLimit float64) ([]core.Order, error)
CreateOrderOCO creates an OCO (One-Cancels-the-Other) order
func (*PaperWallet) CreateOrderStop ¶
func (p *PaperWallet) CreateOrderStop(_ context.Context, pair string, size float64, limit float64) (core.Order, error)
CreateOrderStop creates a stop order
func (*PaperWallet) EquityValues ¶
func (p *PaperWallet) EquityValues() []AssetValue
EquityValues returns the wallet's value history
func (*PaperWallet) MaxDrawdown ¶
MaxDrawdown calculates the maximum drawdown of the wallet
func (*PaperWallet) OnCandle ¶
func (p *PaperWallet) OnCandle(candle core.Candle)
OnCandle processes a new candle
func (*PaperWallet) Pairs ¶
func (p *PaperWallet) Pairs() []string
Pairs returns the list of available pairs in the wallet
func (*PaperWallet) Summary ¶
func (p *PaperWallet) Summary()
Summary prints a summary of the wallet
type PaperWalletOption ¶
type PaperWalletOption func(*PaperWallet)
PaperWalletOption defines an option function to configure PaperWallet
func WithDataFeed ¶
func WithDataFeed(feeder core.Feeder) PaperWalletOption
WithDataFeed configures the data provider
func WithPaperAsset ¶
func WithPaperAsset(pair string, amount float64) PaperWalletOption
WithPaperAsset adds an initial asset to the wallet
func WithPaperFee ¶
func WithPaperFee(maker, taker float64) PaperWalletOption
WithPaperFee configures the wallet fees
type PeriodBoundaryCheck ¶
PeriodBoundaryCheck defines an interface for checking period boundaries
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription represents a consumer subscription to a data feed