There isn't any function for closing a position. I am trying to improvise a function which gets the position size and direction of the ticker requested to put a marketorder of the oposite direction (if you where long then a short order) with the same size. But in your portfolio function there is no way to get the direction of the position, so I get the long or short bias by the sign of price minus break even price. If the sign is negative it is long, if positive it is short.
If you could do a specific function for this it would be really helpfull.
Hello.
There isn't any function for closing a position. I am trying to improvise a function which gets the position size and direction of the ticker requested to put a marketorder of the oposite direction (if you where long then a short order) with the same size. But in your portfolio function there is no way to get the direction of the position, so I get the long or short bias by the sign of price minus break even price. If the sign is negative it is long, if positive it is short. If you could do a specific function for this it would be really helpfull.
Thank you for all the work.