Lu-Yi-Hsun / iqoptionapi

IQ Option API
372 stars 288 forks source link

How can i get multi option candles? #16

Open btphucvn opened 6 years ago

btphucvn commented 6 years ago

Hello ALL, I want to get candles of EURUSD and USDTRY. But I only recived candles data of EURUSD. this is my code:

from iqoptionapi.stable_api import IQ_Option
import os
import time
I_want_money=IQ_Option("email","pass")

goal="EURUSD"
print("get candles")
print(I_want_money.get_candles(goal,60,111,time.time()))

goal="USDTRY"
print("get candles")
print(I_want_money.get_candles(goal,60,111,time.time()))

Thank you for your help!!!

Lu-Yi-Hsun commented 6 years ago

@btphucvn

thank report it i am fix, now you can get right data

i thing get_candles() not thread safe ,that use the same variable,

but you can try this code to get multi candles, this way is more better than get_candles(), because get_candles() late about 30 sec

from iqoptionapi.stable_api import IQ_Option
import logging
import time
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
I_want_money=IQ_Option("email","password")

I_want_money.start_candles_stream("EURUSD")
thread=I_want_money.collect_realtime_candles_thread_start("EURUSD",100)

I_want_money.start_candles_stream("USDTRY")
thread2=I_want_money.collect_realtime_candles_thread_start("USDTRY",100)

time.sleep(3)
#Do some thing
ans=I_want_money.thread_collect_realtime.items()

for k, v in ans:
    print (k, v)

I_want_money.collect_realtime_candles_thread_stop(thread)
I_want_money.stop_candles_stream("EURUSD")

I_want_money.collect_realtime_candles_thread_stop(thread2)
I_want_money.stop_candles_stream("USDTRY")
hcalitz commented 6 years ago

Hi Anson

Thanks for a great code. I encountered a strange result when executing the code as you give it above. The fields returned for different keys are all the same!

Update I just removed part of my post above. The code produce the expected results this morning. I assume a server problem maybe ?? :)

So far, I am getting non duplicated values. :)

mymggithub commented 5 years ago

What would be the update of that code? Because start_candles_stream would need three parameters goal,, size, and maxdict. I think collect_realtime_candles_thread_start was replaced by get_realtime_candles also thread_collect_realtime dosnt exist anymore.

@btphucvn

thank report it i am fix, now you can get right data

i thing get_candles() not thread safe ,that use the same variable,

but you can try this code to get multi candles, this way is more better than get_candles(), because get_candles() late about 30 sec

from iqoptionapi.stable_api import IQ_Option
import logging
import time
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
I_want_money=IQ_Option("email","password")

I_want_money.start_candles_stream("EURUSD")
thread=I_want_money.collect_realtime_candles_thread_start("EURUSD",100)

I_want_money.start_candles_stream("USDTRY")
thread2=I_want_money.collect_realtime_candles_thread_start("USDTRY",100)

time.sleep(3)
#Do some thing
ans=I_want_money.thread_collect_realtime.items()

for k, v in ans:
    print (k, v)

I_want_money.collect_realtime_candles_thread_stop(thread)
I_want_money.stop_candles_stream("EURUSD")

I_want_money.collect_realtime_candles_thread_stop(thread2)
I_want_money.stop_candles_stream("USDTRY")
jackynguyen93 commented 4 years ago

@Lu-Yi-Hsun is function collect_realtime_candles_thread_start still work ?