MCPcopy
hub / github.com/thrasher-corp/gocryptotrader / GetTicker

Method GetTicker

engine/rpcserver.go:432–468  ·  view source on GitHub ↗

GetTicker returns the ticker for a specified exchange, currency pair and asset type

(_ context.Context, r *gctrpc.GetTickerRequest)

Source from the content-addressed store, hash-verified

430// GetTicker returns the ticker for a specified exchange, currency pair and
431// asset type
432func (s *RPCServer) GetTicker(_ context.Context, r *gctrpc.GetTickerRequest) (*gctrpc.TickerResponse, error) {
433 a, err := asset.New(r.AssetType)
434 if err != nil {
435 return nil, err
436 }
437
438 e, err := s.GetExchangeByName(r.Exchange)
439 if err != nil {
440 return nil, err
441 }
442
443 pair := currency.NewPairWithDelimiter(r.Pair.Base, r.Pair.Quote, r.Pair.Delimiter)
444
445 err = checkParams(r.Exchange, e, a, pair)
446 if err != nil {
447 return nil, err
448 }
449
450 t, err := e.GetCachedTicker(pair, a)
451 if err != nil {
452 return nil, err
453 }
454
455 resp := &gctrpc.TickerResponse{
456 Pair: r.Pair,
457 LastUpdated: s.unixTimestamp(t.LastUpdated),
458 Last: t.Last,
459 High: t.High,
460 Low: t.Low,
461 Bid: t.Bid,
462 Ask: t.Ask,
463 Volume: t.Volume,
464 PriceAth: t.PriceATH,
465 }
466
467 return resp, nil
468}
469
470// GetTickers returns a list of tickers for all enabled exchanges and all
471// enabled currency pairs

Calls 6

unixTimestampMethod · 0.95
NewFunction · 0.92
NewPairWithDelimiterFunction · 0.92
checkParamsFunction · 0.85
GetExchangeByNameMethod · 0.65
GetCachedTickerMethod · 0.65

Tested by 1