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
53 stars 53 forks source link

How can I get the profit of a binary option? #9

Open vtandrea opened 6 years ago

vtandrea commented 6 years ago

Hi, I would like to get something like: api.getProfit("EURUSD") -> return: 71% Can I use getMarketData?

harwee commented 6 years ago

I am searching for the endpoint which provides this, as soon as I find it, it will be implemented.

vtandrea commented 6 years ago

@harwee Thanks! I'll wait for it.

ghost commented 6 years ago

Hi, any update?

lucianopinheiro commented 5 years ago

You have 2 ways. At "api_option_init_all_result" JSON response you have msg['binary']['actives'][#]['option']['profit']['comission'] So, you get profit from it. Profit = (100-comission). But sometimes the value change. So, they have JSON ''active_comission_change" So, you can't just ask to iqoption, but you can get these values when they are available.

LeonardoRk commented 5 years ago

Hi, good night. Where can I find “active_comission_change”? And how to get this JSON to know the real profit value?

lucianopinheiro commented 5 years ago

They send to you automatically. You just need to filter on ws/client.py. The name is activeCommissionChange, not active_comission_change. My bad. As I told before, profit = 100 - comission. The real profit value happens only when you make an order, with real bet/order value. Before that, you have to calculate.

LeonardoRk commented 5 years ago

okay, thanks. Is is possible to take the profit of 1+ min, instead of 5+ min?

MightyMaxSaviorOfTheUniverse commented 5 years ago

@lucianopinheiro

Could you give me the exact code you used to get the profit? I've been trying to understand what you have said, but I can't find anyway to implement it Any help would be greatly appreciated thank you in advance

Also, how do you distinguish which Option you want to get the profit from?

Up until now I've been placing orders in order to get the profit value, which means I'm losing money which isn't very good!

MightyMaxSaviorOfTheUniverse commented 5 years ago

@LeonardoRk

Have you figured it out yet?

Please if you have, can you respond to my request for the code.

Thank you in advance

lucianopinheiro commented 5 years ago

My code probably don't work on files. Anyhow, they changed something again. I am a little far from code, and look like they have a new message instead of (or beside) api_option_init_all_result, called front. So, I can give you some pieces of code

At begginning:

At iqoptionapi/client.py

    def on_message(self, message): 
        [...]
        elif message["name"] == "api_option_init_all_result": # ok 2018-04
            self.api_option_init_all_result(message["msg"])

At iqoptionapi/messages/api_option_init_all.py

    if msg["isSuccessful"]:
        turbo = msg["result"]["turbo"]
        turbo_actives_all = turbo["actives"]

        for taa in turbo_actives_all:
            act = turbo['actives'][taa]
            active = Active(int(taa), act['name'].replace('front.', ''))
            active.gain = 100 - act['option']['profit']['commission']

===========

When it change.

At iqoptionapi/client.py

        elif message["name"] == "activeCommissionChange":
            self.api.active_commission_change(message["msg"])

At iqoptionapi/active_commission_change.py

def ActiveCommissionChange(active, msg):
    """Change commissions from actives.
    Commition is the value IqOption get if you win.
    gain = 100 - commission"""
    if msg["option_type"] == 3:
        active.gain = 100 - msg["commission"] # turbo!
MightyMaxSaviorOfTheUniverse commented 5 years ago

@lucianopinheiro

Thanks for the reply.

I managed to get the commission and stumbled onto a new issue. The program doesn't give you any indication as to when your stock is sold.

I managed to make $2 last night using automatic trading, but my program had no way of telling me when I made a gain or a lose so it was basically blind betting :D

Any ideas for what I can do to fix that? I would like to be a billionaire as soon as possible please

lucianopinheiro commented 5 years ago

I managed to make $2 last night using automatic trading, but my program had no way of telling me when I made a gain or a lose so it was basically blind betting :D

You have to study the response listInfoData. But it is a bit tricky, because you use it on 2 different ocasions. My code (on client.py) now:

        elif message["name"] == "listInfoData": # operation result
            if int(message["msg"][0]["now"]) >= int(message["msg"][0]["expired"]):
                self.api.async_queue.put_listinfodata(message["msg"])
                if self.api.openorders > 0:
                    self.api.openorders -= 1
            if message["msg"][0]["win"] != 'equal':
                if message["msg"][0]["win"] == 'win':
                    value = message["msg"][0]["win_amount"] - message["msg"][0]["sum"]
                else:
                    value = - message["msg"][0]["sum"]
LeonardoRk commented 5 years ago

What are the 2 different ocasions? kkkk

LeonardoRk commented 5 years ago

My code probably don't work on files. Anyhow, they changed something again. I am a little far from code, and look like they have a new message instead of (or beside) api_option_init_all_result, called front. So, I can give you some pieces of code

At begginning:

At iqoptionapi/client.py

  def on_message(self, message): 
      [...]
      elif message["name"] == "api_option_init_all_result": # ok 2018-04
          self.api_option_init_all_result(message["msg"])

At iqoptionapi/messages/api_option_init_all.py

  if msg["isSuccessful"]:
      turbo = msg["result"]["turbo"]
      turbo_actives_all = turbo["actives"]

      for taa in turbo_actives_all:
          act = turbo['actives'][taa]
          active = Active(int(taa), act['name'].replace('front.', ''))
          active.gain = 100 - act['option']['profit']['commission']

===========

When it change.

At iqoptionapi/client.py

      elif message["name"] == "activeCommissionChange":
          self.api.active_commission_change(message["msg"])

At iqoptionapi/active_commission_change.py

def ActiveCommissionChange(active, msg):
  """Change commissions from actives.
  Commition is the value IqOption get if you win.
  gain = 100 - commission"""
  if msg["option_type"] == 3:
      active.gain = 100 - msg["commission"] # turbo!

Where is the client.py file? I cannot find it. I was looking for 'activeCommissionChange' at 'incoming_message' function, but this name never arrived to me.

lucianopinheiro commented 5 years ago

Where is the client.py file? I cannot find it. I was looking for 'activeCommissionChange' at 'incoming_message' function, but this name never arrived to me.

Sorry. It was another project. :) The equivalent is the function that receives the JSON message on api.py: on_socket_message(self,socket,message):

