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

Problem with buy #95

Open raffvyr787iuf opened 6 years ago

raffvyr787iuf commented 6 years ago

During starting below code:

from iqoptionapi.api import IQOptionAPI
import datetime
import time
import logging
logging.basicConfig(format='%(asctime)s %(message)s')

api = IQOptionAPI("iqoption.com", "my.private@mail.address", "s3cr3tPassw0rd")

api.connect()
time.sleep(0.5)
print 'Your current balance is: {:.2f}'.format(api.profile.balance)

if api.timesync.server_datetime.second != 48:
    api.buy(1, 1, "turbo", "call")
time.sleep(0.5)

print 'Your current balance is: {:.2f}'.format(api.profile.balance)

I've got these results:

Your current balance is: 10.00
2018-05-28 16:37:08,377 {"msg": {"direction": "call", "price": 1, "act": 1, "exp": 1527518280.0, "time": 1527518227, "type": "turbo"}, "name": "buyV2"}

2018-05-28 16:37:08,421 {"name":"buyComplete","request_id":"","msg":{"isSuccessful":false,"message":["Invalid request"],"result":{}}}

2018-05-28 16:37:08,828 {"name":"timeSync","msg":1527518228903}
Your current balance is: 10.00

Can you help me with configuration? What I did wrong?

lreiner commented 6 years ago

You have the same Problem as me. Its because there is a ".0" in your "exp" in your request.

I also changed this line in the buyv2.py: exp = self.api.timesync.expiration_timestamp to this: exp = int(self.api.timesync.expiration_timestamp)

So now it looks like this:

import datetime

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.
        """
        exp = int(self.api.timesync.expiration_timestamp)
        #Round to next full minute
        if datetime.datetime.now().second > 30:
            exp = exp - (exp % 60) + 60
        else:
            exp = exp - (exp % 60)

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

        self.send_websocket_request(self.name, data)

The int() normally deletes the .0 in numbers. But somehow in my request there ist still a ".0" Anyone a Solution for this?