user instruments
This commit is contained in:
parent
dd03cae0f3
commit
abb2411af7
9 changed files with 494 additions and 48 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue