types

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: MIT Imports: 16 Imported by: 161

Documentation

Index

Constants

View Source
const (
	DepositOther = DepositStatus("")

	DepositPending = DepositStatus("pending")

	DepositRejected = DepositStatus("rejected")

	DepositSuccess = DepositStatus("success")

	DepositCancelled = DepositStatus("canceled")

	// created but can not withdraw
	DepositCredited = DepositStatus("credited")
)
View Source
const (
	ExchangeMax     = ExchangeName("max")
	ExchangeBinance = ExchangeName("binance")
)
View Source
const (
	SideTypeBuy  = SideType("BUY")
	SideTypeSell = SideType("SELL")
	SideTypeSelf = SideType("SELF")
)
View Source
const DateFormat = "2006-01-02"
View Source
const Green = "#228B22"
View Source
const Red = "#800000"
View Source
const TrendDown = -1
View Source
const TrendFlat = 0
View Source
const TrendUp = 1

Variables

View Source
var BNB = accounting.Accounting{Symbol: "BNB ", Precision: 4}
View Source
var BTC = accounting.Accounting{Symbol: "BTC ", Precision: 2}
View Source
var BookChannel = Channel("book")
View Source
var Interval12h = Interval("12h")
View Source
var Interval15m = Interval("15m")
View Source
var Interval1d = Interval("1d")
View Source
var Interval1h = Interval("1h")
View Source
var Interval1m = Interval("1m")
View Source
var Interval2h = Interval("2h")
View Source
var Interval30m = Interval("30m")
View Source
var Interval3d = Interval("3d")
View Source
var Interval4h = Interval("4h")
View Source
var Interval5m = Interval("5m")
View Source
var Interval6h = Interval("6h")
View Source
var KLineChannel = Channel("kline")
View Source
var MarketBNBUSDT = Market{
	Symbol:          "BNBUSDT",
	BaseCurrency:    "BNB",
	QuoteCurrency:   "USDT",
	PricePrecision:  4,
	VolumePrecision: 2,
	MinQuantity:     0.01,
	MinLot:          0.01,
	MinAmount:       10.0,
	MinNotional:     10.0,
}
View Source
var MarketBTCUSDT = Market{
	Symbol:          "BTCUSDT",
	BaseCurrency:    "BTC",
	QuoteCurrency:   "USDT",
	PricePrecision:  2,
	VolumePrecision: 6,
	MinQuantity:     0.000001,
	MinLot:          0.000001,
	MinAmount:       10.0,
	MinNotional:     10.0,
}
View Source
var MarketETHUSDT = Market{
	Symbol:          "ETHUSDT",
	BaseCurrency:    "ETH",
	QuoteCurrency:   "USDT",
	PricePrecision:  2,
	VolumePrecision: 5,
	MinQuantity:     0.01,
	MinLot:          0.01,
	MinAmount:       10.0,
	MinNotional:     10.0,
}
View Source
var Markets = map[string]Market{
	"ETHUSDT": MarketETHUSDT,
	"BNBUSDT": MarketBNBUSDT,
	"BTCUSDT": MarketBTCUSDT,
}
View Source
var SupportedIntervals = map[Interval]int{
	Interval1m:  1,
	Interval5m:  5,
	Interval15m: 15,
	Interval30m: 30,
	Interval1h:  60,
	Interval2h:  60 * 2,
	Interval4h:  60 * 4,
	Interval6h:  60 * 6,
	Interval12h: 60 * 12,
	Interval1d:  60 * 24,
	Interval3d:  60 * 24 * 3,
}
View Source
var USD = accounting.Accounting{Symbol: "$ ", Precision: 2}

Functions

func SideToColorName

func SideToColorName(side SideType) string

Types

type Account

type Account struct {
	sync.Mutex

	MakerCommission int    `json:"makerCommission"`
	TakerCommission int    `json:"takerCommission"`
	AccountType     string `json:"accountType"`
	// contains filtered or unexported fields
}

