Balance not updating accordingly
Opened this issue · 15 comments
Hello,
Thank you very much for your effort. I'm using this library implementation to automate binary options but I have a trouble calculating the if an option went well or bad. My very first idea was to just compute current_balance - last_balance
, although even if I wait 10 seconds after the option is closed, the api.balance
is exactly the same.
Is there a way to compute the profit?
Moreover, if you share the API docs I may try to implement it.
EDIT: I tried using api.update_balances()
but it doesn't work neither
Regards
iqoption.portfolio
stores all the options you open/close, each object in iqoption.portfolio
is an object which stores all the data of your option, try checking the attributes of that object, it gets updated automatically whenever the options is closed. Also don't forget to user the code from this tree that is updated https://github.com/harwee/IQOption-Api/blob/async
it gets updated automatically whenever the options is closed
@harwee can we have some callback when option gets closed (to write result into db for example)
This feature would be really useful to me. I opened a fork of this project in IssueHunt if someone is interested. We can merge it back to the parent project (this one)
@cnexans I'll appreciate if you'll notify about updates in current topic. Thanks.
It's not difficult to implement it but I am busy with some other work so if someone can implement this and create a pull request, will merge it.
@cnexans use this library instead it has all the function https://github.com/Lu-Yi-Hsun/iqoptionapi
@cnexans Yes, I'm already doing this. But I still have no proper trigger for this check. I was trying to run infinite async loop aside but have not enough expertise in python to accomplish this (I'm from go/php)
@djumpen That's my implementation right now. I will take that tech debt in few weeks, probably requesting a PR on here.
You can use the implementation for waiting until is done in my repo. You have to use asyncio so you don't block the tasks inside the API.
It should look like this
def order_is_completed(order_id):
return api.portfolio[order_id]['rate_finished']
def get_if_won(order_id):
return api.portfolio[order_id]['win']
async def wait_until_is_complete(order_id):
while not order_is_completed():
await asyncio.sleep(quantity_of_seconds)
return get_if_won(order_id)
def place_order_and_get_id():
# buy sync
# get order_id
return order_id
order_id = place_order_and_get_id()
await wait_until_is_complete(order_id)
I'm currently stuck on this same problem.
Has anyone found a working answer yet?
I've already tried all the above with no results. The closest to an answer I could get was to just create a whole new instance of the program within the program and starting that to get a new balance...
but that is insane!
@cnexans
please help
@MightyMaxSaviorOfTheUniverse I just run separate thread with infinite loop and check for updates there. Works well
Can you provide your exact code?
It isn't working on my side and I also ran infinite loops to see if at least one instance of it works.
on my side the portfolio is NEVER populated so the following code returns
print(iqoption.portfolio.items())
Return:
dict_items([])
I've tried 3 different methods for getting the results of the market and none work. I've tried looking at the balance, refreshing and starting a whole new instance of the program to get a balance update, and this portfolio method.
NOTHING WORKS.
Can you please put my mind at easy by showing me exactly how you do it... it could even be a network error on my side
I fond a sure fire way to get the balance, no matter what!
You simply look at the candles and compare the ending time of your stock with the currency value in the candle at that placement.
DONE!
Call this function before you use/call the balance again. It will update the balance so that you get the latest/updated balance.
api.update_balances_sync()