harwee / IQOption-Api

** Unmaintained ** I have rewritten some of the functionality using async if you are want to use the updated code you can use the code from `async` branch
Apache License 2.0
52 stars 54 forks source link

Balance not updating accordingly #41

Open cdgn-coding opened 5 years ago

cdgn-coding commented 5 years ago

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

harwee commented 5 years ago

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

djumpen commented 5 years ago

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)

cdgn-coding commented 5 years ago

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)

djumpen commented 5 years ago

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

harwee commented 5 years ago

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.

zmedia786 commented 5 years ago

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

cdgn-coding commented 5 years ago

@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

djumpen commented 5 years ago

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

cdgn-coding commented 5 years ago

@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)
MightyMaxSaviorOfTheUniverse commented 5 years ago

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!

MightyMaxSaviorOfTheUniverse commented 5 years ago

@cnexans

please help

djumpen commented 5 years ago

@MightyMaxSaviorOfTheUniverse I just run separate thread with infinite loop and check for updates there. Works well

MightyMaxSaviorOfTheUniverse commented 5 years ago

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

_dictitems([])

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

MightyMaxSaviorOfTheUniverse commented 5 years ago

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!

Big-Tigga commented 5 years ago

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