Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Howard3
Copy link
Contributor

@Howard3 Howard3 commented Jan 15, 2021

Using these patches you can now request the open positions from the Kraken API.

Minor addition - Adding a minimum AAVE constant as well.

@@ -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) {
Copy link

@drakos74 drakos74 Jan 24, 2021

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.

Copy link
Contributor Author

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.

@drakos74
Copy link

great addition !!!

VolumeClosed float64 `json:"vol_closed,string"`
Margin float64 `json:"margin,string"`
Value float64 `json:"value,string"`
Net float64 `json:"net,string"`

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 ?

Copy link
Contributor Author

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!

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"`
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"`
Copy link

@drakos74 drakos74 Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Net float64 `json:"net,string"`
Net Float64 `json:"net,string"`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants