/
recent_trades.go
41 lines (33 loc) · 955 Bytes
/
recent_trades.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package itbit
import (
"fmt"
"net/http"
"time"
)
type Trades struct {
Count int `json:"count"`
RecentTrades []struct {
Timestamp time.Time `json:"timestamp"`
MatchNumber string `json:"matchNumber"`
Price float64 `json:"price,string"`
Amount float64 `json:"amount,string"`
} `json:"recentTrades"`
}
// MarketService returns recent trades for the specified market
//
// since is an optional parameter
func (c *Client) GetRecentTrades(tickerSymbol, since string) (Trades, error) {
var trades Trades
if tickerSymbol == "" {
return trades, fmt.Errorf("tickerSymbol is a required field, got: %s", tickerSymbol)
}
url := fmt.Sprintf("%s/markets/%s/trades", Endpoint, tickerSymbol)
if since != "" {
url = fmt.Sprintf("%s?since=%s", url, since)
}
err := c.doRequest(http.MethodGet, url, nil, &trades)
if err != nil {
return trades, fmt.Errorf("could not do request: %v", err)
}
return trades, nil
}