mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
exchange/wrapper: add GetServerTime() for exchange analytics (#938)
* exchange/wrapper: add GetServerTime() for exchange analytics * binance: fix linter issue * glorious: nits * glorious: nits rides again * thrasher: nits implement huobi * thrasher: nits add to exchange_wrapper_issues cmd
This commit is contained in:
@@ -70,6 +70,41 @@ func TestUServerTime(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrapperGetServerTime(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetServerTime(context.Background(), asset.Empty)
|
||||
if !errors.Is(err, asset.ErrNotSupported) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, asset.ErrNotSupported)
|
||||
}
|
||||
|
||||
st, err := b.GetServerTime(context.Background(), asset.Spot)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
|
||||
if st.IsZero() {
|
||||
t.Fatal("expected a time")
|
||||
}
|
||||
|
||||
st, err = b.GetServerTime(context.Background(), asset.USDTMarginedFutures)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
|
||||
if st.IsZero() {
|
||||
t.Fatal("expected a time")
|
||||
}
|
||||
|
||||
st, err = b.GetServerTime(context.Background(), asset.CoinMarginedFutures)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
|
||||
if st.IsZero() {
|
||||
t.Fatal("expected a time")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSAPITime(t *testing.T) {
|
||||
t.Parallel()
|
||||
tm, err := time.Parse(binanceSAPITimeLayout, "2021-05-27 03:56:46")
|
||||
|
||||
@@ -74,7 +74,7 @@ func (b *Binance) UServerTime(ctx context.Context) (time.Time, error) {
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
return time.Unix(0, data.ServerTime*1000000), nil
|
||||
return time.UnixMilli(data.ServerTime), nil
|
||||
}
|
||||
|
||||
// UExchangeInfo stores usdt margined futures data
|
||||
|
||||
@@ -1882,3 +1882,24 @@ func (b *Binance) formatUSDTMarginedFuturesPair(p currency.Pair, pairFmt currenc
|
||||
}
|
||||
return p.Format(currency.UnderscoreDelimiter, pairFmt.Uppercase)
|
||||
}
|
||||
|
||||
// GetServerTime returns the current exchange server time.
|
||||
func (b *Binance) GetServerTime(ctx context.Context, ai asset.Item) (time.Time, error) {
|
||||
switch ai {
|
||||
case asset.USDTMarginedFutures:
|
||||
return b.UServerTime(ctx)
|
||||
case asset.Spot:
|
||||
info, err := b.GetExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
return info.Servertime, nil
|
||||
case asset.CoinMarginedFutures:
|
||||
info, err := b.FuturesExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
return time.UnixMilli(info.ServerTime), nil
|
||||
}
|
||||
return time.Time{}, fmt.Errorf("%s %w", ai, asset.ErrNotSupported)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user