-
Notifications
You must be signed in to change notification settings - Fork 14
/
transaction.go
59 lines (52 loc) · 1.8 KB
/
transaction.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
package igmarkets
import (
"bytes"
"context"
"fmt"
"net/http"
"time"
)
// HistoryTransactionResponse - Response for transactions endpoint
type HistoryTransactionResponse struct {
Transactions []Transaction `json:"transactions"`
MetaData struct {
PageData struct {
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
TotalPages int `json:"totalPages"`
} `json:"pageData"`
Size int `json:"size"`
} `json:"metaData"`
}
// Transaction - Part of HistoryTransactionResponse
type Transaction struct {
CashTransaction bool `json:"cashTransaction"`
CloseLevel string `json:"closeLevel"`
Currency string `json:"currency"`
Date string `json:"date"`
DateUTC string `json:"dateUtc"`
InstrumentName string `json:"instrumentName"`
OpenDateUtc string `json:"openDateUtc"`
OpenLevel string `json:"openLevel"`
Period string `json:"period"`
ProfitAndLoss string `json:"profitAndLoss"`
Reference string `json:"reference"`
Size string `json:"size"`
TransactionType string `json:"transactionType"`
}
// GetTransactions - Return all transaction
func (ig *IGMarkets) GetTransactions(ctx context.Context, transactionType string, from time.Time) (*HistoryTransactionResponse, error) {
bodyReq := new(bytes.Buffer)
fromStr := from.Format("2006-01-02T15:04:05")
req, err := http.NewRequest("GET", fmt.Sprintf("%s/gateway/deal/history/transactions?from=%s&type=%s&pageSize=0",
ig.APIURL, fromStr, transactionType), bodyReq)
if err != nil {
return nil, fmt.Errorf("igmarkets: unable to get transactions: %v", err)
}
igResponseInterface, err := ig.doRequest(ctx, req, 2, HistoryTransactionResponse{})
if err != nil {
return nil, err
}
igResponse, _ := igResponseInterface.(*HistoryTransactionResponse)
return igResponse, err
}