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:
Ryan O'Hara-Reid
2022-05-06 11:38:59 +10:00
committed by GitHub
parent c6ad429827
commit d735effc8e
24 changed files with 230 additions and 28 deletions

View File

@@ -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

View File

@@ -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) {

View File

@@ -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)
}