user instruments

This commit is contained in:
yash 2026-04-28 11:42:07 +03:00
parent dd03cae0f3
commit abb2411af7
9 changed files with 494 additions and 48 deletions

View file

@ -3,6 +3,7 @@ package bybit
import (
"context"
"encoding/json"
"fmt"
"log/slog"
"net/http"
@ -100,6 +101,28 @@ func intervalBybit(interval provider.KlineInterval) (string, error) {
return i, nil
}
// InstrumentExists reports whether base/quote is a valid spot pair on Bybit.
// A non-zero retCode (e.g. unknown symbol) is treated as "not found" — only
// actual transport / parse failures propagate as errors.
func (b *Bybit) InstrumentExists(ctx context.Context, base, quote string) (bool, error) {
req := marketOrderbookReq{
Category: categorySpot,
Symbol: fmt.Sprintf("%s%s", base, quote),
}
body, err := b.getRequest(ctx, "/v5/market/orderbook", req)
if err != nil {
return false, fmt.Errorf("failed to check instrument existence: %w", err)
}
var resp response
if err := json.Unmarshal(body, &resp); err != nil {
return false, fmt.Errorf("failed to parse response: %w", err)
}
return resp.RetCode == 0, nil
}
// Candles returns OHLC candles for the given interval in the [from, to) range.
// It paginates automatically when the range exceeds klineLimit candles per request.
func (b *Bybit) Candles(ctx context.Context, instrument entities.Instrument, from, to time.Time, interval provider.KlineInterval) ([]entities.Candle, error) {

View file

@ -17,6 +17,10 @@ type Provider interface {
// The implementation handles pagination automatically when the range exceeds one
// request's capacity.
Candles(ctx context.Context, instrument entities.Instrument, from, to time.Time, interval KlineInterval) ([]entities.Candle, error)
// InstrumentExists reports whether the trading pair base/quote is listed on this provider.
// Returns (false, nil) when the symbol is simply not found (as opposed to a network error).
InstrumentExists(ctx context.Context, base, quote string) (bool, error)
}
type KlineInterval string