func NewAccount

func NewAccount() *Account

func (*Account) AddBalance

func (a *Account) AddBalance(currency string, fund fixedpoint.Value) error

func (*Account) Balance

func (a *Account) Balance(currency string) (balance Balance, ok bool)

func (*Account) Balances

func (a *Account) Balances() BalanceMap

Balances lock the balances and returned the copied balances

func (*Account) BindStream

func (a *Account) BindStream(stream Stream)

func (*Account) LockBalance

func (a *Account) LockBalance(currency string, locked fixedpoint.Value) error

func (*Account) Print

func (a *Account) Print()

func (*Account) UnlockBalance

func (a *Account) UnlockBalance(currency string, unlocked fixedpoint.Value) error

func (*Account) UpdateBalances

func (a *Account) UpdateBalances(balances BalanceMap)

func (*Account) UseLockedBalance

func (a *Account) UseLockedBalance(currency string, fund fixedpoint.Value) error

type Balance

type Balance struct {
	Currency  string           `json:"currency"`
	Available fixedpoint.Value `json:"available"`
	Locked    fixedpoint.Value `json:"locked"`
}

type BalanceMap

type BalanceMap map[string]Balance

func (BalanceMap) Print

func (m BalanceMap) Print()

type Channel

type Channel string

type Deposit

type Deposit struct {
	Time          time.Time     `json:"time"`
	Amount        float64       `json:"amount"`
	Asset         string        `json:"asset"`
	Address       string        `json:"address"`
	AddressTag    string        `json:"addressTag"`
	TransactionID string        `json:"txId"`
	Status        DepositStatus `json:"status"`
}

func (Deposit) EffectiveTime

func (d Deposit) EffectiveTime() time.Time

type DepositStatus

type DepositStatus string

type Exchange

type Exchange interface {
	Name() ExchangeName

	PlatformFeeCurrency() string

	NewStream() Stream

	QueryMarkets(ctx context.Context) (MarketMap, error)

	QueryAccount(ctx context.Context) (*Account, error)

	QueryAccountBalances(ctx context.Context) (BalanceMap, error)

	QueryKLines(ctx context.Context, symbol string, interval Interval, options KLineQueryOptions) ([]KLine, error)

	QueryTrades(ctx context.Context, symbol string, options *TradeQueryOptions) ([]Trade, error)

	QueryDepositHistory(ctx context.Context, asset string, since, until time.Time) (allDeposits []Deposit, err error)

	QueryWithdrawHistory(ctx context.Context, asset string, since, until time.Time) (allWithdraws []Withdraw, err error)

	SubmitOrders(ctx context.Context, orders ...SubmitOrder) (createdOrders OrderSlice, err error)

	QueryOpenOrders(ctx context.Context, symbol string) (orders []Order, err error)

	QueryClosedOrders(ctx context.Context, symbol string, since, until time.Time, lastOrderID uint64) (orders []Order, err error)

	CancelOrders(ctx context.Context, orders ...Order) error
}

type ExchangeBatchProcessor

type ExchangeBatchProcessor struct {
	Exchange
}

func (ExchangeBatchProcessor) BatchQueryClosedOrders

func (e ExchangeBatchProcessor) BatchQueryClosedOrders(ctx context.Context, symbol string, startTime, endTime time.Time, lastOrderID uint64) (c chan Order, errC chan error)

func (ExchangeBatchProcessor) BatchQueryKLines

func (e ExchangeBatchProcessor) BatchQueryKLines(ctx context.Context, symbol string, interval Interval, startTime, endTime time.Time) (c chan KLine, errC chan error)

func (ExchangeBatchProcessor) BatchQueryTrades

func (e ExchangeBatchProcessor) BatchQueryTrades(ctx context.Context, symbol string, options *TradeQueryOptions) (c chan Trade, errC chan error)

type ExchangeName

type ExchangeName string

func ValidExchangeName

func ValidExchangeName(a string) (ExchangeName, error)

func (ExchangeName) String

func (n ExchangeName) String() string

type Interval

type Interval string

func (Interval) Duration

func (i Interval) Duration() time.Duration

func (Interval) Minutes

func (i Interval) Minutes() int

func (Interval) String

func (i Interval) String() string

func (*Interval) UnmarshalJSON

func (i *Interval) UnmarshalJSON(b []byte) (err error)

type IntervalSlice

type IntervalSlice []Interval

func (IntervalSlice) StringSlice

func (s IntervalSlice) StringSlice() (slice []string)

type IntervalWindow

type IntervalWindow struct {
	// The interval of kline
	Interval Interval

	// The windows size of the indicator (EWMA and SMA)
	Window int
}

IntervalWindow is used by the indicators

type KLine

type KLine struct {
	GID      uint64 `json:"gid" db:"gid"`
	Exchange string `json:"exchange" db:"exchange"`

	Symbol string `json:"symbol" db:"symbol"`

	StartTime time.Time `json:"startTime" db:"start_time"`
	EndTime   time.Time `json:"endTime" db:"end_time"`

	Interval Interval `json:"interval" db:"interval"`

	Open        float64 `json:"open" db:"open"`
	Close       float64 `json:"close" db:"close"`
	High        float64 `json:"high" db:"high"`
	Low         float64 `json:"low" db:"low"`
	Volume      float64 `json:"volume" db:"volume"`
	QuoteVolume float64 `json:"quoteVolume" db:"quote_volume"`

	LastTradeID    uint64 `json:"lastTradeID" db:"last_trade_id"`
	NumberOfTrades uint64 `json:"numberOfTrades" db:"num_trades"`
	Closed         bool   `json:"closed" db:"closed"`
}

KLine uses binance's kline as the standard structure

func (KLine) BounceDown

func (k KLine) BounceDown() bool

red candle with open and close near low price

func (KLine) BounceUp

func (k KLine) BounceUp() bool

green candle with open and close near high price

func (KLine) Color

func (k KLine) Color() string

func (KLine) GetBody

func (k KLine) GetBody() float64

GetBody returns the height of the candle real body

func (KLine) GetChange

func (k KLine) GetChange() float64

GetChange returns Close price - Open price.

func (KLine) GetClose

func (k KLine) GetClose() float64

func (KLine) GetEndTime

func (k KLine) GetEndTime() time.Time

func (KLine) GetHigh

func (k KLine) GetHigh() float64

func (KLine) GetInterval

func (k KLine) GetInterval() Interval

func (KLine) GetLow

func (k KLine) GetLow() float64

func (KLine) GetLowerShadowHeight

func (k KLine) GetLowerShadowHeight() float64

func (KLine) GetLowerShadowRatio

func (k KLine) GetLowerShadowRatio() float64

func (KLine) GetMaxChange

func (k KLine) GetMaxChange() float64

func (KLine) GetOpen

func (k KLine) GetOpen() float64

func (KLine) GetStartTime

func (k KLine) GetStartTime() time.Time

func (KLine) GetThickness

func (k KLine) GetThickness() float64

GetThickness returns the thickness of the kline. 1 => thick, 0.1 => thin

func (KLine) GetTrend

func (k KLine) GetTrend() Trend

func (KLine) GetUpperShadowHeight

func (k KLine) GetUpperShadowHeight() float64

func (KLine) GetUpperShadowRatio

func (k KLine) GetUpperShadowRatio() float64

func (KLine) Mid

func (k KLine) Mid() float64

func (KLine) SlackAttachment

func (k KLine) SlackAttachment() slack.Attachment

func (KLine) String

func (k KLine) String() string

type KLineCallback

type KLineCallback func(kline KLine)

type KLineOrWindow

