-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path01_fetch_ticker_with_adapter.go
More file actions
33 lines (27 loc) · 1.16 KB
/
Copy path01_fetch_ticker_with_adapter.go
File metadata and controls
33 lines (27 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package examples
import (
"context"
"github.com/QuantProcessing/exchanges/adapter/binance"
"github.com/QuantProcessing/exchanges/model"
"github.com/QuantProcessing/exchanges/venue"
)
// FetchTickerWithDataClient shows the smallest normalized market-data path:
// connect a venue.DataClient, request one ticker, and disconnect it.
func FetchTickerWithDataClient(ctx context.Context, client venue.DataClient, instrumentID model.InstrumentID) (model.Ticker, error) {
if err := client.Connect(ctx); err != nil {
return model.Ticker{}, err
}
defer client.Disconnect(context.Background())
return client.FetchTicker(ctx, instrumentID)
}
// FetchBTCUSDTFromBinanceSpot is the same workflow using the concrete Binance
// spot adapter. It calls Binance public endpoints, so tests compile this helper
// but do not execute it by default.
func FetchBTCUSDTFromBinanceSpot(ctx context.Context) (model.Ticker, error) {
adapter, err := binance.NewSpotAdapter(ctx, binance.Options{})
if err != nil {
return model.Ticker{}, err
}
defer adapter.Close(context.Background())
return FetchTickerWithDataClient(ctx, adapter.Data(), model.MustInstrumentID("BTC-USDT-SPOT.BINANCE"))
}