forked from jyap808/go-poloniex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trade.go
58 lines (52 loc) · 1.38 KB
/
trade.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package poloniex
import (
"encoding/json"
"time"
)
const (
TRADE_FILL_OR_KILL = "fillOrKill"
TRADE_IMMEDIATE_OR_CANCEL = "immediateOrCancel"
TRADE_POST_ONLY = "postOnly"
)
type Trade struct {
GlobalTradeID uint64 `json:"globalTradeID"`
TradeID uint64 `json:"tradeID,string"`
Date time.Time `json:"date,string"`
Type string `json:"type"`
Category string `json:"category"`
Rate float64 `json:"rate,string"`
Amount float64 `json:"amount,string"`
Total float64 `json:"total,string"`
Fee float64 `json:"fee,string"`
}
func (t *Trade) UnmarshalJSON(data []byte) error {
var err error
type Alias Trade
aux := &struct {
Date string `json:"date"`
*Alias
}{
Alias: (*Alias)(t),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
t.Date, err = time.Parse("2006-01-02 15:04:05", aux.Date)
if err != nil {
return err
}
return nil
}
type ResultingTrade struct {
Amount float64 `json:"amount,string"`
Date string `json:"date"`
Rate float64 `json:"rate,string"`
Total float64 `json:"total,string"`
TradeID string `json:"tradeID"`
Type string `json:"type"`
}
type TradeOrder struct {
OrderNumber string `json:"orderNumber"`
ResultingTrades []ResultingTrade `json:"resultingTrades"`
ErrorMessage string `json:"error"`
}