type KLineOrWindow interface {
	GetInterval() string
	GetTrend() int
	GetChange() float64
	GetMaxChange() float64
	GetThickness() float64

	Mid() float64
	GetOpen() float64
	GetClose() float64
	GetHigh() float64
	GetLow() float64

	BounceUp() bool
	BounceDown() bool
	GetUpperShadowRatio() float64
	GetLowerShadowRatio() float64

	SlackAttachment() slack.Attachment
}

type KLineQueryOptions

type KLineQueryOptions struct {
	Limit     int
	StartTime *time.Time
	EndTime   *time.Time
}

type KLineWindow

type KLineWindow []KLine

func (*KLineWindow) Add

func (k *KLineWindow) Add(line KLine)

func (KLineWindow) AllDrop

func (k KLineWindow) AllDrop() bool

func (KLineWindow) AllRise

func (k KLineWindow) AllRise() bool

func (KLineWindow) BounceDown

func (k KLineWindow) BounceDown() bool

red candle with open and close near low price

func (KLineWindow) BounceUp

func (k KLineWindow) BounceUp() bool

green candle with open and close near high price

func (KLineWindow) Color

func (k KLineWindow) Color() string

func (KLineWindow) First

func (k KLineWindow) First() KLine

func (KLineWindow) GetBody

func (k KLineWindow) GetBody() float64

func (KLineWindow) GetChange

func (k KLineWindow) GetChange() float64

func (KLineWindow) GetClose

func (k KLineWindow) GetClose() float64

func (KLineWindow) GetHigh

func (k KLineWindow) GetHigh() float64

func (KLineWindow) GetInterval

func (k KLineWindow) GetInterval() Interval

func (KLineWindow) GetLow

func (k KLineWindow) GetLow() float64

func (KLineWindow) GetLowerShadowHeight

func (k KLineWindow) GetLowerShadowHeight() float64

func (KLineWindow) GetLowerShadowRatio

func (k KLineWindow) GetLowerShadowRatio() float64

func (KLineWindow) GetMaxChange

func (k KLineWindow) GetMaxChange() float64

func (KLineWindow) GetOpen

func (k KLineWindow) GetOpen() float64

func (KLineWindow) GetThickness

func (k KLineWindow) GetThickness() float64

func (KLineWindow) GetTrend

func (k KLineWindow) GetTrend() int

func (KLineWindow) GetUpperShadowHeight

func (k KLineWindow) GetUpperShadowHeight() float64

func (KLineWindow) GetUpperShadowRatio

func (k KLineWindow) GetUpperShadowRatio() float64

func (KLineWindow) Last

func (k KLineWindow) Last() KLine

func (KLineWindow) Len

func (k KLineWindow) Len() int

func (KLineWindow) Mid

func (k KLineWindow) Mid() float64

func (KLineWindow) ReduceClose

func (k KLineWindow) ReduceClose() float64

ReduceClose reduces the closed prices

func (KLineWindow) SlackAttachment

func (k KLineWindow) SlackAttachment() slack.Attachment

func (KLineWindow) Tail

func (k KLineWindow) Tail(size int) KLineWindow

func (KLineWindow) Take

func (k KLineWindow) Take(size int) KLineWindow

func (*KLineWindow) Truncate

func (k *KLineWindow) Truncate(size int)

Truncate removes the old klines from the window

type Market

type Market struct {
	Symbol          string
	PricePrecision  int
	VolumePrecision int
	QuoteCurrency   string
	BaseCurrency    string

	// The MIN_NOTIONAL filter defines the minimum notional value allowed for an order on a symbol. An order's notional value is the price * quantity
	MinNotional float64
	MinAmount   float64

	// The LOT_SIZE filter defines the quantity
	MinLot      float64
	MinQuantity float64
	MaxQuantity float64

	MinPrice float64
	MaxPrice float64
	TickSize float64
}

func FindMarket

func FindMarket(symbol string) (m Market, ok bool)

func (Market) CanonicalizeVolume

func (m Market) CanonicalizeVolume(val float64) float64

func (Market) FormatPrice

func (m Market) FormatPrice(val float64) string

func (Market) FormatPriceCurrency

func (m Market) FormatPriceCurrency(val float64) string

func (Market) FormatQuantity

func (m Market) FormatQuantity(val float64) string

func (Market) FormatVolume

func (m Market) FormatVolume(val float64) string

type MarketMap

type MarketMap map[string]Market

type MutexOrderBook

type MutexOrderBook struct {
	sync.Mutex

	*OrderBook
}

func NewMutexOrderBook

func NewMutexOrderBook(symbol string) *MutexOrderBook

func (*MutexOrderBook) Get

func (b *MutexOrderBook) Get() OrderBook

func (*MutexOrderBook) Load

func (b *MutexOrderBook) Load(book OrderBook)

func (*MutexOrderBook) Update

func (b *MutexOrderBook) Update(book OrderBook)

type Order

type Order struct {
	SubmitOrder

	Exchange         string      `json:"exchange" db:"exchange"`
	GID              uint64      `json:"gid" db:"gid"`
	OrderID          uint64      `json:"orderID" db:"order_id"` // order id
	Status           OrderStatus `json:"status" db:"status"`
	ExecutedQuantity float64     `json:"executedQuantity" db:"executed_quantity"`
	IsWorking        bool        `json:"isWorking" db:"is_working"`
	CreationTime     time.Time   `json:"creationTime" db:"created_at"`
	UpdateTime       time.Time   `json:"updateTime" db:"updated_at"`
}

func (Order) String

func (o Order) String() string

type OrderBook

type OrderBook struct {
	Symbol string
	Bids   PriceVolumeSlice
	Asks   PriceVolumeSlice
	// contains filtered or unexported fields
}

func (*OrderBook) Copy

func (b *OrderBook) Copy() (book OrderBook)

func (*OrderBook) EmitAsksChange

func (b *OrderBook) EmitAsksChange(pvs PriceVolumeSlice)

func (*OrderBook) EmitBidsChange

func (b *OrderBook) EmitBidsChange(pvs PriceVolumeSlice)

func (*OrderBook) EmitLoad

func (b *OrderBook) EmitLoad(book *OrderBook)

func (*OrderBook) EmitUpdate

func (b *OrderBook) EmitUpdate(book *OrderBook)

func (*OrderBook) Load

func (b *OrderBook) Load(book OrderBook)

func (*OrderBook) OnAsksChange

func (b *OrderBook) OnAsksChange(cb func(pvs PriceVolumeSlice))

func (*OrderBook) OnBidsChange

func (b *OrderBook) OnBidsChange(cb func(pvs PriceVolumeSlice))

func (*OrderBook) OnLoad

func (b *OrderBook) OnLoad(cb func(book *OrderBook))

func (*OrderBook) OnUpdate

func (b *OrderBook) OnUpdate(cb func(book *OrderBook))

func (*OrderBook) PriceVolumesBySide

func (b *OrderBook) PriceVolumesBySide(side SideType) PriceVolumeSlice

func (*OrderBook) Print

func (b *OrderBook) Print()

func (*OrderBook) Reset

func (b *OrderBook) Reset()

func (*OrderBook) Update

func (b *OrderBook) Update(book OrderBook)

type OrderMap

type OrderMap map[uint64]Order

OrderMap is used for storing orders by their order id

func (OrderMap) Add

func (m OrderMap) Add(o Order)

func (OrderMap) Canceled

func (m OrderMap) Canceled() OrderSlice

func (OrderMap) Delete

func (m OrderMap) Delete(orderID uint64)

func (OrderMap) Exists

func (m OrderMap) Exists(orderID uint64) bool

func (OrderMap) Filled

func (m OrderMap) Filled() OrderSlice

func (OrderMap) FindByStatus

func (m OrderMap) FindByStatus(status OrderStatus) (orders OrderSlice)

func (OrderMap) IDs

func (m OrderMap) IDs() (ids []uint64)

func (OrderMap) Orders

func (m OrderMap) Orders() (orders OrderSlice)

func (OrderMap) Update

func (m OrderMap) Update(o Order)

Update only updates the order when the order exists in the map

type OrderSlice

type OrderSlice []Order

func (OrderSlice) IDs

func (s OrderSlice) IDs() (ids []uint64)

type OrderStatus

type OrderStatus string
const (
	OrderStatusNew             OrderStatus = "NEW"
	OrderStatusFilled          OrderStatus = "FILLED"
	OrderStatusPartiallyFilled OrderStatus = "PARTIALLY_FILLED"
	OrderStatusCanceled        OrderStatus = "CANCELED"
	OrderStatusRejected        OrderStatus = "REJECTED"
)

type OrderType

type OrderType string

OrderType define order type

const (
	OrderTypeLimit      OrderType = "LIMIT"
	OrderTypeMarket     OrderType = "MARKET"
	OrderTypeStopLimit  OrderType = "STOP_LIMIT"
	OrderTypeStopMarket OrderType = "STOP_MARKET"
)

type PriceVolume

type PriceVolume struct {
	Price  fixedpoint.Value
	Volume fixedpoint.Value
}

func (PriceVolume) String

func (p PriceVolume) String() string

type PriceVolumeSlice

type PriceVolumeSlice []PriceVolume

func (PriceVolumeSlice) Copy

func (slice PriceVolumeSlice) Copy() PriceVolumeSlice

func (PriceVolumeSlice) Find

func (slice PriceVolumeSlice) Find(price fixedpoint.Value, descending bool) (pv PriceVolume, idx int)

FindPriceVolumePair finds the pair by the given price, this function is a read-only operation, so we use the value receiver to avoid copy value from the pointer If the price is not found, it will return the index where the price can be inserted at. true for descending (bid orders), false for ascending (ask orders)

func (PriceVolumeSlice) First

func (slice PriceVolumeSlice) First() (PriceVolume, bool)

func (PriceVolumeSlice) IndexByVolumeDepth

func (slice PriceVolumeSlice) IndexByVolumeDepth(requiredVolume fixedpoint.Value) int

func (PriceVolumeSlice) InsertAt

func (slice PriceVolumeSlice) InsertAt(idx int, pv PriceVolume) PriceVolumeSlice

func (PriceVolumeSlice) Len

func (slice PriceVolumeSlice) Len() int

func (PriceVolumeSlice) Less

func (slice PriceVolumeSlice) Less(i, j int) bool

func (PriceVolumeSlice) Remove

func (slice PriceVolumeSlice) Remove(price fixedpoint.Value, descending bool) PriceVolumeSlice

func (PriceVolumeSlice) Swap

func (slice PriceVolumeSlice) Swap(i, j int)

func (PriceVolumeSlice) Trim

func (slice PriceVolumeSlice) Trim() (pvs PriceVolumeSlice)

Trim removes the pairs that volume = 0

func (PriceVolumeSlice) Upsert

func (slice PriceVolumeSlice) Upsert(pv PriceVolume, descending bool) PriceVolumeSlice

type SideType

type SideType string

SideType define side type of order

func (SideType) Color

func (side SideType) Color() string

func (SideType) Reverse

func (side SideType) Reverse() SideType

type StandardStream

type StandardStream struct {
	Subscriptions []Subscription
	// contains filtered or unexported fields
}

func (*StandardStream) EmitBalanceSnapshot

func (stream *StandardStream) EmitBalanceSnapshot(balances BalanceMap)

func (*StandardStream) EmitBalanceUpdate

func (stream *StandardStream) EmitBalanceUpdate(balances BalanceMap)

func (*StandardStream) EmitBookSnapshot

func (stream *StandardStream) EmitBookSnapshot(book OrderBook)

func (*StandardStream) EmitBookUpdate

