forked from AwolDes/goanda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pricing.go
60 lines (54 loc) · 1.68 KB
/
pricing.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
package goanda
import (
"net/url"
"strings"
"time"
)
// Supporting OANDA docs - http://developer.oanda.com/rest-live-v20/pricing-ep/
type Pricings struct {
Prices []struct {
Asks []struct {
Liquidity int `json:"liquidity"`
Price string `json:"price"`
} `json:"asks"`
Bids []struct {
Liquidity int `json:"liquidity"`
Price string `json:"price"`
} `json:"bids"`
CloseoutAsk string `json:"closeoutAsk"`
CloseoutBid string `json:"closeoutBid"`
Instrument string `json:"instrument"`
QuoteHomeConversionFactors struct {
NegativeUnits string `json:"negativeUnits"`
PositiveUnits string `json:"positiveUnits"`
} `json:"quoteHomeConversionFactors"`
Status string `json:"status"`
Time time.Time `json:"time"`
UnitsAvailable struct {
Default struct {
Long string `json:"long"`
Short string `json:"short"`
} `json:"default"`
OpenOnly struct {
Long string `json:"long"`
Short string `json:"short"`
} `json:"openOnly"`
ReduceFirst struct {
Long string `json:"long"`
Short string `json:"short"`
} `json:"reduceFirst"`
ReduceOnly struct {
Long string `json:"long"`
Short string `json:"short"`
} `json:"reduceOnly"`
} `json:"unitsAvailable"`
} `json:"prices"`
}
func (c *OandaConnection) GetPricingForInstruments(instruments []string) (Pricings, error, error) {
instrumentString := strings.Join(instruments, ",")
endpoint := "v3/accounts/" + c.AccountID + "/pricing?instruments=" + url.QueryEscape(instrumentString)
response, err1, err2 := c.Request(endpoint)
data := Pricings{}
_ = unmarshalJson(response, &data)
return data, err1, err2
}