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
120 stars 545 forks source link

How to use them #2

Open Marc1993Idel opened 8 years ago

Marc1993Idel commented 8 years ago

Hey, can you leave a short comment how to use this API? I want to add them to my EA. Thanks

n1nj4z33 commented 8 years ago

Added a little comment to a README.md

engelkohle commented 8 years ago

Hi, after run the api the websocket returns the following json message:

{'msg': {'code': 4, 'isSuccessful': False, 'message': ['Time for purchasing options is over, please try again later.'], 'result': {'request_id': None}}, 'name': 'buyComplete'} {'msg': 1471594551119, 'name': 'timeSync'}

Have you the same problem?

n1nj4z33 commented 8 years ago

hi try to buy on 0 seconds by server time something like

if api.timesync.servertime.seconds == 0: api.buy(args)

joebrassi commented 8 years ago

@n1nj4z33 And what value goes in args?

This project needs documentation.

Could you publish a sample of how to use this API?

n1nj4z33 commented 8 years ago

@joebrassi Hi, i add sphinx generated documentation http://iqapi.readthedocs.io/en/latest/ I'll add a user guide to wiki soon

joebrassi commented 8 years ago

@n1nj4z33 Yes, but that documentation does not say anything about the parameters accepted by the method buy, it only mentions it. Could you just publish a sample?

n1nj4z33 commented 8 years ago

@joebrassi api.buy(price, active, option, direction) api.buy(10, 76, "turbo", "call")

n1nj4z33 commented 8 years ago

@joebrassi also you can see here https://github.com/n1nj4z33/iqpy

joebrassi commented 8 years ago

@n1nj4z33 Thank you very much. And a couple more questions,

  1. Is there any way to retrieve the current price from the API?
  2. I see you assign 76 to the parameter "active", what does 76 actually mean?
n1nj4z33 commented 8 years ago

@joebrassi 1) No way yet. You just send your price to buy 2) https://github.com/n1nj4z33/iqapi/blob/master/iqapi/constants.py

joebrassi commented 8 years ago
  1. OK.
  2. Are those the only constants you have? How should I get the number of other symbols?
n1nj4z33 commented 8 years ago

@joebrassi Im get it from chrome devtools in websocket tab just choose another active ad check

http://i.stack.imgur.com/OIbxT.png

joebrassi commented 8 years ago

I see. Well, it seems that it needs to be completed then.

n1nj4z33 commented 8 years ago

@joebrassi of course it was )

n1nj4z33 commented 8 years ago

@joebrassi and you can help by doing a pull requests )

joebrassi commented 8 years ago

OK, let me see what I can do.

n1nj4z33 commented 8 years ago

@joebrassi @engelkohle @Marc1993Idel you can find some information in wiki now https://github.com/n1nj4z33/iqoptionapi/wiki.

fsnlarson commented 8 years ago

{'msg': {'code': 4, 'isSuccessful': False, 'message': ['Time for purchasing options is over, please try again later.'], 'result': {'request_id': None}}, 'name': 'buyComplete'} {'msg': 1471594551119, 'name': 'timeSync'}

@engelkohle Have you found a away around this?

fsnlarson commented 8 years ago

@engelkohle @n1nj4z33

May have solved...

{'msg': {'code': 4, 'isSuccessful': False, 'message': ['Time for purchasing options is over, please try again later.'], 'result': {'request_id': None}}, 'name': 'buyComplete'} {'msg': 1471594551119, 'name': 'timeSync'}

This ^^ Is the result of expiration times. When rounding all turbo expirations to up to nearest minute, and binaries up to the nearest 15 minutes, it works.

Using datetime:

        def round_up(tm, nearest=15):
            upmins = math.ceil(float(tm.minute)/nearest)*nearest
            diffmins = upmins - tm.minute
            newtime = tm + datetime.timedelta(minutes=diffmins)
            newtime = newtime.replace(second=0)
            return newtime
n1nj4z33 commented 8 years ago

https://github.com/n1nj4z33/iqoptionapi/blob/master/iqoptionapi/ws/objects/timesync.py

@property
def expiration_timestamp(self):
    """Property to get expiration timestamp.
    :returns: The expiration timestamp.
    """
    return time.mktime(self.expiration_datetime.timetuple())

https://github.com/n1nj4z33/iqoptionapi/blob/master/iqoptionapi/ws/chanels/buyv2.py

so you can try to set expiration time before buy

self.api.timesync.expiration_time = 1

engelkohle commented 7 years ago

Are we all agree that these workarounds are used to resolve the trouble about the time to buy, that is possible to do only when the time is zero zero seconds? Or it is possible to buy a position in every time using one of workarounds described before? Have implemented a method that wait until the time is to zero zero seconds and then return true.

joebrassi commented 7 years ago

How do you set the volume in a call to:

api.buy(price, active, option, direction)
api.buy(10, 76, "turbo", "call")
n1nj4z33 commented 7 years ago

volume? what does it mean "volume"?

joebrassi commented 7 years ago

Also called "Trading Size" or "Amount".

RickyGlobal9 commented 7 years ago

Hi, i want to develop iqoption autotrade bot for my own strategy but i am not a Python programmer and the api script is in the same lang.

Is here anyone who can convert these scripts to .net C#. I'll helpful to him for this kind job.

Regards

engelkohle commented 7 years ago

Sorry @n1nj4z33, but your suggest:

self.api.timesync.expiration_time = 1

not work absolutely. At the moment I'm using a function waiting that the seconds are zero, like this:

 def zero_zero_seconds(self):
   logger = logging.getLogger(__name__)
   logger.info("Wait for zero zero seconds.")
   while not self.timesync.server_datetime.second == 0:
       time.sleep(1)
   return True
j1and1 commented 7 years ago

Hi, did you manage to figure out how to resolve the issue with expiration times? I'm kinda stuck at this...

engelkohle commented 7 years ago

Hi @j1and1, In /iqoptionapi/ws/objects/timesync.py replace the content of expiration_timestamp() method with the following code:

return time.mktime(self.expiration_datetime.replace(second=0, microsecond=0).timetuple())

It should appear:

@property
def expiration_timestamp(self):
"""
   Property to get expiration timestamp.

   :returns: The expiration timestamp.
"""

# return time.mktime(self.expiration_datetime.timetuple())
  return time.mktime(self.expiration_datetime.replace(second=0, microsecond=0).timetuple())

I'm sure this will help you.

j1and1 commented 7 years ago

Hey @engelkohle thanks that solved the issue with expiration times!

jglydes commented 7 years ago

hi, how can i retrieve profile data? i would like to get the users balance

j1and1 commented 7 years ago

hi @jglydes ,

If I am correct.... After you have created a connection with the api you can use api.profile.balance to get the balance....

mitch71 commented 7 years ago

Hi, I have been trying to access candle information but it comes back empty using candles= api.getcandles (1,1)

jglydes commented 7 years ago

hi @j1and1 ,

thank you for your response. i just followed the steps on wiki and api.profile.balance returns None. however i managed to get the balance by doing this profile = api.getprofile() res = json.loads(profile._content) balance = res['result']['balance'])

Do you have any idea how can i retrieve the result of buy method? if the trade wins or lose. thanks

Olascoaga commented 7 years ago

@mitch71

Hi, i thinks that i solved the problem, try with this:

api.getcandles(1,1)
candles = api.candles.candles_data 
print candles[-1] # current candle
j1and1 commented 7 years ago

@jglydes

Do you have any idea how can i retrieve the result of buy method? if the trade wins or lose. thanks

I'm wondering the same thing....... And I havent investigated it, but for now I have not found method to get reecent deals...... witch would be usefull for buget controll......

Niks005 commented 7 years ago

how to get current % of return of an active?

frxncisjoseph commented 7 years ago

This is still a huge problem at large dispute the efforts of fixing it by @engelkohle, sadly.

crypto-maniac commented 7 years ago

any update on this guy ? thx you

frxncisjoseph commented 7 years ago

@Niks005 There is a way, do you still need it? I can add a issue with a tutorial/code to do it.

frxncisjoseph commented 7 years ago

@j1and1 Check out https://github.com/n1nj4z33/iqoptionapi/issues/17, this gives you open position information in real time and the trade result.

j1and1 commented 7 years ago

@frxncisjoseph Thanks!!!

crypto-maniac commented 7 years ago

for fix the problem (our csharp line)

expirationtimestamp -= expirationtimestamp % 60;

the server only accept EXACT 60 sec match

Niks005 commented 7 years ago

@frxncisjoseph I had got it working. Using http request "all". Thanks.

conuxconux commented 6 years ago

Hi.

I'm not using the python api, I'm writing a little application in c#. I'm able to send the message to setActives with:

{"msg" : {"actives" : 1}, "name" : "setActives"}

and it works fine.

Can you tell me what is the right message to send at websocket to buy an option with buyV2 message in binary mode?

I have tested the following, but any parameters I thing that are wrong, beacuse I don't know any sample to compose it:

{"msg" : {"price" : 1.17779}, "act" : 1, "exp" : 1507636800000 , "type" : 3, "direction" : "put", "time" : 1507636658690, "name" : "buyV2"}

I receive the following response:

{"msg":{"code":26,"codeList":[26],"isSuccessful":false,"message":["Failed to process"],"result":{"request_id":null}},"name":"buyComplete"}

I suppose the they are the right parameter because I have seen in the "buyv2.py" file, but i don't know the right value for field: type, direction.

The "act" i suppose is right and it is the same of "actives" that I have used in "setActives", right?

Where I can find messages that iqoption support, exist any documentation?

What are the right message to send to by an option?

Please can you help me?

Many thanks to all

HubSpace2000 commented 6 years ago

just download the iqoption mobile application (apk) and you can see all the code source, since 4 month i didnt worked on the iqoption api so i dont remember the flow

conuxconux commented 6 years ago

just download the iqoption mobile application (apk) and you can see all the code source, since 4 month i didnt worked on the iqoption api so i dont remember the flow

@HubSpace2000 many thanks for your reply and suggestion.

I have downloaded the apk but I don't see anything about it... I have searched: buyv2, buy, msg but I haven't found anything ... :(

Have you any suggestion?

HubSpace2000 commented 6 years ago

give me your skype

oravix commented 6 years ago

Hi to every body...Is there someone who has been able to send request_id parameter to the buyv2 method and get It into buyComplete response? If Yes..how? Thx very much

oravix commented 6 years ago

@HubSpace2000 Hi HubSpace2000, could I receive source code to understand how to complete buyV2 with other parameters? (my skype is the same as github username) Thank you