func (stream *StandardStream) EmitBookUpdate(book OrderBook)

func (*StandardStream) EmitConnect

func (stream *StandardStream) EmitConnect()

func (*StandardStream) EmitKLine

func (stream *StandardStream) EmitKLine(kline KLine)

func (*StandardStream) EmitKLineClosed

func (stream *StandardStream) EmitKLineClosed(kline KLine)

func (*StandardStream) EmitOrderUpdate

func (stream *StandardStream) EmitOrderUpdate(order Order)

func (*StandardStream) EmitTradeUpdate

func (stream *StandardStream) EmitTradeUpdate(trade Trade)

func (*StandardStream) OnBalanceSnapshot

func (stream *StandardStream) OnBalanceSnapshot(cb func(balances BalanceMap))

func (*StandardStream) OnBalanceUpdate

func (stream *StandardStream) OnBalanceUpdate(cb func(balances BalanceMap))

func (*StandardStream) OnBookSnapshot

func (stream *StandardStream) OnBookSnapshot(cb func(book OrderBook))

func (*StandardStream) OnBookUpdate

func (stream *StandardStream) OnBookUpdate(cb func(book OrderBook))

func (*StandardStream) OnConnect

func (stream *StandardStream) OnConnect(cb func())

func (*StandardStream) OnKLine

func (stream *StandardStream) OnKLine(cb func(kline KLine))

func (*StandardStream) OnKLineClosed

func (stream *StandardStream) OnKLineClosed(cb func(kline KLine))

func (*StandardStream) OnOrderUpdate

func (stream *StandardStream) OnOrderUpdate(cb func(order Order))

func (*StandardStream) OnTradeUpdate

func (stream *StandardStream) OnTradeUpdate(cb func(trade Trade))

func (*StandardStream) Subscribe

func (stream *StandardStream) Subscribe(channel Channel, symbol string, options SubscribeOptions)

type StandardStreamEventHub

type StandardStreamEventHub interface {
	OnConnect(cb func())

	OnTradeUpdate(cb func(trade Trade))

	OnOrderUpdate(cb func(order Order))

	OnBalanceSnapshot(cb func(balances BalanceMap))

	OnBalanceUpdate(cb func(balances BalanceMap))

	OnKLineClosed(cb func(kline KLine))

	OnKLine(cb func(kline KLine))

	OnBookUpdate(cb func(book OrderBook))

	OnBookSnapshot(cb func(book OrderBook))
}

type Stream

type Stream interface {
	StandardStreamEventHub

	Subscribe(channel Channel, symbol string, options SubscribeOptions)
	Connect(ctx context.Context) error
	Close() error
}

type StreamOrderBook

type StreamOrderBook struct {
	*MutexOrderBook

	C sigchan.Chan
}

StreamOrderBook receives streaming data from websocket connection and update the order book with mutex lock, so you can safely access it.

func NewStreamBook

func NewStreamBook(symbol string) *StreamOrderBook

func (*StreamOrderBook) BindStream

func (sb *StreamOrderBook) BindStream(stream Stream)

type SubmitOrder

type SubmitOrder struct {
	ClientOrderID string `json:"clientOrderID" db:"client_order_id"`

	Symbol string    `json:"symbol" db:"symbol"`
	Side   SideType  `json:"side" db:"side"`
	Type   OrderType `json:"orderType" db:"order_type"`

	Quantity  float64 `json:"quantity" db:"quantity"`
	Price     float64 `json:"price" db:"price"`
	StopPrice float64 `json:"stopPrice" db:"stop_price"`

	Market Market `json:"market" db:"-"`

	// TODO: we can probably remove these field
	StopPriceString string `json:"-"`
	PriceString     string `json:"-"`
	QuantityString  string `json:"-"`

	TimeInForce string `json:"timeInForce" db:"time_in_force"` // GTC, IOC, FOK
}

func (*SubmitOrder) SlackAttachment

