mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 07:26:47 +00:00
exchanges/kraken,bittrex,gemini: Resolve Kraken panic, lint corrections, Bittrex batch tickers, set Gemini order limits and update tradable pairs (#1372)
* fix kraken, batch bittrex, fix lint * surprise gemini! * thought this happened automatically * fix before shazbert sees * fixes annoying atoi bug * rm futures from gemini * lint * bittrex UpdatedAt, gemini Limits, stats relook * STATS used HARDEN!(improve stats package) * Whoopsies in your Daisies * rm RWMutex, json stringeroo * fixes additional index issues 😆 😭
This commit is contained in:
@@ -36,6 +36,7 @@ const (
|
||||
getMarkets = "/markets"
|
||||
getMarketSummaries = "/markets/summaries"
|
||||
getTicker = "/markets/%s/ticker"
|
||||
getTickers = "/markets/tickers"
|
||||
getMarketSummary = "/markets/%s/summary"
|
||||
getMarketTrades = "/markets/%s/trades"
|
||||
getOrderbook = "/markets/%s/orderbook?depth=%s"
|
||||
@@ -87,8 +88,14 @@ func (b *Bittrex) GetTicker(ctx context.Context, marketName string) (TickerData,
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestSpot, fmt.Sprintf(getTicker, marketName), &resp, nil)
|
||||
}
|
||||
|
||||
// GetTickers returns bittrex tickers
|
||||
func (b *Bittrex) GetTickers(ctx context.Context) ([]TickerData, error) {
|
||||
var resp []TickerData
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestSpot, getTickers, &resp, nil)
|
||||
}
|
||||
|
||||
// GetMarketSummaries is used to get the last 24 hour summary of all active
|
||||
// exchanges
|
||||
// currencies
|
||||
func (b *Bittrex) GetMarketSummaries(ctx context.Context) ([]MarketSummaryData, error) {
|
||||
var resp []MarketSummaryData
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestSpot, getMarketSummaries, &resp, nil)
|
||||
|
||||
@@ -725,3 +725,23 @@ func TestGetHistoricCandlesExtended(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetTickers(context.Background())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := b.UpdateTickers(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
err = b.UpdateTickers(context.Background(), asset.Futures)
|
||||
if !errors.Is(err, asset.ErrNotSupported) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,10 +72,11 @@ type MarketData struct {
|
||||
|
||||
// TickerData stores ticker data
|
||||
type TickerData struct {
|
||||
Symbol string `json:"symbol"`
|
||||
LastTradeRate float64 `json:"lastTradeRate,string"`
|
||||
BidRate float64 `json:"bidRate,string"`
|
||||
AskRate float64 `json:"askRate,string"`
|
||||
Symbol string `json:"symbol"`
|
||||
LastTradeRate float64 `json:"lastTradeRate,string"`
|
||||
BidRate float64 `json:"bidRate,string"`
|
||||
AskRate float64 `json:"askRate,string"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// TradeData stores trades data
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -87,6 +88,7 @@ func (b *Bittrex) SetDefaults() {
|
||||
Websocket: true,
|
||||
RESTCapabilities: protocol.Features{
|
||||
TickerFetching: true,
|
||||
TickerBatching: true,
|
||||
KlineFetching: true,
|
||||
TradeFetching: true,
|
||||
OrderbookFetching: true,
|
||||
@@ -297,8 +299,36 @@ func (b *Bittrex) UpdateTradablePairs(ctx context.Context, forceUpdate bool) err
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
func (b *Bittrex) UpdateTickers(_ context.Context, _ asset.Item) error {
|
||||
return common.ErrFunctionNotSupported
|
||||
func (b *Bittrex) UpdateTickers(ctx context.Context, a asset.Item) error {
|
||||
if a != asset.Spot {
|
||||
return fmt.Errorf("%w %v", asset.ErrNotSupported, a)
|
||||
}
|
||||
tickers, err := b.GetTickers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
summaries, err := b.GetMarketSummaries(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for x := range tickers {
|
||||
for y := range summaries {
|
||||
if !strings.EqualFold(summaries[y].Symbol, tickers[x].Symbol) {
|
||||
continue
|
||||
}
|
||||
var pair currency.Pair
|
||||
pair, err = currency.NewPairFromString(tickers[x].Symbol)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tickerPrice := b.constructTicker(tickers[x], &summaries[y], pair, a)
|
||||
err = ticker.ProcessTicker(tickerPrice)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
|
||||
Reference in New Issue
Block a user