blockchain/internal/domain/repository/exchange_adapter.go

26 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package repository
import (
"blockchain/internal/domain/blockchain"
"time"
)
// ====== Adapter 介面(每家交易所各實作一份) ======
type ExchangeAdapter interface {
Name() string // e.g. "binance"
URL() string // 該交易所的 ws 連線位址
NormalizeSymbol(internal string) string // 內部 -> 交易所格式ex: BTCUSDT -> BTC-USD / BTC-USDT
DenormalizeSymbol(external string) string // 交易所 -> 內部格式
BuildSubscribe(symbols []string, interval blockchain.Interval) ([][]byte, error) // BuildSubscribe 訂閱K線可一次多個
BuildUnsubscribe(symbols []string, interval blockchain.Interval) ([][]byte, error) // BuildUnsubscribe 取消訂閱K線可一次多個
ParseKLines(msg []byte) ([]blockchain.Kline, error) // ParseKLines 解析 WS 訊息:不是 K 線就回 (nil, nil)
ClientPingInterval() time.Duration // ClientPingInterval 心跳:是否需要主動 ping有些交易所 server 會送 ping) ,0 表示不用主動 ping
ReadDeadline() time.Duration // 建議 read deadline
}
type StreamHandler interface {
OnKline(k blockchain.Kline)
OnError(err error)
}