func (o *SubmitOrder) SlackAttachment() slack.Attachment

func (*SubmitOrder) String

func (o *SubmitOrder) String() string

type SubscribeOptions

type SubscribeOptions struct {
	Interval string
	Depth    string
}

SubscribeOptions provides the standard stream options

func (SubscribeOptions) String

func (o SubscribeOptions) String() string

type Subscription

type Subscription struct {
	Symbol  string
	Channel Channel
	Options SubscribeOptions
}

type SyncOrderMap

type SyncOrderMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSyncOrderMap

func NewSyncOrderMap() *SyncOrderMap

func (*SyncOrderMap) Add

func (m *SyncOrderMap) Add(o Order)

func (*SyncOrderMap) AnyFilled

func (m *SyncOrderMap) AnyFilled() (order Order, ok bool)

AnyFilled find any order is filled and stop iterating the order map

func (*SyncOrderMap) Canceled

func (m *SyncOrderMap) Canceled() OrderSlice

func (*SyncOrderMap) Delete

func (m *SyncOrderMap) Delete(orderID uint64)

func (*SyncOrderMap) Exists

func (m *SyncOrderMap) Exists(orderID uint64) bool

func (*SyncOrderMap) Filled

func (m *SyncOrderMap) Filled() OrderSlice

func (*SyncOrderMap) FindByStatus

func (m *SyncOrderMap) FindByStatus(status OrderStatus) OrderSlice

func (*SyncOrderMap) IDs

func (m *SyncOrderMap) IDs() []uint64

func (*SyncOrderMap) Iterate

func (m *SyncOrderMap) Iterate(it func(id uint64, order Order) bool)

func (*SyncOrderMap) Len

func (m *SyncOrderMap) Len() int

func (*SyncOrderMap) Orders

func (m *SyncOrderMap) Orders() OrderSlice

func (*SyncOrderMap) Update

func (m *SyncOrderMap) Update(o Order)

type Trade

type Trade struct {
	// GID is the global ID
	GID int64 `json:"gid" db:"gid"`

	// ID is the source trade ID
	ID            int64   `json:"id" db:"id"`
	OrderID       uint64  `json:"orderID" db:"order_id"`
	Exchange      string  `json:"exchange" db:"exchange"`
	Price         float64 `json:"price" db:"price"`
	Quantity      float64 `json:"quantity" db:"quantity"`
	QuoteQuantity float64 `json:"quoteQuantity" db:"quote_quantity"`
	Symbol        string  `json:"symbol" db:"symbol"`

	Side        SideType  `json:"side" db:"side"`
	IsBuyer     bool      `json:"isBuyer" db:"is_buyer"`
	IsMaker     bool      `json:"isMaker" db:"is_maker"`
	Time        time.Time `json:"tradedAt" db:"traded_at"`
	Fee         float64   `json:"fee" db:"fee"`
	FeeCurrency string    `json:"feeCurrency" db:"fee_currency"`
}

func (Trade) SlackAttachment

func (trade Trade) SlackAttachment() slack.Attachment

type TradeQueryOptions

type TradeQueryOptions struct {
	StartTime   *time.Time
	EndTime     *time.Time
	Limit       int64
	LastTradeID int64
}

type Trend

type Trend int

type Withdraw

type Withdraw struct {
	ID         string  `json:"id"`
	Asset      string  `json:"asset"`
	Amount     float64 `json:"amount"`
	Address    string  `json:"address"`
	AddressTag string  `json:"addressTag"`
	Status     string  `json:"status"`

	TransactionID   string    `json:"txId"`
	TransactionFee  float64   `json:"transactionFee"`
	WithdrawOrderID string    `json:"withdrawOrderId"`
	ApplyTime       time.Time `json:"applyTime"`
	Network         string    `json:"network"`
}

func (Withdraw) EffectiveTime

func (w Withdraw) EffectiveTime() time.Time

Jump to

Keyboard shortcuts

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