Skip to content
This repository has been archived by the owner on Dec 9, 2019. It is now read-only.

Balance not updating accordingly #41

Open
cdgn-coding opened this issue Jul 2, 2019 · 15 comments
Open

Balance not updating accordingly #41

cdgn-coding opened this issue Jul 2, 2019 · 15 comments

Comments

@cdgn-coding
Copy link

cdgn-coding commented Jul 2, 2019

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
Copy link
Owner

harwee commented Jul 3, 2019

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
Copy link

djumpen commented Jul 7, 2019

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
Copy link
Author

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
Copy link

djumpen commented Jul 8, 2019

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

@harwee
Copy link
Owner

harwee commented Jul 9, 2019

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
Copy link

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

@cdgn-coding
Copy link
Author

@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
Copy link

djumpen commented Jul 15, 2019

@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
Copy link
Author

cdgn-coding commented Jul 15, 2019

@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

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

@cnexans

please help

@djumpen
Copy link

djumpen commented Sep 5, 2019

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

@MightyMaxSaviorOfTheUniverse

@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

@MightyMaxSaviorOfTheUniverse

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
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants