hs

package module
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: MIT Imports: 9 Imported by: 32

README

hs

hs golang utils lib

Documentation

Index

Constants

View Source
const (
	GateIO = "gate"
	MXC    = "mxc"
	OKEx   = "okex"
	Huobi  = "huobi"
)
View Source
const (
	Open      OrderStatus = 1 // open but not filled
	Closed                = 2 // full filled
	Filled                = 3 // part filled
	Cancelled             = 4
)
View Source
const (
	MIN1  = time.Minute
	MIN5  = time.Minute * 5
	MIN15 = time.Minute * 15
	MIN30 = time.Minute * 30
	HOUR1 = time.Hour
	HOUR4 = time.Hour * 4
	DAY1  = time.Hour * 24
	MON1  = DAY1 * 30
	WEEK1 = DAY1 * 7
	YEAR1 = DAY1 * 365
)

Variables

This section is empty.

Functions

func ConnectMongo added in v0.6.0

func ConnectMongo(ctx context.Context, conf MongoConf) (*mongo.Database, error)

func IsDuplicateError added in v0.6.0

func IsDuplicateError(err error) bool

func ParseJsonConfig

func ParseJsonConfig(filename string, config interface{}) error

Types

type BroadcastConf added in v0.7.7

type BroadcastConf = broadcast.Config

type Candle added in v0.7.5

type Candle struct {
	Capacity  int
	Timestamp []int64 // unix timestamp in seconds
	Open      []float64
	High      []float64
	Low       []float64
	Close     []float64
	Volume    []float64
}

func NewCandle added in v0.7.5

func NewCandle(capacity int) Candle

func (*Candle) Add added in v0.7.5

func (c *Candle) Add(other Candle)

func (*Candle) Append added in v0.7.5

func (c *Candle) Append(ticker Ticker)

func (Candle) Length added in v0.7.5

func (c Candle) Length() int

func (*Candle) Truncate added in v0.7.13

func (c *Candle) Truncate()

type Exchange added in v0.7.2

type Exchange interface {
	RestAPIExchange
	WsAPIExchange
}

common exchange interface, for all symbols, all crypto-exchanges

type ExchangeConf added in v0.5.1

type ExchangeConf struct {
	Name    string // see const below
	Label   string
	Symbols []string
	Key     string
	Secret  string
	Host    string
}

type Grid added in v0.5.8

type Grid struct {
	Id         int
	Price      decimal.Decimal
	AmountBuy  decimal.Decimal
	AmountSell decimal.Decimal
	TotalBuy   decimal.Decimal
	Order      uint64
}

type GridStrategyConf added in v0.5.8

type GridStrategyConf struct {
	MaxPrice float64
	MinPrice float64
	Number   int
	Total    float64
}

type HistoryConf added in v0.6.1

type HistoryConf struct {
	Prefix   string
	Interval string
}

type MongoConf added in v0.5.0

type MongoConf struct {
	// mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
	URI         string `json:"uri"`
	Database    string `json:"database"`
	MaxPoolSize uint64 `json:"maxPoolSize"`
	MinPoolSize uint64 `json:"minPoolSize"`
	AppName     string `json:"appName"`
}

type MySQLConf added in v0.5.0

type MySQLConf struct {
	URI string `json:"uri"`
}

type Order added in v0.7.14

type Order struct {
	Id       uint64
	ClientId string

	Type          OrderType
	Symbol        string
	InitialPrice  decimal.Decimal
	InitialAmount decimal.Decimal
	Timestamp     int64

	Status OrderStatus

	FilledPrice  decimal.Decimal
	FilledAmount decimal.Decimal
	Trades       []Trade
	Fee          map[string]decimal.Decimal
}

type OrderStatus added in v0.7.14

type OrderStatus = int

type OrderType added in v0.7.15

type OrderType = int
const (
	Buy  OrderType = 1
	Sell           = -1
)

type RestAPIExchange added in v0.10.0

type RestAPIExchange interface {
	PricePrecision(symbol string) int32
	AmountPrecision(symbol string) int32
	MinAmount(symbol string) decimal.Decimal
	MinTotal(symbol string) decimal.Decimal

	SpotAvailableBalance() (map[string]decimal.Decimal, error)
	LastPrice(symbol string) (decimal.Decimal, error)
	Candle(symbol string, period time.Duration, size int) (Candle, error)

	//PlaceOrder(orderType, symbol, clientOrderId string, price, amount decimal.Decimal) (uint64, error)
	BuyLimit(symbol, clientOrderId string, price, amount decimal.Decimal) (orderId uint64, err error)
	SellLimit(symbol, clientOrderId string, price, amount decimal.Decimal) (orderId uint64, err error)
	BuyStopLimit(symbol, clientOrderId string, price, amount, stopPrice decimal.Decimal, operator string) (orderId uint64, err error)
	SellStopLimit(symbol, clientOrderId string, price, amount, stopPrice decimal.Decimal, operator string) (orderId uint64, err error)
	CancelOrder(symbol string, orderId uint64) error
}

common exchange interface for all symbols

type RestGridStrategyConf added in v0.5.8

type RestGridStrategyConf struct {
	MaxPrice  float64
	MinPrice  float64
	Number    int
	Total     float64
	Rebalance bool
	Interval  string // sleep interval
}

type SQLiteConf added in v0.5.8

type SQLiteConf struct {
	Location string
}

type Ticker added in v0.7.5

type Ticker struct {
	Timestamp int64 // unix timestamp in seconds
	Open      float64
	High      float64
	Low       float64
	Close     float64
	Volume    float64
}

type Trade added in v0.7.14

type Trade struct {
	Id          uint64
	Price       decimal.Decimal
	Amount      decimal.Decimal
	FeeCurrency string
	FeeAmount   decimal.Decimal
}

type WsAPIExchange added in v0.10.0

type WsAPIExchange interface {
	SubscribeCandlestick(ctx context.Context, symbol, clientId string, period time.Duration, responseHandler websocketclientbase.ResponseHandler)
	SubscribeCandlestickWithReq(ctx context.Context, symbol, clientId string, period time.Duration, responseHandler websocketclientbase.ResponseHandler)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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