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 542 forks source link

Buy position does not work any more? #55

Open EVAZA opened 6 years ago

EVAZA commented 6 years ago

IQ Option seems changed their API. The current code does not work any more... Have anyone a solution?

kanXuT commented 6 years ago

They added (or req. now) another params in buyV2: skey - is stored in profile user_balance_id - not sure if it's required but I added that and works fine

milteven12 commented 6 years ago

Hello @kanXuT , please, could you explain what should I do? My current code is: captura eurusd

PS: How can I get the skey and user_balance_id? I tried print (api.profile.skey) but the output is None.

kanXuT commented 6 years ago

Sorry not using this api and not famiiar with Python, so this is just where you can look for: you need update buyv2.py ad add something like this:

data = {"price": price, "act": active, "exp": self.api.timesync.expiration_timestamp, "type": option, "direction": direction, "time": self.api.timesync.server_timestamp, "skey": self.api.profile.skey, "user_balance_id": self.api.profile.balance_id }

And if skey and balance_id is not set/deffined, you need fill them up first from profile message ;)

iQBotProject commented 6 years ago

what we should to do exactly

iQBotProject commented 6 years ago

@kanXuT i try a version of api have skey and balance difined and the property in profil and i add self.__balance_id = None

profile.py


from iqoptionapi.ws.objects.base import Base

class Profile(Base):
    """Class for IQ Option Profile websocket object."""

    def __init__(self):
        super(Profile, self).__init__()
        self.__name = "profile"
        self.__skey = None
        self.__balance = None
        self.__balance_id = None

    @property
    def skey(self):
        """Property to get skey value.

        :returns: The skey value.
        """
        return self.__skey

    @skey.setter
    def skey(self, skey):
        """Method to set skey value."""
        self.__skey = skey

    @property
    def balance(self):
        """Property to get balance value.

        :returns: The balance value.
        """
        return self.__balance

    @balance.setter
    def balance(self, balance):
        """Method to set balance value."""
        self.__balance = balance

    @property
    def balance_id(self):
        """Property to get balance_id value.

        :returns: The balance_id value.
        """
        return self.__balance_id

    @balance_id.setter
    def balance_id(self, balance):
        """Method to set balance_id value."""
        self.__balance_id = balance_id

buyV2.py


from iqoptionapi.ws.chanels.base import Base

class Buyv2(Base):
    """Class for IQ option buy websocket chanel."""
    # pylint: disable=too-few-public-methods

    name = "buyV2"

    def __call__(self, price, active, option, direction):
        """Method to send message to buyv2 websocket chanel.

        :param price: The buying price.
        :param active: The buying active.
        :param option: The buying option.
        :param direction: The buying direction.
        """
        data = {"price": price,
                "act": active,
                "exp": self.api.timesync.expiration_timestamp,
                "type": option,
                "direction": direction,
                "time": self.api.timesync.server_timestamp, 
                "skey": self.api.profile.skey, 
                "user_balance_id": self.api.profile.balance_id
               }

        self.send_websocket_request(self.name, data)

always buy not happened i think skey and balance_id is always None

milteven12 commented 6 years ago

@yesamine , just a comment: I have the same version, you don't need to modify the call function to: def call(self, price, active, option, direction,skey,user_balance_id) ?

The thing is, skey and user_balance_id aren't 'None', if you see the log when it connect to the server you will se the values there but I don't know how to retrieve it.

iQBotProject commented 6 years ago

now i tested the iqoptionbot in TEST mode work good and trade and i see skey and balance_id in loge file the probleme this robot not working with other methods like TBL , TBH , ... and have many issues (candles and market ... )

but buy (call , put) work fin thats mean i miss somthing in my simple buy code

import time
from iqoptionapi.api import IQOptionAPI

api = IQOptionAPI("iqoption.com", "myemail@example.com", "mypass")

api.connect()
time.sleep(1)

balance = api.profile.balance
time.sleep(1)
print (balance)

api.setactives([1, 2])
time.sleep(1)

api.subscribe('tradersPulse')
reslt = api.buy(1, 1, "turbo", "call")
time.sleep(2)
print reslt