iqoptionapi icon indicating copy to clipboard operation
iqoptionapi copied to clipboard

Problem with buy

Open raffvyr787iuf opened this issue 7 years ago • 1 comments

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", "[email protected]", "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?

raffvyr787iuf avatar May 28 '18 14:05 raffvyr787iuf

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?

lreiner avatar Jun 08 '18 16:06 lreiner