-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathpositions.go
59 lines (54 loc) · 1.55 KB
/
positions.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 goanda
// Supporting OANDA docs - http://developer.oanda.com/rest-live-v20/position-ep/
type OpenPositions struct {
LastTransactionID string `json:"lastTransactionID"`
Positions []struct {
Instrument string `json:"instrument"`
Long struct {
AveragePrice string `json:"averagePrice"`
Pl string `json:"pl"`
ResettablePL string `json:"resettablePL"`
TradeIDs []string `json:"tradeIDs"`
Units string `json:"units"`
UnrealizedPL string `json:"unrealizedPL"`
} `json:"long"`
Pl string `json:"pl"`
ResettablePL string `json:"resettablePL"`
Short struct {
AveragePrice string `json:"averagePrice"`
Pl string `json:"pl"`
ResettablePL string `json:"resettablePL"`
TradeIDs []string `json:"tradeIDs"`
Units string `json:"units"`
UnrealizedPL string `json:"unrealizedPL"`
} `json:"short"`
UnrealizedPL string `json:"unrealizedPL"`
} `json:"positions"`
}
type ClosePositionPayload struct {
LongUnits string `json:"longUnits"`
ShortUnits string `json:"shortUnits"`
}
func (c *Connection) GetOpenPositions() (OpenPositions, error) {
op := OpenPositions{}
err := c.getAndUnmarshal(
"/accounts/"+
c.accountID+
"/openPositions",
&op,
)
return op, err
}
func (c *Connection) ClosePosition(instrument string, body ClosePositionPayload) (ModifiedTrade, error) {
mt := ModifiedTrade{}
err := c.putAndUnmarshal(
"/accounts/"+
c.accountID+
"/positions/"+
instrument+
"/close",
body,
&mt,
)
return mt, err
}