By the way, here I got no activeCommissionChange too. They changed something. Now, when I receive a new message, my system warns me, but today no message was received. I will look up to the new JSON message. On this system, you just need to enable this print (or better, change it to log) to watch new responses.

        else:
             print(message)
            pass
lucianopinheiro commented 5 years ago

What are the 2 different ocasions? kkkk

When you receive the result for your option (win, loose, empty) and when you create your bet. But looks like they were replaced. Now we have 4 messages option-*: option-opened, option-rejected, option-closed, option-archived. But I have not studied them yet.

LeonardoRk commented 5 years ago

Where is the client.py file? I cannot find it. I was looking for 'activeCommissionChange' at 'incoming_message' function, but this name never arrived to me.

Sorry. It was another project. :) The equivalent is the function that receives the JSON message on api.py: on_socket_message(self,socket,message):

By the way, here I got no activeCommissionChange too. They changed something. Now, when I receive a new message, my system warns me, but today no message was received. I will look up to the new JSON message. On this system, you just need to enable this print (or better, change it to log) to watch new responses.

        else:
             print(message)
            pass

I could not find the function 'on_socket_message', i found 'processing_incoming_message' then i redirected all the raw_message to a log file. The only commission thing a found was in 'api_option_init_all_result' and only on login then never more. On google-chrome debug the message name is 'commission-changed' but this message never comes through the iqoption socket api. Thank you for the answer (=

MightyMaxSaviorOfTheUniverse commented 5 years ago

I found the solution to this problem quite some time ago but neglected to share it. let me make up for that by sharing it now and perhaps you can further help me by improving my code because it is a little noob, since I know almost nothing about python

Stock = iqoption.options["binary"]["EURUSD"] if((Stock.is_enabled)): profit=100-int(str(Stock.option).split(':')[2].split(' ')[1].replace(",",""))

LeonardoRk commented 5 years ago

Goof afternoon. What message do i need to subscribe in order to receive the 'commission-changed' message name? I receive many name messages, but not 'commission-changed'.