dydxprotocol / dydx-v3-python

Python client for dYdX (API v3)
Apache License 2.0
304 stars 174 forks source link

Can't Close Positions when Margin Utilization Gets Too High #230

Open bperritt opened 1 week ago

bperritt commented 1 week ago

Because there's not provided way to simply close a position, it's necessary to open a counter-position of the same quantity in the opposite direction in order to close a position using the API. However, if my available margin is too low, closing will fail, with the error 'order would put account below collateralization'. This seems to be a symptom of the fact that the system just blindly checks whether the client has the collateral to open a given position, without considering the fact that that position may be reducing the size of a presently open one. There is no elegant way around this and it presents a huge flaw with the API, because it becomes impossible to get out of losing positions. Please fix this ASAP.