instrument usecases & repository methods
This commit is contained in:
parent
39b89fc404
commit
16d38bb3cf
7 changed files with 100 additions and 13 deletions
|
|
@ -36,17 +36,17 @@ func New(log *slog.Logger, cfg *config.Bybit) provider.Provider {
|
|||
}
|
||||
}
|
||||
|
||||
func (b *Bybit) symbol(pair *entities.Pair) string {
|
||||
func (b *Bybit) symbol(pair *entities.Instrument) string {
|
||||
return fmt.Sprintf("%s%s", pair.BaseCurrency, pair.QuoteCurrency)
|
||||
}
|
||||
|
||||
// Price returns the current price of the pair (base currency / quote currency).
|
||||
// e.g. BTC/USDT.
|
||||
func (b *Bybit) Price(ctx context.Context, pair entities.Pair) (*entities.Price, error) {
|
||||
func (b *Bybit) Price(ctx context.Context, instrument entities.Instrument) (*entities.Price, error) {
|
||||
// build request
|
||||
req := marketOrderbookReq{
|
||||
Category: categorySpot,
|
||||
Symbol: b.symbol(&pair),
|
||||
Symbol: b.symbol(&instrument),
|
||||
}
|
||||
var resp marketOrderbookResp
|
||||
// make request
|
||||
|
|
@ -67,9 +67,9 @@ func (b *Bybit) Price(ctx context.Context, pair entities.Pair) (*entities.Price,
|
|||
spread := askPrice.Sub(bidPrice)
|
||||
|
||||
return &entities.Price{
|
||||
Ask: askPrice,
|
||||
Bid: bidPrice,
|
||||
Spread: spread,
|
||||
Pair: pair,
|
||||
Ask: askPrice,
|
||||
Bid: bidPrice,
|
||||
Spread: spread,
|
||||
Instrument: instrument,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@ import (
|
|||
type Provider interface {
|
||||
// Price returns the current price of the pair (base currency / quote currency).
|
||||
// e.g. BTC/USDT.
|
||||
Price(ctx context.Context, pair entities.Pair) (*entities.Price, error)
|
||||
Price(ctx context.Context, instrument entities.Instrument) (*entities.Price, error)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue