IQOption-Api icon indicating copy to clipboard operation
IQOption-Api copied to clipboard

Balance not updating accordingly

Open cdgn-coding opened this issue 5 years ago • 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

cdgn-coding avatar Jul 02 '19 14:07 cdgn-coding

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

harwee avatar Jul 03 '19 10:07 harwee

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)

djumpen avatar Jul 07 '19 13:07 djumpen

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)

cdgn-coding avatar Jul 08 '19 13:07 cdgn-coding

@cnexans I'll appreciate if you'll notify about updates in current topic. Thanks.

djumpen avatar Jul 08 '19 13:07 djumpen

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.

harwee avatar Jul 09 '19 09:07 harwee

@cnexans use this library instead it has all the function https://github.com/Lu-Yi-Hsun/iqoptionapi

zmedia786 avatar Jul 09 '19 10:07 zmedia786

@djumpen I found a way to check. As @harwee mentioned, one can use portfolio field to check win/loose/equal. Check screenshots Screen Shot 2019-07-14 at 23 31 29 Screen Shot 2019-07-14 at 23 31 39

Use the position id to check inside portfolio dictionary

cdgn-coding avatar Jul 15 '19 02:07 cdgn-coding

@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 avatar Jul 15 '19 02:07 djumpen

@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)

cdgn-coding avatar Jul 15 '19 03:07 cdgn-coding

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

djumpen avatar Sep 05 '19 21:09 djumpen

@djumpen

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()

Big-Tigga avatar Sep 16 '19 21:09 Big-Tigga