Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buy id #52

Closed
mymggithub opened this issue Nov 13, 2018 · 22 comments
Closed

buy id #52

mymggithub opened this issue Nov 13, 2018 · 22 comments

Comments

@mymggithub
Copy link

mymggithub commented Nov 13, 2018

Hi @Lu-Yi-Hsun,
Sorry to bug but am I doing it wrong to get the id when I buy a binary option.

print("login...")
I_want_money=IQ_Option("email","password")

ACTIVES="EURUSD"
ACTION="put"
expirations_mode=1
force_buy= False
cost=1
optionID = 0

optionID = I_want_money.buy(cost,ACTIVES,ACTION,expirations_mode,force_buy)
time.sleep(5)
print(optionID)

I want the id to later put and infinite loop to check if the option is a won or loss.
The thing is, the buy option executes just fine, but when hard coded it returns None to the variable and if done manually in shell it returns the id.
I looked through the other issues and did not find an answer.
I did find #14
what ever happened to "ok"?
ok,id_number=I_want_money.buy(2,"EURUSD","call",1,force_buy=False)
It seamed like a great idea.

Thanks in advanced.

@Lu-Yi-Hsun
Copy link
Owner

@mymggithub
if you buy fail get None
success get id

@mymggithub
Copy link
Author

I understand that, but it is not failing.
image

I see the option go through on iqoption while I run my code, but I get None.
After further investigation I find it seams to happen to the first time the function is called.
image

@JafferWilson
Copy link

Can you share your code with us,please? The python file which you are trying to execute the API with.

@mymggithub
Copy link
Author

mymggithub commented Nov 14, 2018

I grew frustrated and stated from scratch, it reproduces the results of only buying an option displaying the ID.

image

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import random
import time
import json
from iqoptionapi.stable_api import IQ_Option
from datetime import datetime

email = ""
password = ""

print("login...")
I_want_money=IQ_Option(email, password)
I_want_money.change_balance("PRACTICE")



ACTIVES="EURUSD"
ACTION="put"
expirations_mode=1
force_buy= False
cost=1
optionID = 0


while True:
    print("")
    print("Buying option...")
    print("Cost: ${}".format(cost))
    optionID = I_want_money.buy(cost,ACTIVES,ACTION,expirations_mode,force_buy)
    time.sleep(5)
    print(ACTIVES+" - History")
    print("--------------------------------")
    print("Option ID: {}".format(optionID))
    time.sleep(65)

test.zip

@Lu-Yi-Hsun
Copy link
Owner

Lu-Yi-Hsun commented Nov 15, 2018

give me log file

@JafferWilson
Copy link

I grew frustrated and stated from scratch, it reproduces the results of only buying an option displaying the ID.

image

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import random
import time
import json
from iqoptionapi.stable_api import IQ_Option
from datetime import datetime

email = ""
password = ""

print("login...")
I_want_money=IQ_Option(email, password)
I_want_money.change_balance("PRACTICE")



ACTIVES="EURUSD"
ACTION="put"
expirations_mode=1
force_buy= False
cost=1
optionID = 0


while True:
    print("")
    print("Buying option...")
    print("Cost: ${}".format(cost))
    optionID = I_want_money.buy(cost,ACTIVES,ACTION,expirations_mode,force_buy)
    time.sleep(5)
    print(ACTIVES+" - History")
    print("--------------------------------")
    print("Option ID: {}".format(optionID))
    time.sleep(65)

test.zip

Try force_buy= True. Secondly, what you mean by only buying an option displaying the ID.
Have a look at the script and the image that I have created.
test
The script is:
test.zip

Hope this will help.

@mymggithub
Copy link
Author

mymggithub commented Nov 15, 2018

It turned out to be a problem with python 2.7.
My bad.

What I was doing for a very bad quick fix was got the ID from open_options.
I would not recommend it.

d=I_want_money.get_optioninfo(10)
for open_options in d["msg"]["result"]["open_options"]:
    if open_options["active"] == ACTIVES:
    optionID = open_options["id"]

@JafferWilson do you still want to communicate?
Do you have a discord?

@Lu-Yi-Hsun
Copy link
Owner

So you get the problem in python2.7?
I will check that bug

@JafferWilson
Copy link

