n1nj4z33 / iqoptionapi

IQ Option API 4.x (Python 2.7) The project is obsolete and is not supported because of problems with access to IQ Options in Russia
119 stars 539 forks source link

Does this still work? #23

Open MadOne199 opened 7 years ago

MadOne199 commented 7 years ago

Hi, I am new to Python but have programmed in other languages. I tried the following code in a new document run in TextWrangler - using this code:-

from iqoptionapi.api import IQOptionAPI api = IQOptionAPI("iqoption.com", "username", "password") api.connect() balance = api.profile.balance print balance api.setactives([1, 2]) api.getcandles(1,1) data = api.candles.candles_data print api.candles.candles_data

It runs okay but I get None from both print commands? But I notice that if I leave username as "username" and password as "password", it still runs okay, so is there a way to determine if it actually did connect correctly?

I installed as per the instructions, but my code is a new file created on my desktop - does that matter? Does the code need to be within the installed files path?

I obviously changed the username to my email, and password to my password. Are HTML special characters handled in passwords?

I tried opening an account at IqOption using a password without special characters, but the same result. I then tried testing the wss address of wss://iqoption.com/echo/websocket at the site - https://www.websocket.org/echo.html, and that seems to connect via the site.

I am trying to understand how this API works. It is a hobby - learning to program - I have made practical programs in Java to trade on the iqOption platform, but the price stream I used is not good enough and results in loses. Ideally I want to understand how the HTTP and WSS connections work in terms of command structure, but as I cannot get this simple program to work it seems a long long way off.

Can anyone please confirm whether this API still works. I am wondering if IqOption moved their api? And if it does work, can you see what I have done wrong?

MightyMaxSaviorOfTheUniverse commented 4 years ago

One thing I've been noticing about these xhr request is that they don't have a authentication mechanism, surely "user_id" and "device_id" is something but I don't think they play a part in authentication. My bet is that these xhr request and websocket connection both make up for a success call, when inspect the messages of the ws in chrome dev tool, you can see it does send this frame to the server

{"name": "sendMessage", "request_id": "215", "msg": {"name": "binary-options.open-option", "version": "1.0", "body": {"user_balance_id": 262936171, "active_id": 76, "option_type_id": 3, "direction": "call", "expired": 1576941840, "refund_value": 0, "price": 80.23, "value": 1105420, "profit_percent": 83}}}

@redmiix24 @MightyMaxSaviorOfTheUniverse

EDIT: dont worry about my "user_balance_id" it's just a dummy account

Can we not simply send a WS command using your above parameters? I've been trying to do that very thing but a none return is my reply every time. I feel like a ws request would be far better than the HRX because ws return with a response other than statues ok. Instead of using the buyV2 request, how might I change that into a binary-options-open and successfully get a response?

Thank you in advance for the help

MightyMaxSaviorOfTheUniverse commented 4 years ago

HOLY FUCKING SHIT!

I SOLVED IT!!!!!

zidokobik commented 4 years ago

@MightyMaxSaviorOfTheUniverse
HOW?

redmiix24 commented 4 years ago

@MightyMaxSaviorOfTheUniverse how did you solve can you tell us what was wrong?

MightyMaxSaviorOfTheUniverse commented 4 years ago

Sorry just got back from work. I'm trying to replicate the results but I managed to make one automatic bet while on my break. Thanks to @dwighthalpert I managed to find a working means of trading.


await self._parent.send_socket_message(
            "sendMessage",
            {"name": "binary-options.open-option",
              "version": "1.0",
              "body": {"user_balance_id": 2________7,
                       "active_id": active_ID,
                       "option_type_id": 3,
                       "direction": direction,
                       "expired": expiration,
                       "refund_value": 0,
                       "price": price,
                       "value": Option_ID,
                       "profit_percent": 100}
              },
            request_id,
        ) ```

Right now it keeps returning none returns but using this same WS request it sent a successful automatic bid. I'm sorry that this is all I have to offer, maybe I'll edit this post in  few hours with the solution

Lets hope this thing is solved for good now

EDIT:

If you are using the old WS request, simply change buyV2 with binary-options.open-option and of course change the other parameters.

This:
    **"buyV2",
            {
                "price":price,
                "act":self._id,
                "exp":expiration,
                "type":sell_type,
                "direction":direction.lower(),
                "user_balance_id":self._parent._active_balance_id,
                "value":value,
                "time":int(self._parent._server_time/1000),
            },
            request_id,**

becomes this:

            **
            "sendMessage",
            {"name": "binary-options.open-option",
              "version": "1.0",
              "body": {"user_balance_id": 2________7,
                       "active_id": active_ID,
                       "option_type_id": 3,
                       "direction": direction,
                       "expired": expiration,
                       "refund_value": 0,
                       "price": price,
                       "value": Option_ID,
                       "profit_percent": 100}
              },
            request_id,
        )**
redmiix24 commented 4 years ago

@MightyMaxSaviorOfTheUniverse this code is c#? I always remember this await async in c#. I didn't see it in Python, can you confirm?

MightyMaxSaviorOfTheUniverse commented 4 years ago

@MightyMaxSaviorOfTheUniverse this code is c#? I always remember this await async in c#. I didn't see it in Python, can you confirm?

No it is in python. I only know python and java

redmiix24 commented 4 years ago

@MightyMaxSaviorOfTheUniverse ok let me test it and see Thank you bro

redmiix24 commented 4 years ago

@MightyMaxSaviorOfTheUniverse last thing. We need to change the below in the file buyv2.py correct? Below parameters needs to be updated by your parameters yes? data= { "price": price, "act": active, "exp": exp, "type": option, "direction": direction, "time": self.api.timesync.server_timestamp }

MightyMaxSaviorOfTheUniverse commented 4 years ago

@MightyMaxSaviorOfTheUniverse last thing. We need to change the below in the file buyv2.py correct? Below parameters needs to be updated by your parameters yes? data= { "price": price, "act": active, "exp": exp, "type": option, "direction": direction, "time": self.api.timesync.server_timestamp }

Yes that is correct

The difficult ones to get are active id and option id.

Active id is gained by getting the stock id... in my program that wasn't hard to do but I don't know what your code looks like. For me all I had to do was say Stock.ID

Option id is the last ID given when you collect the stock candles, they come with IDs

redmiix24 commented 4 years ago

@MightyMaxSaviorOfTheUniverse yes I remember those IDs when I was inspecting the network requests by Google chrome inspector. When you fire the "call" button. There are 3 json requests. "button_pressed" which contains the ids we mentioned above and the 2 remaining requests contains the ones you are taking about. Yes I get you bro. I will tweak the code a little bit and come back here.

Thanks a lot for your effort. We as a team we can always find solutions. I tried from my end also and put what have I done. Will update you guys soon

MightyMaxSaviorOfTheUniverse commented 4 years ago

Ok I made some progress, and instead of swearing this time I'll share the results:


'msg': {'message': 'Time for purchasing options is over, please try again later.', 'result': {'request_id': None}}, 'status': 4104}
Place Bet```
MightyMaxSaviorOfTheUniverse commented 4 years ago

@redmiix24

Sorry about this but I actually gave you the wrong information. the set up for the new parameters are like this

            "sendMessage",
            {"name": "binary-options.open-option",
              "version": "1.0",
              "body": {"user_balance_id": 2________7,
                       "active_id": active_ID,
                       "option_type_id": 3,
                       "direction": direction,
                       "expired": expiration,
                       "refund_value": 0,
                       "price": price,
                       "value": Option_ID,
                       "profit_percent": 100}
              },
            request_id,
        )

I successfully made a bet during my lunch break, but then changed it before seeing the result. Hence why I didn't understand why I couldn't replicate the results. Good luck finding the solution before I do

:P

RickyGlobal9 commented 4 years ago

Yes, now u r in the right track. The status code 4104 seems to b sent proposal "price has been changed" for purchasing the contract meaning either send buy requests for delayed contract or have execute the code much faster...

On Sun, Dec 22, 2019, 11:37 PM MightyMaxSaviorOfTheUniverse < notifications@github.com> wrote:

Ok I made some progress, and instead of swearing this time I'll share the results:

'msg': {'message': 'Time for purchasing options is over, please try again later.', 'result': {'request_id': None}}, 'status': 4104} Place Bet```

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/n1nj4z33/iqoptionapi/issues/23?email_source=notifications&email_token=ACORVB6M6FVHMBNQWEBYTUDQZ6UFVA5CNFSM4DK74Y4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHPWPMQ#issuecomment-568289202, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACORVB2GLRTLR4TR3IJIHFLQZ6UFVANCNFSM4DK74Y4A .

MightyMaxSaviorOfTheUniverse commented 4 years ago

Ok I'm a genius, it is official.

In order to make a bet, make sure the commission in your request is set to ZERO(0). For some reason the commission is 4 by default and if you place a number higher than 4 then it returns an error of 'Commission changed'

MightyMaxSaviorOfTheUniverse commented 4 years ago

Ok new problem

How do you get your balance ID of your practice or real money account?

As you can see this new buy order requires your balance ID, and while I can easily get my practice ID, it isn't allowing me to see the real account ID.

When you look at the XHR request it merely says, account value 4 when dealing with the real account but it isn't providing the ID.

Any help will be great, thanks in advance

zidokobik commented 4 years ago

I am not responding but am following this thread. I don't know why but seems the thread is not moving in correct direction, possibly you are in an endless track. You really do not need to mesh with device_id/xhr headers, the clue is inside iq's buying architecture it's same as any financial institution works a) Send proposal requests b) If accepted then buy contract Hope this will give you rough idea I am not a python developer but if needed i can share my experience in either c# or nodejs whatever you all guys prefer. On Sat, Dec 21, 2019, 9:03 PM SamBee @.***> wrote: @dwighthalpert https://github.com/dwighthalpert @MightyMaxSaviorOfTheUniverse https://github.com/MightyMaxSaviorOfTheUniverse @HubSpace2000 https://github.com/HubSpace2000 Honestly after troubleshooting alot and after trying both ws and xhr I found out 2 things. The iqoption stable library developed by — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#23?email_source=notifications&email_token=ACORVB5KTMUOF67GK34HTGLQZYZONA5CNFSM4DK74Y4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHO6FRA#issuecomment-568189636>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACORVBYEMZMI5XKZ5ESMBY3QZYZONANCNFSM4DK74Y4A .

does this mean we have to make 2 or more separate requests for a success call.

MightyMaxSaviorOfTheUniverse commented 4 years ago

@zidokobik

I'm not too sure what you are confused about?

All you need to do is change the following in this file(binary_option.py)


This:
    "buyV2",
            {
                "price":price,
                "act":self._id,
                "exp":expiration,
                "type":sell_type,
                "direction":direction.lower(),
                "user_balance_id":self._parent._active_balance_id,
                "value":value,
                "time":int(self._parent._server_time/1000),
            },
            request_id,

becomes this:

            "sendMessage",
            {"name": "binary-options.open-option",
              "version": "1.0",
              "body": {"user_balance_id": 2________7,
                       "active_id": active_ID,
                       "option_type_id": 3,
                       "direction": direction,
                       "expired": expiration,
                       "refund_value": 0,
                       "price": price,
                       "value": Option_ID,
                       "profit_percent": 100}
              },
            request_id,
        )```
MightyMaxSaviorOfTheUniverse commented 4 years ago

Ok I need some serious help now in trying to find the ID of my active account. I need the real money account ID because with the new changes they made to the app, when you trade you need to include your account ID.

How do you get your balance ID?

redmiix24 commented 4 years ago

@MightyMaxSaviorOfTheUnivers i will try tonight and post here. Just give me some time

MightyMaxSaviorOfTheUniverse commented 4 years ago

@redmiix24

Don't worry, I guess I'm super impatient because I solved this problem too. Still I would like to see how you did it because how I did it was super messy and manual

dwighthalpert commented 4 years ago

GUYS, I DID IT It's just websocket guys, no xhr involved

EDIT: cleaning up codes, will update later

redmiix24 commented 4 years ago

@dwighthalpert congratulations bro. Kindly tell us how did you bypass the expiry time issue and those IDs

MightyMaxSaviorOfTheUniverse commented 4 years ago

@dwighthalpert congratulations bro. Kindly tell us how did you bypass the expiry time issue and those IDs

But dude... I solved this problem yesterday, or did you not catch on that I already started auto trading?

Ok I'm a genius, it is official.

In order to make a bet, make sure the commission in your request is set to ZERO(0). For some reason the commission is 4 by default and if you place a number higher than 4 then it returns an error of 'Commission changed'

kkagill commented 4 years ago

@MightyMaxSaviorOfTheUniverse

are you looking for this?

"user_balance_id":int(self.api.profile.balance_id),

MightyMaxSaviorOfTheUniverse commented 4 years ago

@kkagill

Unfortunately that only gives you your Practice account ID, I need the real account ID. I've already managed to get this ID but through a very manual process.

If you have any automatic means that would be great, I want my program to be able to work for any ones account not just mine

MightyMaxSaviorOfTheUniverse commented 4 years ago

If anyone is still struggling to make a bet, let me know what you problem is and I'll get back to you

pavilion20bw commented 4 years ago

@dwighthalpert @MightyMaxSaviorOfTheUniverse

Can you share your working code/script please?

dwighthalpert commented 4 years ago

Alright, I just made a pull requests at @Lu-Yi-Hsun iqoptionapi repo that should fix the buy and multi buy functions.

redmiix24 commented 4 years ago

@dwighthalpert thanks alot bro

MightyMaxSaviorOfTheUniverse commented 4 years ago

Uhm... so are you guys still having problems getting this program to run?

All you have to do is follow my instructions above and you should be able to trade again. I really don't understand what the problem is?

pavilion20bw commented 4 years ago

@MightyMaxSaviorOfTheUniverse

I'm a total noob, i just want someone forward me a single script (i know yours is working) so i can learn step by step.

Hattingg commented 4 years ago

Fix: https://github.com/dwighthalpert/iqoptionapi/commit/d83e54bc1c9848dca44ef290ccaa8b48ddaf43a0#diff-3a83549416a011249baa2c026484f498

MightyMaxSaviorOfTheUniverse commented 4 years ago

@everyone @dwighthalpert

I see that they changed the command for buying AGAIN it could just be my computer but if it isn't I'm asking @dwighthalpert for the solution. Last time it was your ws command retrieval that lead to the answer, please use your chrome browser magic again and find out if they changed the WS command message for buy orders

Hopefully this time it doesn't take 20 days to find the solution.

Thank you in advance

zidokobik commented 4 years ago

@MightyMaxSaviorOfTheUniverse Mine is working fine, can you share your code, I might be able to help.

MightyMaxSaviorOfTheUniverse commented 4 years ago

@zidokobik

Oh wow, sorry for taking so long to reply to this message. I eventually manage to fix the problem but now I see that the commission isn't working anymore. Looks like they changed something any ideas?

find me here

https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/193