Skip to content

Commit

Permalink
Merge pull request #13 from itsksaurabh/improve/timefields
Browse files Browse the repository at this point in the history
Improve/timefields
  • Loading branch information
itsksaurabh authored Mar 14, 2020
2 parents 249dc5f + b295294 commit 6660fd6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
30 changes: 24 additions & 6 deletions marketStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"net/http"
"time"

"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
Expand Down Expand Up @@ -66,12 +67,29 @@ type Market struct {
// Top ask order price
Sell string `json:"sell,omitempty"`
// Top bid order price
Buy string `json:"buy,omitempty"`
At int `json:"at,omitempty"`
MaxBuyAmount int `json:"maxBuyAmount,omitempty"`
MinBuyVolume int `json:"minBuyVolume,omitempty"`
MaxBuyVolume int `json:"maxBuyVolume,omitempty"`
FeePercentOnProfit float64 `json:"feePercentOnProfit,omitempty"`
Buy string `json:"buy,omitempty"`
At time.Time `json:"at,omitempty"`
MaxBuyAmount int `json:"maxBuyAmount,omitempty"`
MinBuyVolume int `json:"minBuyVolume,omitempty"`
MaxBuyVolume int `json:"maxBuyVolume,omitempty"`
FeePercentOnProfit float64 `json:"feePercentOnProfit,omitempty"`
}

// UnmarshalJSON implements the json.Unmarshaler interface.
// coverts Timestamp from `int` to unix timestamp
func (m *Market) UnmarshalJSON(data []byte) error {
type Alias Market
aux := &struct {
At int64 `json:"at,omitempty"`
*Alias
}{
Alias: (*Alias)(m),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
m.At = time.Unix(aux.At, 0)
return nil
}

// Asset holds asset related data
Expand Down
21 changes: 20 additions & 1 deletion marketTicker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package wazirx

import (
"context"
"encoding/json"
"net/http"
"time"

"github.com/pkg/errors"
)
Expand All @@ -29,11 +31,28 @@ type TickerData struct {
// Top bid order price
Buy string `json:"buy"`
// Timestamp when ticker information is fetched
At int `json:"at"`
At time.Time `json:"at"`
// Display text of market
Name string `json:"name"`
}

// UnmarshalJSON implements the json.Unmarshaler interface.
// coverts Timestamp from `int` to unix timestamp
func (t *TickerData) UnmarshalJSON(data []byte) error {
type Alias TickerData
aux := &struct {
At int64 `json:"at"`
*Alias
}{
Alias: (*Alias)(t),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
t.At = time.Unix(aux.At, 0)
return nil
}

// MarketTicker returs the latest market heart-beat for all the markets for the last 24hrs.
func (c Client) MarketTicker(ctx context.Context) (data map[string]TickerData, err error) {
endpoint := "/api/v2/tickers"
Expand Down

0 comments on commit 6660fd6

Please sign in to comment.