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

Loading currently open positions and overriding method #30

Closed
kausality opened this issue Jan 19, 2020 · 4 comments
Closed

Loading currently open positions and overriding method #30

kausality opened this issue Jan 19, 2020 · 4 comments

Comments

@kausality
Copy link

Is there a way to load currently open positions preferabbly as a separate object?

The method which loads the positions can be made overridable so if we have multiple strategies running on one account, and say 2 strategies have positions on asset X with quantity 10 and 20 each then we can determine what is the position for the current strategy in asset X by subtracting the total open position on the asset X in our account by a value we stored locally.

The value could have been saved in the last run of our current strategy when it received fill status.

So this way we know that even though the account has 30 shares of X, we have to only see it as 10(30 - 20) if we are inside the second strategy.

@jbax
Copy link
Member

jbax commented Jan 19, 2020 via email

@kausality
Copy link
Author

kausality commented Jan 20, 2020

You may be right. I was thinking something along the lines of: https://www.backtrader.com/docu/position/

Is there a method to check the current position size in asset on the exchange? This will be useful in case whenever we restart the strategy due to computer restarting or program crashing.
Before emitting a BUY signal, we can use this method to check if we already have position in asset X on the exchange and if yes, then don't emit signal.

I tried to find something like it in the source files but couldn't.

@jbax
Copy link
Member

jbax commented Jan 20, 2020

When live trading, ClientAccount.updateBalances() should return a Map<String, Balance> with all open positions, including amounts locked (i.e. in some order). Even if you open a trade manually on the exchange directly, updateBalances will pick up the changes in your account balance.

This is done atuomatically and you can simply use Balance balance = trader.balance("BTC") from within the OrderManager that is called before (and after) placing an order.

Let me know if this helps

@kausality
Copy link
Author

Looks like it is what I was looking for. Thanks.

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

No branches or pull requests

2 participants