exchange

package
v0.0.0-...-0d73d77 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFeePrice = 0.5

Variables

This section is empty.

Functions

This section is empty.

Types

type Candle

type Candle = hs.Candle

type Config

type Config struct {
	hs.ExchangeConf
	FeeCurrency string `json:"feeCurrency"` // eg. HT
	ClientId    string `json:"clientId"`
	Period      string // candle type, 1m, 15m, 1h

	Csv *CsvExchangeConfig `json:"csv,omitempty"`
}

type CsvExchange

type CsvExchange struct {
	FeeRatio decimal.Decimal
	// contains filtered or unexported fields
}

func NewCsvExchange

func NewCsvExchange(config CsvExchangeConfig, symbols []string) *CsvExchange

func (*CsvExchange) AmountPrecision

func (c *CsvExchange) AmountPrecision() int32

func (*CsvExchange) Balance

func (c *CsvExchange) Balance() (cash, currency, fee decimal.Decimal)

func (*CsvExchange) BaseCurrency

func (c *CsvExchange) BaseCurrency() string

func (*CsvExchange) Buy

func (c *CsvExchange) Buy(price, amount decimal.Decimal, clientId string) (hs.Order, error)

func (*CsvExchange) FeeCurrency

func (c *CsvExchange) FeeCurrency() string

func (*CsvExchange) FeePrice

func (c *CsvExchange) FeePrice() (decimal.Decimal, error)

func (*CsvExchange) LastPrice

func (c *CsvExchange) LastPrice() decimal.Decimal

func (*CsvExchange) MinAmount

func (c *CsvExchange) MinAmount() decimal.Decimal

func (*CsvExchange) MinTotal

func (c *CsvExchange) MinTotal() decimal.Decimal

func (*CsvExchange) Price

func (c *CsvExchange) Price() (decimal.Decimal, error)

func (*CsvExchange) PricePrecision

func (c *CsvExchange) PricePrecision() int32

func (*CsvExchange) QuoteCurrency

func (c *CsvExchange) QuoteCurrency() string

func (*CsvExchange) Sell

func (c *CsvExchange) Sell(price, amount decimal.Decimal, clientId string) (hs.Order, error)

func (*CsvExchange) SetCandleChannel

func (c *CsvExchange) SetCandleChannel(candleCh chan Candle)

func (*CsvExchange) SetTickerChannel

func (c *CsvExchange) SetTickerChannel(tickerCh chan Ticker)

func (*CsvExchange) Start

func (c *CsvExchange) Start(ctx context.Context)

func (*CsvExchange) Symbol

func (c *CsvExchange) Symbol() string

type CsvExchangeConfig

type CsvExchangeConfig struct {
	File      string `json:"file"`
	StartTime string `json:"startTime"`

	Balance     map[string]float64
	FeeCurrency string  `json:"feeCurrency"`
	FeeRatio    float64 `json:"feeRatio"`
	FeePrice    float64 `json:"feePrice"`
}

type Exchange

type Exchange interface {
	Symbol() string

	QuoteCurrency() string // BTC/USDT -> USDT
	BaseCurrency() string  // BTC/USDT -> BTC
	FeeCurrency() string

	MinAmount() decimal.Decimal
	MinTotal() decimal.Decimal
	PricePrecision() int32
	AmountPrecision() int32

	Balance() (cash, currency, fee decimal.Decimal)

	Price() (decimal.Decimal, error)
	FeePrice() (decimal.Decimal, error)

	Buy(price, amount decimal.Decimal, clientId string) (hs.Order, error)
	Sell(price, amount decimal.Decimal, clientId string) (hs.Order, error)

	SetTickerChannel(tickerCh chan Ticker)
	SetCandleChannel(candleCh chan Candle)
	Start(ctx context.Context)
}

exchange interface for turtle trade only. with only one symbol, only one fee currency, and almost no error

func New

func New(config Config) (ex Exchange)

type Ticker

type Ticker = hs.Ticker

type TurtleExchange

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

func NewTurtle

func NewTurtle(config Config) *TurtleExchange

func (*TurtleExchange) AmountPrecision

func (t *TurtleExchange) AmountPrecision() int32

func (*TurtleExchange) Balance

func (t *TurtleExchange) Balance() (cash, currency, fee decimal.Decimal)

func (*TurtleExchange) BaseCurrency

func (t *TurtleExchange) BaseCurrency() string

func (*TurtleExchange) Buy

func (t *TurtleExchange) Buy(price, amount decimal.Decimal, clientId string) (hs.Order, error)

func (*TurtleExchange) FeeCurrency

func (t *TurtleExchange) FeeCurrency() string

func (*TurtleExchange) FeePrice

func (t *TurtleExchange) FeePrice() (decimal.Decimal, error)

func (*TurtleExchange) MinAmount

func (t *TurtleExchange) MinAmount() decimal.Decimal

func (*TurtleExchange) MinTotal

func (t *TurtleExchange) MinTotal() decimal.Decimal

func (*TurtleExchange) Price

func (t *TurtleExchange) Price() (decimal.Decimal, error)

func (*TurtleExchange) PricePrecision

func (t *TurtleExchange) PricePrecision() int32

func (*TurtleExchange) QuoteCurrency

func (t *TurtleExchange) QuoteCurrency() string

func (*TurtleExchange) Sell

func (t *TurtleExchange) Sell(price, amount decimal.Decimal, clientId string) (hs.Order, error)

func (*TurtleExchange) SetCandleChannel

func (t *TurtleExchange) SetCandleChannel(candleCh chan Candle)

func (*TurtleExchange) SetTickerChannel

func (t *TurtleExchange) SetTickerChannel(tickerCh chan Ticker)

func (*TurtleExchange) Start

func (t *TurtleExchange) Start(ctx context.Context)

func (*TurtleExchange) Symbol

func (t *TurtleExchange) Symbol() string

Jump to

Keyboard shortcuts

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