@mymggithub No I do not have any discord. I tried to help. Delighted to know it was Python version issues.

@mymggithub
Copy link
Author

@mymggithub No I do not have any discord. I tried to help. Delighted to know it was Python version issues.

Thanks @JafferWilson I always appreciate the help, if it wasnt for you I wouldnt have thought it would be the python version.

@Lu-Yi-Hsun
Copy link
Owner

Lu-Yi-Hsun commented Nov 17, 2018

@mymggithub
i have been test on python2

you get the None ID because the "purchase time" is zero,so you "buy fail" and you get None ID

i think not python2 problem

Uploading 2018-11-17 23-03-22 的螢幕擷圖.png…

import random
import time
import json
from iqoptionapi.stable_api import IQ_Option
from datetime import datetime
print("login...")
I_want_money = IQ_Option("email", "password")
I_want_money.change_balance("PRACTICE")
ACTIVES="EURUSD-OTC"
ACTION="put"
expirations_mode=1
force_buy= False
cost=1
optionID = 0
while True:
    print("")
    print("Buying option...")
    print("Cost: ${}".format(cost))
    optionID = I_want_money.buy(cost,ACTIVES,ACTION,expirations_mode,force_buy)
    time.sleep(0)
    print(ACTIVES+" - History")
    print("--------------------------------")
    print("Option ID: {}".format(optionID))
    time.sleep(0)
    cost=cost+0.01
    if optionID==None:
        break

@mymggithub
Copy link
Author

I dont know that does not look like it had a "buy fail" to me.

image

@Lu-Yi-Hsun
Copy link
Owner

Lu-Yi-Hsun commented Nov 18, 2018

@mymggithub
i test python2.7 on window 10
still can not find your problem

please give """log file"",so i can know what happen

@mymggithub
Copy link
Author

Yea, this is unbelievable.
Once I started logging using #54, tnx btw, the problem of the id being none at the beginning disappeared.
But if I take away logging it easily comes back.

@Lu-Yi-Hsun
Copy link
Owner

just print log, can get that bug?

@mymggithub
Copy link
Author

There would be no log to print, as the bug does not appear during that time.
I am sending a video to show what is going on.
Yes I know if there was a log it would be in logging.txt
py.zip

@Lu-Yi-Hsun
Copy link
Owner

Lu-Yi-Hsun commented Nov 18, 2018

I Reproduct that bug.. i will try find bug!

@mymggithub
Copy link
Author

i think "try: exception:" can be problem

I am using the code from the reply, also there is no

try:
    #code
except Exception as e:
    raise e

@mymggithub
i have been test on python2

you get the None ID because the "purchase time" is zero,so you "buy fail" and you get None ID

i think not python2 problem

Uploading 2018-11-17 23-03-22 的螢幕擷圖.png…

import random
import time
import json
from iqoptionapi.stable_api import IQ_Option
from datetime import datetime
print("login...")
I_want_money = IQ_Option("email", "password")
I_want_money.change_balance("PRACTICE")
ACTIVES="EURUSD-OTC"
ACTION="put"
expirations_mode=1
force_buy= False
cost=1
optionID = 0
while True:
    print("")
    print("Buying option...")
    print("Cost: ${}".format(cost))
    optionID = I_want_money.buy(cost,ACTIVES,ACTION,expirations_mode,force_buy)
    time.sleep(0)
    print(ACTIVES+" - History")
    print("--------------------------------")
    print("Option ID: {}".format(optionID))
    time.sleep(0)
    cost=cost+0.01
    if optionID==None:
        break

Or am I miss understanding?

I just added a try and still nothing.

@mymggithub
Copy link
Author

print on terminel?

import logging
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')

The video shows that the bug only shows when there is no.
logging.basicConfig

That applies to
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
and
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s',filename='logging.txt',filemode='w')

@mymggithub
Copy link
Author

I dont know, its not a big deal.
If logging get rid of the bug, I am happy.

logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s',filename='logging.txt',filemode='w')

@Lu-Yi-Hsun
Copy link
Owner

Lu-Yi-Hsun commented Nov 18, 2018

@mymggithub
try last version
i find how to fix that!

@mymggithub
Copy link
Author

@Lu-Yi-Hsun
Awesome it works!
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants