Lu-Yi-Hsun / iqoptionapi

IQ Option API
371 stars 286 forks source link

Buy option not working anymore #168

Open redmiix24 opened 4 years ago

redmiix24 commented 4 years ago

yes the buy option is not working anymore, surely iqoption changed some parameters. Will troubleshoot the problem and come back here

Regards

Frank-prog-stack commented 4 years ago

so there is not the possibiliy to pass orders automatically ?????

redmiix24 commented 4 years ago

@Frank-prog-stack apparently iqoption changed something in their socket stream. Now the error in Python is : buy takes 5 arguments (6 was given)

dwighthalpert commented 4 years ago

@Frank-prog-stack apparently iqoption changed something in their socket stream. Now the error in Python is : buy takes 5 arguments (6 was given)

how to fix ??

redmiix24 commented 4 years ago

@Frank-prog-stack I have checked quickly this morning. I need time to know what is going on. Also some other threads are saying they changed it to XHR messages instead of WS. Will look into it when I have time. I developed separate project with @Lu-Yi-Hsun library. Now it seems that he cannot continue support it for free and I understand. So probably will do something on my own and release it here.

pavilion20bw commented 4 years ago

@redmiix24 Hope you find how to fix it. Please do a pull request once you've figured it out.

lp1982 commented 4 years ago

Checking with Chrome DevTools, the traderoom application is definitely using XHR. The body of a trade request looks like {"category":"button_pressed","name":"traderoom_deal-call","value":1.0,"user_id":xxx,"group_id":147,"platform_id":9,"app_version":"1632.5.2413.release","device_id":"xxx","time":1576255163458,"parameters":{"asset_id":"5","balance_type":"4","expiration_time":"1576255200","instrument_type":"turbo","leverage_value":"1","order_type":"market"}}

On the other hand, other WS requests still work. So what gives?

redmiix24 commented 4 years ago

@lp1982 I successfully send post request with "button_pressed" in Python and it returned code 200 however no call or put has been made because I know I need to make a function that put the server time in my request and I also need to make another function to calculate the expiration time.

Timesyn I can get it with socket but expiration I need to so how it's working , it seems a bit difficult for me. Anyhow I'm half way through .

Will share my code later

lp1982 commented 4 years ago

Isn't this just, for turbos,

get_expiration_time(int(self.api.timesync.server_timestamp),duration)

Defined as

def get_expiration_time(self, duration):
    exp = time.time()
    if duration >= 1 and duration <= 5:
        option = 3#"turbo"
        # Round to next full minute
        # datetime.datetime.now().second>30
        if (exp % 60) > 30:
            exp = exp - (exp % 60) + 60*(duration+1)
        else:
            exp = exp - (exp % 60)+60*(duration)

The Darth-Carrotpie code for the binaries is wrong though. I modified it as follows to work for 15-minute binaries (don't try it for greater times, I'm not sure it will give the correct option)

    elif duration > 5:
        option = 1#"binary"
        period = int(round(duration / 15))
        tmp_exp = exp - (exp % 60)  # nuima sekundes
        tmp_exp = tmp_exp - (tmp_exp % 3600)  # nuimam minutes
        j = 0
        while exp > tmp_exp + (j)*15*60:  # find quarter
            j = j+1
        quarter = tmp_exp + (j)*15*60
        if quarter - exp > 5*60:
            exp = quarter + (period-1)*15*60
        else:
            exp = quarter + period*15*60
    else:
        logging.error("ERROR get_expiration_time DO NOT LESS 1")
        exit(1)
    return exp, option
Frank-prog-stack commented 4 years ago

@ redmiix24 can I have your mail address please ?

redmiix24 commented 4 years ago

@Frank-prog-stack same username + gmail.com

Lu-Yi-Hsun commented 4 years ago

Everyone can Pull request to fix this public version

redmiix24 commented 4 years ago

@lp1982 @Frank-prog-stack

only expiration time is not taken into consideration although its showing in my output

input

import requests
import json
import urllib3
import time
from websocket import create_connection

def get_expiration_time(self, duration):
    exp = time.time()
    if duration >= 1 and duration <= 5:
        #option = 3 #"turbo"
        # Round to next full minute
        # datetime.datetime.now().second>30
        if (exp % 60) > 30:
            exp = exp - (exp % 60) + 60*(duration+1)
            print int(exp)
        else:
            exp = exp - (exp % 60)+60*(duration)
            print int(exp)

ws = create_connection("wss://iqoption.com/echo/{randomnumber}/{randomnumber}/websocket")
result = ws.recv()
data = json.loads(result)
get_expiration_time(data["msg"],1)

url = 'https://event.iqoption.com/api/v1/events'

headers = {  'Host': 'event.iqoption.com',
             'Connection': 'keep-alive',
             'Content-Length': '1191',
             'X-Action': 'single',
             'Origin': 'https://iqoption.com',
             'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36',
             'Content-Type': 'application/json',
             'Accept': '*/*',
             'DNT': '1',
             'Referer': 'https://iqoption.com/traderoom',
             'Accept-Encoding': 'gzip}, deflate}, br',
             'Accept-Language': 'en-GB},en-US;q=0.8},en;q=0.6',
}              

payload =   {
    "category": "button_pressed",
    "name": "traderoom_deal-call",
    "value": 50,
    "user_id": XXXXXX,
    "group_id": XXX,
    "platform_id": 9,
    "app_version": "1632.5.2413.release",
    "device_id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "time": data["msg"],
    "parameters": {
      "asset_id": "77",
      "balance_type": "4",
      "expiration_time": get_expiration_time(data["msg"],1),
      "instrument_type": "turbo",
      "leverage_value": "1",
      "order_type": "market"
    }
  }

print payload

r = requests.post(url, data=json.dumps(payload), headers=headers)
print(r.content)

output

time : 1576312653177
expiration_time : 1576312740

{'category': 'button_pressed', 'platform_id': 9, 'app_version': '1632.5.2413.release', 'user_id': XXXXX, 'name': 'traderoom_deal-call', 'parameters': {'asset_id': '77', 'instrument_type': 'turbo', 'order_type': 'market', 'leverage_value': '1', 'balance_type': '4', 'expiration_time': None}, 'time': 1576312653177, 'group_id': XXX, 'value': 50, 'device_id': 'XXXXXXXXXXXXXXXXXXXXXXXXXX'}
{"code":200,"errors":[]}

as you can see 'expiration_time': None

anyone can try a fix ?

zidokobik commented 4 years ago

@redmiix24 your get_expiration_time doesnt return anything

redmiix24 commented 4 years ago

@zidokobik if you print it before its working however inside the json its not taking into consideration

lp1982 commented 4 years ago

Yeah, sorry, you're missing the end of the code as you didn't include the binaries part.

else:
    logging.error("ERROR get_expiration_time DO NOT LESS 1")
    exit(1)
return exp, option
redmiix24 commented 4 years ago

@lp1982 fixed it and now there is expiration time , but still not executing anything.

I went back to @Lu-Yi-Hsun code and the error thrown was "late by 30 seconds"

I'm troubleshooting his expiration.py file where the function of get_expiration_time

Will update you soon

dwighthalpert commented 4 years ago

I just make a pull request that should fix it, unfortunately I was working with ver5.1 so .... things got rollback a bit

redmiix24 commented 4 years ago

@dwighthalpert thanks a lot brother

Frank-prog-stack commented 4 years ago

Here is the version which work correctly ???

Le 24 déc. 2019 19:02, "SamBee" notifications@github.com a écrit :

@dwighthalpert https://github.com/dwighthalpert thanks a lot brother

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/168?email_source=notifications&email_token=ANYHVIGE7LBFWEIOUPJBZ3LQ2I6CJA5CNFSM4JZCBKMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHTOCZI#issuecomment-568779109, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANYHVIH63V7LWKXBDXISNGLQ2I6CJANCNFSM4JZCBKMA .

Frank-prog-stack commented 4 years ago

What are we supposed to learn to develop an entire Iq Option API like Lu-Yi-Hsun did? Can someone give me for example a training PDF? I know the Python language but I don't know anything about API development?

Le 24 déc. 2019 21:01, "EVERYDAY ON LINE" frankmuhindokansime@gmail.com a écrit :

Here is the version which work correctly ???

Le 24 déc. 2019 19:02, "SamBee" notifications@github.com a écrit :

@dwighthalpert https://github.com/dwighthalpert thanks a lot brother

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/168?email_source=notifications&email_token=ANYHVIGE7LBFWEIOUPJBZ3LQ2I6CJA5CNFSM4JZCBKMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHTOCZI#issuecomment-568779109, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANYHVIH63V7LWKXBDXISNGLQ2I6CJANCNFSM4JZCBKMA .

vivekkairi commented 4 years ago

I just make a pull request that should fix it, unfortunately I was working with ver5.1 so .... things got rollback a bit

Still the error is same,

Cannot purchase and option (the asset is not available at the moment)

I cloned your git and tried too, same op

dwighthalpert commented 4 years ago

@vivekkairi Are you sure that the market is opening?

vivekkairi commented 4 years ago

@vivekkairi Are you sure that the market is opening?

Ya I can manually place order from browser

kkagill commented 4 years ago

@vivekkairi Did you try with OTC market? Ex: EURUSD-OTC

vivekkairi commented 4 years ago

@vivekkairi Did you try with OTC market? Ex: EURUSD-OTC

Ya it worked but what's OTC? I want to do Binary trading

kkagill commented 4 years ago

OTC market is for weekends & holidays. It is binary trading.

dwighthalpert commented 4 years ago

@vivekkairi It's chrismas, Stock markets are closed, only otc markets are open

https://blog.iqoption.com/en/trading-schedule-during-the-holidays/

Frank-prog-stack commented 4 years ago

@vivekkairi how can I program a whole IQ Option API like did Lu-Yi-Hsun. What are prerequisites and steps ? Help me with an advice please !!!

Le 25 déc. 2019 08:26, "dwighthalpert" notifications@github.com a écrit :

@vivekkairi https://github.com/vivekkairi It's chrismas, Stock markets are closed, only otc markets are open

https://blog.iqoption.com/en/trading-schedule-during-the-holidays/

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/168?email_source=notifications&email_token=ANYHVIBMXZSHXW2FD4A5ZA3Q2L4HZA5CNFSM4JZCBKMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHT67EY#issuecomment-568848275, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANYHVICXBEKBUTQN5NSF3LLQ2L4HZANCNFSM4JZCBKMA .

PoYuTsai commented 4 years ago

@dwighthalpert Thanks for fixing buyv2!

截圖 2019-12-25 下午3 56 28

Everyone Merry Christmas :)

vivekkairi commented 4 years ago

@vivekkairi how can I program a whole IQ Option API like did Lu-Yi-Hsun. What are prerequisites and steps ? Help me with an advice please !!! Le 25 déc. 2019 08:26, "dwighthalpert" notifications@github.com a écrit : @vivekkairi https://github.com/vivekkairi It's chrismas, Stock markets are closed, only otc markets are open https://blog.iqoption.com/en/trading-schedule-during-the-holidays/ — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#168?email_source=notifications&email_token=ANYHVIBMXZSHXW2FD4A5ZA3Q2L4HZA5CNFSM4JZCBKMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHT67EY#issuecomment-568848275>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANYHVICXBEKBUTQN5NSF3LLQ2L4HZANCNFSM4JZCBKMA .

Even I'm new to these stuffs, it's majorly WS and XHR requests. Analyze them.

vivekkairi commented 4 years ago

@vivekkairi how can I program a whole IQ Option API like did Lu-Yi-Hsun. What are prerequisites and steps ? Help me with an advice please !!! Le 25 déc. 2019 08:26, "dwighthalpert" notifications@github.com a écrit : @vivekkairi https://github.com/vivekkairi It's chrismas, Stock markets are closed, only otc markets are open https://blog.iqoption.com/en/trading-schedule-during-the-holidays/ — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#168?email_source=notifications&email_token=ANYHVIBMXZSHXW2FD4A5ZA3Q2L4HZA5CNFSM4JZCBKMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHT67EY#issuecomment-568848275>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANYHVICXBEKBUTQN5NSF3LLQ2L4HZANCNFSM4JZCBKMA .

@dwighthalpert Any help would be appreciated.

dougrn commented 4 years ago

Guys, I did it!!!!

I fix the buy error. I had to change a few codes at three files (client.py, stable_api.py and buyv3.py)

iqoptionapi-5.3.zip

gstroligo commented 4 years ago

@dougrn thank you so much! You've acomplished something amazing! Can you specify what were the changes you made on those files?

dougrn commented 4 years ago

@dougrn thank you so much! You've acomplished something amazing! Can you specify what were the changes you made on those files?

Sure...

On client.py from this =>

        elif message["name"] == "buyComplete":
            try:
                self.api.buy_successful = message["msg"]["isSuccessful"]
                self.api.buy_id= message["msg"]["result"]["id"]
            except:
                pass

to this =>

        elif message["name"] == "option":
            try:
                self.api.buy_successful = message["msg"]
                self.api.buy_id= message["msg"]["id"]
            except:
                pass

On stable_api.py from this =>

    def buy(self, price, ACTIVES, ACTION, expirations):
        self.api.buy_successful = None
        self.api.buy_id = None
        self.api.buy(price, OP_code.ACTIVES[ACTIVES], ACTION, expirations)
        start_t=time.time()
        while self.api.buy_successful == None and self.api.buy_id == None:
            if time.time()-start_t>=30:
                logging.error('**warning** buy late 30 sec')
                return False,None

        return self.api.buy_successful,self.api.buy_id

