-
Notifications
You must be signed in to change notification settings - Fork 29
/
transactions.go
105 lines (97 loc) · 2.9 KB
/
transactions.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package goanda
import (
"net/url"
"time"
)
// Supporting OANDA docs - http://developer.oanda.com/rest-live-v20/transaction-ep/
type TransactionPages struct {
Count int `json:"count"`
From time.Time `json:"from"`
LastTransactionID string `json:"lastTransactionID"`
PageSize int `json:"pageSize"`
Pages []string `json:"pages"`
To time.Time `json:"to"`
}
type Transaction struct {
LastTransactionID string `json:"lastTransactionID"`
Transaction struct {
AccountBalance string `json:"accountBalance"`
AccountID string `json:"accountID"`
BatchID string `json:"batchID"`
Financing string `json:"financing"`
ID string `json:"id"`
Instrument string `json:"instrument"`
OrderID string `json:"orderID"`
Pl string `json:"pl"`
Price string `json:"price"`
Reason string `json:"reason"`
Time time.Time `json:"time"`
TradeOpened struct {
TradeID string `json:"tradeID"`
Units string `json:"units"`
} `json:"tradeOpened"`
Type string `json:"type"`
Units string `json:"units"`
UserID int `json:"userID"`
} `json:"transaction"`
}
type Transactions struct {
LastTransactionID string `json:"lastTransactionID"`
Transactions []struct {
AccountBalance string `json:"accountBalance"`
AccountID string `json:"accountID"`
BatchID string `json:"batchID"`
Financing string `json:"financing"`
ID string `json:"id"`
Instrument string `json:"instrument"`
OrderID string `json:"orderID"`
Pl string `json:"pl"`
Price string `json:"price"`
Reason string `json:"reason"`
Time time.Time `json:"time"`
TradeOpened struct {
TradeID string `json:"tradeID"`
Units string `json:"units"`
} `json:"tradeOpened"`
Type string `json:"type"`
Units string `json:"units"`
UserID int `json:"userID"`
} `json:"transactions"`
}
// https://golang.org/pkg/time/#Time.AddDate
// https://play.golang.org/p/Dw7D4JJ7EC
func (c *Connection) GetTransactions(from time.Time, to time.Time) (TransactionPages, error) {
tp := TransactionPages{}
err := c.getAndUnmarshal(
"/accounts/"+
c.accountID+
"/transactions?to="+
url.QueryEscape(to.Format(time.RFC3339))+
"&from="+
url.QueryEscape(from.Format(time.RFC3339)),
&tp,
)
return tp, err
}
func (c *Connection) GetTransaction(ticket string) (Transaction, error) {
tr := Transaction{}
err := c.getAndUnmarshal(
"/accounts/"+
c.accountID+
"/transactions/"+
ticket,
&tr,
)
return tr, err
}
func (c *Connection) GetTransactionsSinceId(id string) (Transactions, error) {
tr := Transactions{}
err := c.getAndUnmarshal(
"/accounts/"+
c.accountID+
"/transactions/sinceid?id="+
id,
&tr,
)
return tr, err
}