-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding API call to get open positions #58
base: master
Are you sure you want to change the base?
Conversation
@@ -340,6 +342,31 @@ func (api *KrakenAPI) OpenOrders(args map[string]string) (*OpenOrdersResponse, e | |||
return resp.(*OpenOrdersResponse), nil | |||
} | |||
|
|||
// OpenPositions returns all open orders | |||
func (api *KrakenAPI) OpenPositions(args map[string]string) (*OpenPositionsResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to make the arguments more concrete ?
For example docals could be a bool. This could make the usage easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally probably use a custom struct to define what can go into this, admittedly I was just following the format of how the rest of the SDK is currently designed.
A custom struct would go a long way toward allowing custom options and future expandability.
great addition !!! |
VolumeClosed float64 `json:"vol_closed,string"` | ||
Margin float64 `json:"margin,string"` | ||
Value float64 `json:"value,string"` | ||
Net float64 `json:"net,string"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from some tests i did, it seems this breaks when the net value is returned from kraken as a string with a +
sign i.e. +24.768
. Would it make sense to try a custom unmarhsaling ? Something maybe similar to how OrderBookItem is handled ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize they do this, I can check later for this or if you have a patch we can merge it in!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure its the best way ... but thats what i used to get around it.
But then when parsing the object you need to do something like this, when using the Net property
net := float64(Position.Net)
OrderFlags string `json:"oflags"` | ||
Status string `json:"posstatus"` | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type Float64 float64 | |
func (ff *Float64) UnmarshalJSON(data []byte) error { | |
f, err := strconv.ParseFloat(string(data), 64) | |
if err != nil { | |
return err | |
} | |
*ff = Float64(f) | |
return nil | |
} |
VolumeClosed float64 `json:"vol_closed,string"` | ||
Margin float64 `json:"margin,string"` | ||
Value float64 `json:"value,string"` | ||
Net float64 `json:"net,string"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Net float64 `json:"net,string"` | |
Net Float64 `json:"net,string"` |
Using these patches you can now request the open positions from the Kraken API.
Minor addition - Adding a minimum AAVE constant as well.