to this =>

    def buy(self, price, ACTIVES, ACTION, expirations):
        self.api.buy_successful = None
        self.api.buy_id = None
        self.api.buy(price, OP_code.ACTIVES[ACTIVES], ACTION, expirations,1)
        start_t=time.time()
        while self.api.buy_successful == None and self.api.buy_id == None:
            if time.time()-start_t>=30:
                logging.error('**warning** buy late 30 sec')
                return False,None

        return self.api.buy_successful,self.api.buy_id

on buyv3.py from this =>

    def __call__(self, price, active, direction, duration,request_id):

        # thank Darth-Carrotpie's code
        # https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/6
        exp,idx=get_expiration_time(int(self.api.timesync.server_timestamp),duration)  
        if idx<=5:
            option = 3#"turbo"
        else:
             option = 1#"binary"
        data = {
            "body": {"price": price,
                     "active_id": active,
                     "expired": int(exp),
                     "direction": direction.lower(),
                    "option_type_id":option,
                     },
            "name": "binary-options.open-option",
            "version": "1.0"
        }
        self.send_websocket_request(self.name, data,str(request_id))

to this =>

   def __call__(self, price, active, direction, duration,request_id):

        # thank Darth-Carrotpie's code
        # https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/6
        exp,idx=get_expiration_time(int(self.api.timesync.server_timestamp),duration)  
        if idx<=5:
            option = 3#"turbo"
        else:
            option = 1#"binary"

        data = {
            "body": {
                    "user_balance_id":int(self.api.profile.balance_id),
                    "active_id": active,
                    "option_type_id":option,

                    "direction": direction.lower(),
                    "expired": int(exp),
                    "price": price
                    },
            "name": "binary-options.open-option",
            "version": "1.0"
        }

        self.send_websocket_request(self.name, data,str(request_id))
pankakj8710 commented 1 year ago

Hi @dougrn I tried the fixed version you provided but I'm still not able to buy Forex-Margin. I think we need to update buy_place_order_temp.py file to reflect changed parameters.

{
        "category": "button_pressed",
        "name": "traderoom_deal-call",
        "uuid": "XXXXX",
        "active_session_uuid": "XXXXX",
        "connection_hash": "XXXXXX",
        "value": 102.40900000000004,
        "user_id": 123456789,
        "group_id": 123,
        "platform_id": 9,
        "app_version": "2697.4.4127.release",
        "device_id": "XXXXXXXXXXXXX",
        "sync_time": 1669030014686,
        "client_time": 1669030014278,
        "parameters": {
            "asset_id": "1",
            "balance_type": "4",
            "instrument_type": "marginal-forex",
            "leverage_value": "500",
            "margin": "102.40900000000003",
            "market_price": "1.02407",
            "order_type": "market",
            "pip_value": "5.000000000000002",
            "quantity": "0.5",
            "single-click": "1"
        }
    },

But I don't know from where to get uuid, active_session_uuid, connection_hash, and device_id. And is there any way to get margin, pip_value or would i have to calculate that on my own?

AchrafBella commented 4 months ago

Guys, I did it!!!!

I fix the buy error. I had to change a few codes at three files (client.py, stable_api.py and buyv3.py)

iqoptionapi-5.3.zip

I installed your file but i got this error image

AchrafBella commented 4 months ago

Hi @dougrn I tried the fixed version you provided but I'm still not able to buy Forex-Margin. I think we need to update buy_place_order_temp.py file to reflect changed parameters.

{
        "category": "button_pressed",
        "name": "traderoom_deal-call",
        "uuid": "XXXXX",
        "active_session_uuid": "XXXXX",
        "connection_hash": "XXXXXX",
        "value": 102.40900000000004,
        "user_id": 123456789,
        "group_id": 123,
        "platform_id": 9,
        "app_version": "2697.4.4127.release",
        "device_id": "XXXXXXXXXXXXX",
        "sync_time": 1669030014686,
        "client_time": 1669030014278,
        "parameters": {
            "asset_id": "1",
            "balance_type": "4",
            "instrument_type": "marginal-forex",
            "leverage_value": "500",
            "margin": "102.40900000000003",
            "market_price": "1.02407",
            "order_type": "market",
            "pip_value": "5.000000000000002",
            "quantity": "0.5",
            "single-click": "1"
        }
    },

But I don't know from where to get uuid, active_session_uuid, connection_hash, and device_id. And is there any way to get margin, pip_value or would i have to calculate that on my own?

How did you manage to make it works ?

jrfrago21 commented 2 months ago

If you get this error, you may think that it is a failed order but the API places the order multiple times. You can't track the orders it places as it returns an empty reference number.

jrfrago21 commented 2 months ago

@dougrn I made these changes to the API. Insanity, it places the trade after 592 seconds., image