mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 23:16:54 +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:
@@ -324,20 +324,17 @@ func (h *HUOBI) GetCurrenciesIncludingChains(ctx context.Context, curr currency.
|
||||
return resp.Data, nil
|
||||
}
|
||||
|
||||
// GetTimestamp returns the Huobi server time
|
||||
func (h *HUOBI) GetTimestamp(ctx context.Context) (int64, error) {
|
||||
type response struct {
|
||||
// GetCurrentServerTime returns the Huobi server time
|
||||
func (h *HUOBI) GetCurrentServerTime(ctx context.Context) (time.Time, error) {
|
||||
var result struct {
|
||||
Response
|
||||
Timestamp int64 `json:"data"`
|
||||
}
|
||||
|
||||
var result response
|
||||
|
||||
err := h.SendHTTPRequest(ctx, exchange.RestSpot, "/v"+huobiAPIVersion+"/"+huobiTimestamp, &result)
|
||||
if result.ErrorMessage != "" {
|
||||
return 0, errors.New(result.ErrorMessage)
|
||||
return time.Time{}, errors.New(result.ErrorMessage)
|
||||
}
|
||||
return result.Timestamp, err
|
||||
return time.UnixMilli(result.Timestamp), err
|
||||
}
|
||||
|
||||
// GetAccounts returns the Huobi user accounts
|
||||
|
||||
@@ -1754,10 +1754,26 @@ func TestGetTicker(t *testing.T) {
|
||||
|
||||
func TestGetTimestamp(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := h.GetTimestamp(context.Background())
|
||||
st, err := h.GetCurrentServerTime(context.Background())
|
||||
if err != nil {
|
||||
t.Errorf("Huobi TestGetTimestamp: %s", err)
|
||||
}
|
||||
|
||||
if st.IsZero() {
|
||||
t.Fatal("expected a time")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrapperGetServerTime(t *testing.T) {
|
||||
t.Parallel()
|
||||
st, err := h.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")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAccounts(t *testing.T) {
|
||||
|
||||
@@ -1844,3 +1844,8 @@ func (h *HUOBI) GetAvailableTransferChains(ctx context.Context, cryptocurrency c
|
||||
}
|
||||
return availableChains, nil
|
||||
}
|
||||
|
||||
// GetServerTime returns the current exchange server time.
|
||||
func (h *HUOBI) GetServerTime(ctx context.Context, _ asset.Item) (time.Time, error) {
|
||||
return h.GetCurrentServerTime(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user