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

Digital options buy with actual price #65

Open
mattia177 opened this issue Dec 24, 2018 · 64 comments
Open

Digital options buy with actual price #65

mattia177 opened this issue Dec 24, 2018 · 64 comments
Labels
imp. have been implement at last version

Comments

@mattia177
Copy link

Hi my friend,

Could you please tell me (and write) a code where I can buy a digital option (for example EURUSD digital) where as buy price I have the actual price?

Now on IQ Option you can buy digitals both setting a specific price or with the actual price (with a fixed payout associated). I would be interested into this second way. Could you help me?

Thanks!

@Lu-Yi-Hsun
Copy link
Owner

@mattia177 sorry i don't understand.

you want to check what price you buy?

@mattia177
Copy link
Author

@Lu-Yi-Hsun I want to buy a digital option, not setting a specific strike price but buying it at the spot price (closest price). Is it possibile?

@Mecabot
Copy link

Mecabot commented Dec 27, 2018

Hi @mattia177 :

The method to buy a digital option require the instrument_id buy_check,id=I_want_money.buy_digital(amount,instrument_id) that require the strike price. If you want to buy an active at the spot price you can try with the binary option because it doesn´t need a strike price.

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","pass")
goal="EURUSD"
print("get candles")
print(I_want_money.get_candles(goal,60,111,time.time()))
Money=1
ACTIVES="EURUSD"
ACTION="call"#or "put"
expirations_mode=1
force_buy= False#i suggest use False
I_want_money.buy(Money,ACTIVES,ACTION,expirations_mode,force_buy)

@mattia177
Copy link
Author

Hi @Mecabot :

I’m not sure you are right. I know that you tipically you have to buy digital options at a specific strike price, but if you check well you will see that you can buy a digital option at the spot price, and the payout is fixed (usually at 87%). It’s an update of the platform che implemented about one month ago. It give you the chance to trade digital options in a similar way to binary options, but you can buy them till 15 seconds to expiry.

Someone can Help me?

@Lu-Yi-Hsun
Copy link
Owner

@mattia177 you want set the price ,like forex limit price?

@mattia177
Copy link
Author

@Lu-Yi-Hsun yes, something like: if [my asset] has a particular condition, then buy the digital options with limit price (strike price) equal to the spot price. It’s like forex limit price, and I want to use it with digitals (I know it’s possible)

@mattia177
Copy link
Author

Any news?

@TileshB
Copy link

TileshB commented Apr 5, 2019

Hi @Lu-Yi-Hsun what @mattia177 means is that he wishes to do a purchase with the percentage ROI that you would get from a regular purchase that is not through using strike prices, in other words making a decision that the price will be higher or lower than it currently is using digital options(Due to the percentage ROI being different from Binary at times). I have attached an image below to help with understanding. I require this solution too, please.

Screen Shot 2019-04-05 at 8 13 28 AM

@Lu-Yi-Hsun
Copy link
Owner

@mattia177
Copy link
Author

Ho @TileshB, exactly, you understood what I mean :)

If someone of you is interested, I developed an algo strategy to play with digital options, and backtested it through Bloomberg terminal. I can write it through Python, I am an engineer, but I do not have a professional account, if you want to join a business with me we could reach a strong result. Have a good day guys...

@Lu-Yi-Hsun
Copy link
Owner

Lu-Yi-Hsun commented Apr 5, 2019

You can get profit percentag.

Sorry I still can not get your point.

You can not set that limit price in digit

You can buy digit by choose what profit you and price

@TileshB
Copy link

TileshB commented Apr 5, 2019

Essentially if you look at the picture attached, what your function does is provide all the strikes in the list but how do we know which one is the white bar. We want to buy a position based on that particular strike. In other words, how do we purchase the position at the current strike position(The strike in the white block). In this example I want to buy digital at the instrument ID that is "1.122700". If that makes sense?
Screen Shot 2019-04-05 at 10 31 10 AM

@mattia177
Copy link
Author

@Lu-Yi-Hsun
Sorry, maybe I didn’t explain well.

Usually when you trade a classic binary option, you have a fixed payout percentage and you can buy it till 30 seconds to expiry.

If you want to buy an option till 15seconds to expiry you have to buy a digital option, where you have to specify the strike price you want to execute the option. If you move far from the spot price the payout percentage will be slower, right?

But you have a second way: buying a digital option without specifying the strike price, because you buy that option at the spot price.

IQ Options tells you: Eur/Usd is @1.1213? If you don’t want to buy a digital option with strike price higher or lower, you can buy a digital option with strike price equals to 1.1213, the same level of the spot price.

So, I would be interested to know how I could do this with python. I mean, how can I do a similar buy trade?

@hesller
Copy link

hesller commented Apr 5, 2019

I think what is trying to say is:
how to get the current price in digital options like in pic below

1 - First go to settings
settings 1

2 - Select the option "Current Price"
settings 2

This way it`s possible to open digital orders in the current price instead of orders to hit strike prices.
Btw, I dont think this API offers this option yet

@mattia177
Copy link
Author

mattia177 commented Apr 5, 2019 via email

@Lu-Yi-Hsun
Copy link
Owner

Lu-Yi-Hsun commented Apr 6, 2019

#65 (comment)
use real-time candle you can get white bar

@kmnaseef
Copy link

Any solution for this issue?

@mattia177
Copy link
Author

@Lu-Yi-Hsun any news? Could you provide as a code to buy Digital Options with ACTUAL PRICE?

@Lu-Yi-Hsun
Copy link
Owner

I haven’t implement yet

@mattia177
Copy link
Author

@Lu-Yi-Hsun I understand, do you think it will be long time for developing? Thank you

@Lu-Yi-Hsun
Copy link
Owner

I think it is very easy , I will add it

@mattia177
Copy link
Author

mattia177 commented Jul 10, 2019 via email

@mattia177
Copy link
Author

mattia177 commented Jul 15, 2019 via email

@Lu-Yi-Hsun
Copy link
Owner

Lu-Yi-Hsun commented Jul 16, 2019

Nothing my friend? Il giorno mer 10 lug 2019 alle ore 17:50 ardemagni mattia < ardemagni.mattia@gmail.com> ha scritto:

Thank you, really appreciate it! Il giorno mer 10 lug 2019 alle 15:45 Anson @.***> ha scritto: > I think it is very easy , I will add it > > — > You are receiving this because you were mentioned. > Reply to this email directly, view it on GitHub > <#65?email_source=notifications&email_token=AKGLQ5EPFA4XJUKFNEUCHWTP6XRWFA5CNFSM4GMBMHCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZTQEPY#issuecomment-510067263>, > or mute the thread > https://github.com/notifications/unsubscribe-auth/AKGLQ5DUWG4F32IQJH5PV7DP6XRWFANCNFSM4GMBMHCA > . >

this code can buy the price near current price!

from iqoptionapi.stable_api import IQ_Option
import time
import random

I_want_money=IQ_Option("email","pasword")

goal="EURUSD"
size=1#size=[1,5,10,15,30,60,120,300,600,900,1800,3600,7200,14400,28800,43200,86400,604800,2592000,"all"]
maxdict=1
print("start stream...")
I_want_money.start_candles_stream(goal,size,maxdict)
 
print("print candles")
candle=I_want_money.get_realtime_candles(goal,size)
key=list(candle)[0]
current_price=candle[key]["close"]
print("current_price",current_price)
 
######
 
 
duration=1#minute 1 or 5
amount=1
buy="call"#or "put"
I_want_money.subscribe_strike_list(goal)
#get strike_list
data=I_want_money.get_realtime_strike_list(goal, duration)
 
#get price list
price_list=list(data.keys())
 
close_current_price=[]
for p_list in price_list:
    close_current_price.append(abs(current_price-float(p_list)))

most_close_price=price_list[close_current_price.index(min(close_current_price))]
print("most_close_price",most_close_price,"current_price",current_price)
print(data[str(most_close_price)])
 
#random choose Strategy
choose_price=most_close_price
#get instrument_id
instrument_id=data[choose_price][buy]["id"]
#get profit
profit=data[choose_price][buy]["profit"]
print("choose you want to buy")
print("price:",choose_price,"side:call","instrument_id:",instrument_id,"profit:",profit)
#put instrument_id to buy
buy_check,id=I_want_money.buy_digital(amount,instrument_id)
if buy_check:
    print("wait for check win")
    #check win
    while True:
        check_close,win_money=I_want_money.check_win_digital(id)
        if check_close:
            if float(win_money)>0:
                win_money=("%.2f" % (win_money))
                print("you win",win_money,"money")
            else:
                print("you loose")
            break
    I_want_money.unsubscribe_strike_list(buy)
else:
    print("fail to buy,please run again,digit is change very fast so sometime if can not buy the price!,please try more time")

@mattia177
Copy link
Author

mattia177 commented Jul 16, 2019 via email

@mattia177
Copy link
Author

mattia177 commented Jul 16, 2019 via email

@Lu-Yi-Hsun
Copy link
Owner

@mattia177
What your api version?
Try update

@mattia177
Copy link
Author

mattia177 commented Jul 16, 2019 via email

@mattia177
Copy link
Author

My friend, I just tried but it's not what I would need yet.

If you see the image I'm actually pasting, you will see that on digital option instrument you can chose between two options:

  1. The nearest strike price (just like the code you sent me yesterday)

  2. The strike price equal to the ACTUAL PRICE.

I would need to buy the option at the actual price, as you can see in the image where the flag is on the right option.

Do you think to be able to solve this issue?

IQ_Digital

@Lu-Yi-Hsun
Copy link
Owner

Lu-Yi-Hsun commented Jul 18, 2019

@mattia177
You just want the api change mode?

The sample code can buy the actual price!

In the low level iqoption buy the Actual price
is working the same as my code.

  1. Iqoption is check the real-time candle

2.buy the actual price near the candle

@mattia177
Copy link
Author

@Lu-Yi-Hsun

As the guys said in the previous messages, I tried to change a little part of your code and I put as "INSTRUMENT ID" = doEURUSD201907242130PT5MCSPT

In this way it works and it buys always at the ACTUAL PRICE.

Now the only thing you could do, if not a problem, is putting it into a function...and the last problem is that in the strike list there are the payouts for all the strikes, but not for the instrument id that finishes with "SPT" --> that means SPOT. How could you do to find that in your opinion?

@mattia177
Copy link
Author

Nothing mi friend?

@Lu-Yi-Hsun
Copy link
Owner

Lu-Yi-Hsun commented Jul 26, 2019

@thiagottjv thank you ,I will check how to implement! And put your name on the code haha

@mattia177
Copy link
Author

@Lu-Yi-Hsun We trust in your ability to develop our request my friend :)

@htnlabs
Copy link

htnlabs commented Aug 11, 2019

Does the code still work? I'm having trouble getting the current price

@Lu-Yi-Hsun
Copy link
Owner

Not working , I am find what happen

@htnlabs
Copy link

htnlabs commented Aug 11, 2019

Not working , I am find what happen

Thanks. You are good!

@valderind4
Copy link

I am waiting for a solution for getting the actual price and a fixed profit as well. Tks for the great work.

@htnlabs
Copy link

htnlabs commented Aug 12, 2019

@Lu-Yi-Hsun

As the guys said in the previous messages, I tried to change a little part of your code and I put as "INSTRUMENT ID" = doEURUSD201907242130PT5MCSPT

In this way it works and it buys always at the ACTUAL PRICE.

Now the only thing you could do, if not a problem, is putting it into a function...and the last problem is that in the strike list there are the payouts for all the strikes, but not for the instrument id that finishes with "SPT" --> that means SPOT. How could you do to find that in your opinion?

Not work?

@Lu-Yi-Hsun
Copy link
Owner

Lu-Yi-Hsun commented Aug 12, 2019

thank@thiagottjv

@mattia177 @valderind4 @htnlabs
fix and implement in the last version

@Lu-Yi-Hsun Lu-Yi-Hsun added the imp. have been implement at last version label Aug 12, 2019
@htnlabs
Copy link

htnlabs commented Aug 13, 2019

Great job

@thiagottjv
Copy link

thank@thiagottjv

Your welcome. Your code helped me a lot understanding how the api works. Thanks for that!

@valderind4
Copy link

thank@thiagottjv

@mattia177 @valderind4 @htnlabs
fix and implement in the last version

Thank You so much for your effort, but I am getting some return of "error" on using buy_digital_spot and when It works I am getting error on check_win_digital as you can see at the picture attached, maybe the problem is that you return digital_option_placed_id in the new code instead return order_id required to use on check_win_digital as before.

Is there another python def to check win for digital spot or I am doing something wrong?

WhatsApp Image 2019-08-12 at 23 59 01(1)

@Lu-Yi-Hsun
Copy link
Owner

@valderind4 thank ,i will check id problem

@valderind4
Copy link

valderind4 commented Aug 13, 2019

@valderind4 thank ,i will check id problem

thanks for your great job again. Below is more specifically the "error" returned when it try buying a digital spot sometimes:

Is It not possible to return the specific error message explaining the reason for not buying at that time?

PS: Please check that buy_order_id is always returning "None".

image

@valderind4
Copy link

Nothing my friend? Il giorno mer 10 lug 2019 alle ore 17:50 ardemagni mattia < ardemagni.mattia@gmail.com> ha scritto:

Thank you, really appreciate it! Il giorno mer 10 lug 2019 alle 15:45 Anson @.***> ha scritto: > I think it is very easy , I will add it > > — > You are receiving this because you were mentioned. > Reply to this email directly, view it on GitHub > <#65?email_source=notifications&email_token=AKGLQ5EPFA4XJUKFNEUCHWTP6XRWFA5CNFSM4GMBMHCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZTQEPY#issuecomment-510067263>, > or mute the thread > https://github.com/notifications/unsubscribe-auth/AKGLQ5DUWG4F32IQJH5PV7DP6XRWFANCNFSM4GMBMHCA > . >

this code can buy the price near current price!

from iqoptionapi.stable_api import IQ_Option
import time
import random

I_want_money=IQ_Option("email","pasword")

goal="EURUSD"
size=1#size=[1,5,10,15,30,60,120,300,600,900,1800,3600,7200,14400,28800,43200,86400,604800,2592000,"all"]
maxdict=1
print("start stream...")
I_want_money.start_candles_stream(goal,size,maxdict)
 
print("print candles")
candle=I_want_money.get_realtime_candles(goal,size)
key=list(candle)[0]
current_price=candle[key]["close"]
print("current_price",current_price)
 
######
 
 
duration=1#minute 1 or 5
amount=1
buy="call"#or "put"
I_want_money.subscribe_strike_list(goal)
#get strike_list
data=I_want_money.get_realtime_strike_list(goal, duration)
 
#get price list
price_list=list(data.keys())
 
close_current_price=[]
for p_list in price_list:
    close_current_price.append(abs(current_price-float(p_list)))

most_close_price=price_list[close_current_price.index(min(close_current_price))]
print("most_close_price",most_close_price,"current_price",current_price)
print(data[str(most_close_price)])
 
#random choose Strategy
choose_price=most_close_price
#get instrument_id
instrument_id=data[choose_price][buy]["id"]
#get profit
profit=data[choose_price][buy]["profit"]
print("choose you want to buy")
print("price:",choose_price,"side:call","instrument_id:",instrument_id,"profit:",profit)
#put instrument_id to buy
buy_check,id=I_want_money.buy_digital(amount,instrument_id)
if buy_check:
    print("wait for check win")
    #check win
    while True:
        check_close,win_money=I_want_money.check_win_digital(id)
        if check_close:
            if float(win_money)>0:
                win_money=("%.2f" % (win_money))
                print("you win",win_money,"money")
            else:
                print("you loose")
            break
    I_want_money.unsubscribe_strike_list(buy)
else:
    print("fail to buy,please run again,digit is change very fast so sometime if can not buy the price!,please try more time")

After the API update yesterday, after 1 hour of execution I am getting this error bellow:

2019-08-13 11:07:21,607 {"request_id":"","name":"position","msg":{"position":{"last_change_reason":"market_order","instrument_id_escape":"doUSDCHF201908131410PT5MP097274","instrument_strike_value":972740,"instrument_type":"digital-option","instrument_id":"doUSDCHF201908131410PT5MP097274","instrument_underlying":"USDCHF","instrument_active_id":72,"instrument_expiration":1565705400000,"instrument_strike":0.97274,"instrument_dir":"put","instrument_period":300,"instrument_percent":null,"id":735301131,"user_id":49006564,"user_balance_id":234839765,"user_balance_type":4,"create_at":1565705102354,"update_at":1565705102354,"close_at":null,"type":"long","leverage":1,"count":0.380512,"count_realized":0.0,"status":"open","buy_amount":19.99998,"sell_amount":0.0,"buy_amount_enrolled":19.99998,"sell_amount_enrolled":0.0,"commission_amount":0.0,"commission":0.0,"commission_enrolled":0.0,"close_effect_amount":null,"close_effect_amount_enrolled":null,"close_reason":null,"close_underlying_price":null,"open_underlying_price":0.97276,"pnl_realized":0.0,"pnl_realized_enrolled":0.0,"buy_avg_price":52.560707,"buy_avg_price_enrolled":52.560707,"sell_avg_price":0.0,"sell_avg_price_enrolled":0.0,"stop_lose_order_id":null,"take_profit_order_id":null,"tpsl_extra":null,"currency":"USD","margin":0.0,"margin_call":0.0,"margin_call_enrolled":0.0,"swap":0.0,"swap_enrolled":0.0,"custodial":0.0,"custodial_enrolled":0.0,"custodial_last_age":0,"user_group_id":184,"charge":0.0,"charge_enrolled":0.0,"orders":[],"currency_unit":1,"currency_rate":1.0,"open_client_platform_id":9,"extra_data":{"amount":20000000,"version":"4.0","init_time":1565705102019,"use_trail_stop":false,"auto_margin_call":false,"last_change_reason":"market_order","use_token_for_commission":false},"order_ids":[1335930181],"last_index":7124327955},"orders":[{"instrument_id_escape":"doUSDCHF201908131410PT5MP097274","basic_stoplimit_amount":20.0,"take_profit_price":null,"stop_lose_price":null,"tpsl_extra":null,"instrument_strike_value":972740,"instrument_type":"digital-option","instrument_id":"doUSDCHF201908131410PT5MP097274","instrument_underlying":"USDCHF","instrument_active_id":72,"instrument_expiration":1565705400000,"instrument_strike":0.97274,"instrument_dir":"put","instrument_period":300,"instrument_percent":null,"id":1335930181,"user_id":49006564,"user_balance_id":234839765,"user_group_id":184,"user_balance_type":4,"position_id":735301131,"create_at":1565705102038,"update_at":1565705102206,"execute_at":1565705102354,"side":"buy","type":"market","status":"filled","execute_status":"trade","count":0.380512,"leverage":1,"underlying_price":0.97276,"avg_price":52.560707,"avg_price_enrolled":52.560707,"client_platform_id":9,"limit_price":0.0,"stop_price":null,"currency":"USD","margin":19.99998,"spread":null,"commission_amount":0.0,"commission_amount_enrolled":0.0,"extra_data":{"amount":20000000,"version":"4.0","init_time":1565705102019,"use_trail_stop":false,"auto_margin_call":false,"paid_for_commission":0,"use_token_for_commission":false,"paid_for_commission_enrolled":0},"time_in_force":"good_till_cancel","time_in_force_date":null,"last_index":3655230481}]},"status":2000}
2019-08-13 11:07:21,614 {"name": "sendMessage", "msg": {"name": "get-order", "body": {"order_id": 1335930181}}, "request_id": ""}
2019-08-13 11:07:21,827 {"request_id":"","name":"order","msg":{"instrument_id_escape":"doUSDCHF201908131410PT5MP097274","basic_stoplimit_amount":20.0,"take_profit_price":null,"stop_lose_price":null,"tpsl_extra":null,"instrument_strike_value":972740,"instrument_type":"digital-option","instrument_id":"doUSDCHF201908131410PT5MP097274","instrument_underlying":"USDCHF","instrument_active_id":72,"instrument_expiration":1565705400000,"instrument_strike":0.97274,"instrument_dir":"put","instrument_period":300,"instrument_percent":null,"id":1335930181,"user_id":49006564,"user_balance_id":234839765,"user_group_id":184,"user_balance_type":4,"position_id":735301131,"create_at":1565705102038,"update_at":1565705102206,"execute_at":1565705102354,"side":"buy","type":"market","status":"filled","execute_status":"trade","count":0.380512,"leverage":1,"underlying_price":0.97276,"avg_price":52.560707,"avg_price_enrolled":52.560707,"client_platform_id":9,"limit_price":0.0,"stop_price":null,"currency":"USD","margin":19.99998,"spread":null,"commission_amount":0.0,"commission_amount_enrolled":0.0,"extra_data":{"amount":20000000,"version":"4.0","init_time":1565705102019,"use_trail_stop":false,"auto_margin_call":false,"paid_for_commission":0,"use_token_for_commission":false,"paid_for_commission_enrolled":0},"time_in_force":"good_till_cancel","time_in_force_date":null,"last_index":3655230481},"status":2000}
2019-08-13 11:07:21,827 {"name": "sendMessage", "msg": {"name": "get-position", "body": {"position_id": 735301131}}, "request_id": ""}
2019-08-13 11:07:22,032 {"request_id":"","name":"position","msg":{"position":{"last_change_reason":"market_order","instrument_id_escape":"doUSDCHF201908131410PT5MP097274","instrument_strike_value":972740,"instrument_type":"digital-option","instrument_id":"doUSDCHF201908131410PT5MP097274","instrument_underlying":"USDCHF","instrument_active_id":72,"instrument_expiration":1565705400000,"instrument_strike":0.97274,"instrument_dir":"put","instrument_period":300,"instrument_percent":null,"id":735301131,"user_id":49006564,"user_balance_id":234839765,"user_balance_type":4,"create_at":1565705102354,"update_at":1565705102354,"close_at":null,"type":"long","leverage":1,"count":0.380512,"count_realized":0.0,"status":"open","buy_amount":19.99998,"sell_amount":0.0,"buy_amount_enrolled":19.99998,"sell_amount_enrolled":0.0,"commission_amount":0.0,"commission":0.0,"commission_enrolled":0.0,"close_effect_amount":null,"close_effect_amount_enrolled":null,"close_reason":null,"close_underlying_price":null,"open_underlying_price":0.97276,"pnl_realized":0.0,"pnl_realized_enrolled":0.0,"buy_avg_price":52.560707,"buy_avg_price_enrolled":52.560707,"sell_avg_price":0.0,"sell_avg_price_enrolled":0.0,"stop_lose_order_id":null,"take_profit_order_id":null,"tpsl_extra":null,"currency":"USD","margin":0.0,"margin_call":0.0,"margin_call_enrolled":0.0,"swap":0.0,"swap_enrolled":0.0,"custodial":0.0,"custodial_enrolled":0.0,"custodial_last_age":0,"user_group_id":184,"charge":0.0,"charge_enrolled":0.0,"orders":[],"currency_unit":1,"currency_rate":1.0,"open_client_platform_id":9,"extra_data":{"amount":20000000,"version":"4.0","init_time":1565705102019,"use_trail_stop":false,"auto_margin_call":false,"last_change_reason":"market_order","use_token_for_commission":false},"order_ids":[1335930181],"last_index":7124327955},"orders":[{"instrument_id_escape":"doUSDCHF201908131410PT5MP097274","basic_stoplimit_amount":20.0,"take_profit_price":null,"stop_lose_price":null,"tpsl_extra":null,"instrument_strike_value":972740,"instrument_type":"digital-option","instrument_id":"doUSDCHF201908131410PT5MP097274","instrument_underlying":"USDCHF","instrument_active_id":72,"instrument_expiration":1565705400000,"instrument_strike":0.97274,"instrument_dir":"put","instrument_period":300,"instrument_percent":null,"id":1335930181,"user_id":49006564,"user_balance_id":234839765,"user_group_id":184,"user_balance_type":4,"position_id":735301131,"create_at":1565705102038,"update_at":1565705102206,"execute_at":1565705102354,"side":"buy","type":"market","status":"filled","execute_status":"trade","count":0.380512,"leverage":1,"underlying_price":0.97276,"avg_price":52.560707,"avg_price_enrolled":52.560707,"client_platform_id":9,"limit_price":0.0,"stop_price":null,"currency":"USD","margin":19.99998,"spread":null,"commission_amount":0.0,"commission_amount_enrolled":0.0,"extra_data":{"amount":20000000,"version":"4.0","init_time":1565705102019,"use_trail_stop":false,"auto_margin_call":false,"paid_for_commission":0,"use_token_for_commission":false,"paid_for_commission_enrolled":0},"time_in_force":"good_till_cancel","time_in_force_date":null,"last_index":3655230481}]},"status":2000}
2019-08-13 11:07:22,032 {"name": "sendMessage", "msg": {"name": "get-order", "body": {"order_id": 1335930181}}, "request_id": ""}
2019-08-13 11:07:22,248 {"request_id":"","name":"order","msg":{"instrument_id_escape":"doUSDCHF201908131410PT5MP097274","basic_stoplimit_amount":20.0,"take_profit_price":null,"stop_lose_price":null,"tpsl_extra":null,"instrument_strike_value":972740,"instrument_type":"digital-option","instrument_id":"doUSDCHF201908131410PT5MP097274","instrument_underlying":"USDCHF","instrument_active_id":72,"instrument_expiration":1565705400000,"instrument_strike":0.97274,"instrument_dir":"put","instrument_period":300,"instrument_percent":null,"id":1335930181,"user_id":49006564,"user_balance_id":234839765,"user_group_id":184,"user_balance_type":4,"position_id":735301131,"create_at":1565705102038,"update_at":1565705102206,"execute_at":1565705102354,"side":"buy","type":"market","status":"filled","execute_status":"trade","count":0.380512,"leverage":1,"underlying_price":0.97276,"avg_price":52.560707,"avg_price_enrolled":52.560707,"client_platform_id":9,"limit_price":0.0,"stop_price":null,"currency":"USD","margin":19.99998,"spread":null,"commission_amount":0.0,"commission_amount_enrolled":0.0,"extra_data":{"amount":20000000,"version":"4.0","init_time":1565705102019,"use_trail_stop":false,"auto_margin_call":false,"paid_for_commission":0,"use_token_for_commission":false,"paid_for_commission_enrolled":0},"time_in_force":"good_till_cancel","time_in_force_date":null,"last_index":3655230481},"status":2000}
2019-08-13 11:07:22,254 {"name": "sendMessage", "msg": {"name": "get-position", "body": {"position_id": 735301131}}, "request_id": ""}
2019-08-13 11:07:22,254 {"name":"timeSync","msg":1565705242119}
2019-08-13 11:07:22,254 {"name":"heartbeat","msg":1565705242119}
2019-08-13 11:07:22,255 {"name": "heartbeat", "msg": {"msg": {"heartbeatTime": 1565705242119, "userTime": 1565705242119}}, "request_id": ""}
Traceback (most recent call last):
  File "/Users/valderi/Documents/iqoptionapi/test_com_soros.py", line 326, in <module>
    id)
  File "/Users/valderi/Documents/iqoptionapi/iqoptionapi/stable_api.py", line 714, in check_win_digital
    check, data = self.get_position(buy_order_id)
  File "/Users/valderi/Documents/iqoptionapi/iqoptionapi/stable_api.py", line 845, in get_position
    self.api.get_position(position_id)
  File "/Users/valderi/Documents/iqoptionapi/iqoptionapi/ws/chanels/get_positions.py", line 26, in __call__
    self.send_websocket_request(self.name, data)
  File "/Users/valderi/Documents/iqoptionapi/iqoptionapi/ws/chanels/base.py", line 23, in send_websocket_request
    return self.api.send_websocket_request(name, msg,request_id)
  File "/Users/valderi/Documents/iqoptionapi/iqoptionapi/api.py", line 243, in send_websocket_request
    self.websocket.send(data)
  File "/usr/local/lib/python3.7/site-packages/websocket/_app.py", line 147, in send
    if not self.sock or self.sock.send(data, opcode) == 0:
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 240, in send
    return self.send_frame(frame)
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 265, in send_frame
    l = self._send(data)
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 430, in _send
    return send(self.sock, data)
  File "/usr/local/lib/python3.7/site-packages/websocket/_socket.py", line 117, in send
    return sock.send(data)
  File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 984, in send
    return self._sslobj.write(data)
OSError: [Errno 22] Invalid argument

PS: before the code update I could run for a lot of hours in a row without get any error.

@otitamario
Copy link

otitamario commented Aug 13, 2019

Nothing my friend? Il giorno mer 10 lug 2019 alle ore 17:50 ardemagni mattia < ardemagni.mattia@gmail.com> ha scritto:

Thank you, really appreciate it! Il giorno mer 10 lug 2019 alle 15:45 Anson @.***> ha scritto: > I think it is very easy , I will add it > > — > You are receiving this because you were mentioned. > Reply to this email directly, view it on GitHub > <#65?email_source=notifications&email_token=AKGLQ5EPFA4XJUKFNEUCHWTP6XRWFA5CNFSM4GMBMHCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZTQEPY#issuecomment-510067263>, > or mute the thread > https://github.com/notifications/unsubscribe-auth/AKGLQ5DUWG4F32IQJH5PV7DP6XRWFANCNFSM4GMBMHCA > . >

this code can buy the price near current price!

from iqoptionapi.stable_api import IQ_Option
import time
import random

I_want_money=IQ_Option("email","pasword")

goal="EURUSD"
size=1#size=[1,5,10,15,30,60,120,300,600,900,1800,3600,7200,14400,28800,43200,86400,604800,2592000,"all"]
maxdict=1
print("start stream...")
I_want_money.start_candles_stream(goal,size,maxdict)
 
print("print candles")
candle=I_want_money.get_realtime_candles(goal,size)
key=list(candle)[0]
current_price=candle[key]["close"]
print("current_price",current_price)
 
######
 
 
duration=1#minute 1 or 5
amount=1
buy="call"#or "put"
I_want_money.subscribe_strike_list(goal)
#get strike_list
data=I_want_money.get_realtime_strike_list(goal, duration)
 
#get price list
price_list=list(data.keys())
 
close_current_price=[]
for p_list in price_list:
    close_current_price.append(abs(current_price-float(p_list)))

most_close_price=price_list[close_current_price.index(min(close_current_price))]
print("most_close_price",most_close_price,"current_price",current_price)
print(data[str(most_close_price)])
 
#random choose Strategy
choose_price=most_close_price
#get instrument_id
instrument_id=data[choose_price][buy]["id"]
#get profit
profit=data[choose_price][buy]["profit"]
print("choose you want to buy")
print("price:",choose_price,"side:call","instrument_id:",instrument_id,"profit:",profit)
#put instrument_id to buy
buy_check,id=I_want_money.buy_digital(amount,instrument_id)
if buy_check:
    print("wait for check win")
    #check win
    while True:
        check_close,win_money=I_want_money.check_win_digital(id)
        if check_close:
            if float(win_money)>0:
                win_money=("%.2f" % (win_money))
                print("you win",win_money,"money")
            else:
                print("you loose")
            break
    I_want_money.unsubscribe_strike_list(buy)
else:
    print("fail to buy,please run again,digit is change very fast so sometime if can not buy the price!,please try more time")

After the API update yesterday, after 1 hour of execution I am getting this error bellow:

2019-08-13 11:07:21,607 {"request_id":"","name":"position","msg":{"position":{"last_change_reason":"market_order","instrument_id_escape":"doUSDCHF201908131410PT5MP097274","instrument_strike_value":972740,"instrument_type":"digital-option","instrument_id":"doUSDCHF201908131410PT5MP097274","instrument_underlying":"USDCHF","instrument_active_id":72,"instrument_expiration":1565705400000,"instrument_strike":0.97274,"instrument_dir":"put","instrument_period":300,"instrument_percent":null,"id":735301131,"user_id":49006564,"user_balance_id":234839765,"user_balance_type":4,"create_at":1565705102354,"update_at":1565705102354,"close_at":null,"type":"long","leverage":1,"count":0.380512,"count_realized":0.0,"status":"open","buy_amount":19.99998,"sell_amount":0.0,"buy_amount_enrolled":19.99998,"sell_amount_enrolled":0.0,"commission_amount":0.0,"commission":0.0,"commission_enrolled":0.0,"close_effect_amount":null,"close_effect_amount_enrolled":null,"close_reason":null,"close_underlying_price":null,"open_underlying_price":0.97276,"pnl_realized":0.0,"pnl_realized_enrolled":0.0,"buy_avg_price":52.560707,"buy_avg_price_enrolled":52.560707,"sell_avg_price":0.0,"sell_avg_price_enrolled":0.0,"stop_lose_order_id":null,"take_profit_order_id":null,"tpsl_extra":null,"currency":"USD","margin":0.0,"margin_call":0.0,"margin_call_enrolled":0.0,"swap":0.0,"swap_enrolled":0.0,"custodial":0.0,"custodial_enrolled":0.0,"custodial_last_age":0,"user_group_id":184,"charge":0.0,"charge_enrolled":0.0,"orders":[],"currency_unit":1,"currency_rate":1.0,"open_client_platform_id":9,"extra_data":{"amount":20000000,"version":"4.0","init_time":1565705102019,"use_trail_stop":false,"auto_margin_call":false,"last_change_reason":"market_order","use_token_for_commission":false},"order_ids":[1335930181],"last_index":7124327955},"orders":[{"instrument_id_escape":"doUSDCHF201908131410PT5MP097274","basic_stoplimit_amount":20.0,"take_profit_price":null,"stop_lose_price":null,"tpsl_extra":null,"instrument_strike_value":972740,"instrument_type":"digital-option","instrument_id":"doUSDCHF201908131410PT5MP097274","instrument_underlying":"USDCHF","instrument_active_id":72,"instrument_expiration":1565705400000,"instrument_strike":0.97274,"instrument_dir":"put","instrument_period":300,"instrument_percent":null,"id":1335930181,"user_id":49006564,"user_balance_id":234839765,"user_group_id":184,"user_balance_type":4,"position_id":735301131,"create_at":1565705102038,"update_at":1565705102206,"execute_at":1565705102354,"side":"buy","type":"market","status":"filled","execute_status":"trade","count":0.380512,"leverage":1,"underlying_price":0.97276,"avg_price":52.560707,"avg_price_enrolled":52.560707,"client_platform_id":9,"limit_price":0.0,"stop_price":null,"currency":"USD","margin":19.99998,"spread":null,"commission_amount":0.0,"commission_amount_enrolled":0.0,"extra_data":{"amount":20000000,"version":"4.0","init_time":1565705102019,"use_trail_stop":false,"auto_margin_call":false,"paid_for_commission":0,"use_token_for_commission":false,"paid_for_commission_enrolled":0},"time_in_force":"good_till_cancel","time_in_force_date":null,"last_index":3655230481}]},"status":2000}
2019-08-13 11:07:21,614 {"name": "sendMessage", "msg": {"name": "get-order", "body": {"order_id": 1335930181}}, "request_id": ""}
2019-08-13 11:07:21,827 {"request_id":"","name":"order","msg":{"instrument_id_escape":"doUSDCHF201908131410PT5MP097274","basic_stoplimit_amount":20.0,"take_profit_price":null,"stop_lose_price":null,"tpsl_extra":null,"instrument_strike_value":972740,"instrument_type":"digital-option","instrument_id":"doUSDCHF201908131410PT5MP097274","instrument_underlying":"USDCHF","instrument_active_id":72,"instrument_expiration":1565705400000,"instrument_strike":0.97274,"instrument_dir":"put","instrument_period":300,"instrument_percent":null,"id":1335930181,"user_id":49006564,"user_balance_id":234839765,"user_group_id":184,"user_balance_type":4,"position_id":735301131,"create_at":1565705102038,"update_at":1565705102206,"execute_at":1565705102354,"side":"buy","type":"market","status":"filled","execute_status":"trade","count":0.380512,"leverage":1,"underlying_price":0.97276,"avg_price":52.560707,"avg_price_enrolled":52.560707,"client_platform_id":9,"limit_price":0.0,"stop_price":null,"currency":"USD","margin":19.99998,"spread":null,"commission_amount":0.0,"commission_amount_enrolled":0.0,"extra_data":{"amount":20000000,"version":"4.0","init_time":1565705102019,"use_trail_stop":false,"auto_margin_call":false,"paid_for_commission":0,"use_token_for_commission":false,"paid_for_commission_enrolled":0},"time_in_force":"good_till_cancel","time_in_force_date":null,"last_index":3655230481},"status":2000}
2019-08-13 11:07:21,827 {"name": "sendMessage", "msg": {"name": "get-position", "body": {"position_id": 735301131}}, "request_id": ""}
2019-08-13 11:07:22,032 {"request_id":"","name":"position","msg":{"position":{"last_change_reason":"market_order","instrument_id_escape":"doUSDCHF201908131410PT5MP097274","instrument_strike_value":972740,"instrument_type":"digital-option","instrument_id":"doUSDCHF201908131410PT5MP097274","instrument_underlying":"USDCHF","instrument_active_id":72,"instrument_expiration":1565705400000,"instrument_strike":0.97274,"instrument_dir":"put","instrument_period":300,"instrument_percent":null,"id":735301131,"user_id":49006564,"user_balance_id":234839765,"user_balance_type":4,"create_at":1565705102354,"update_at":1565705102354,"close_at":null,"type":"long","leverage":1,"count":0.380512,"count_realized":0.0,"status":"open","buy_amount":19.99998,"sell_amount":0.0,"buy_amount_enrolled":19.99998,"sell_amount_enrolled":0.0,"commission_amount":0.0,"commission":0.0,"commission_enrolled":0.0,"close_effect_amount":null,"close_effect_amount_enrolled":null,"close_reason":null,"close_underlying_price":null,"open_underlying_price":0.97276,"pnl_realized":0.0,"pnl_realized_enrolled":0.0,"buy_avg_price":52.560707,"buy_avg_price_enrolled":52.560707,"sell_avg_price":0.0,"sell_avg_price_enrolled":0.0,"stop_lose_order_id":null,"take_profit_order_id":null,"tpsl_extra":null,"currency":"USD","margin":0.0,"margin_call":0.0,"margin_call_enrolled":0.0,"swap":0.0,"swap_enrolled":0.0,"custodial":0.0,"custodial_enrolled":0.0,"custodial_last_age":0,"user_group_id":184,"charge":0.0,"charge_enrolled":0.0,"orders":[],"currency_unit":1,"currency_rate":1.0,"open_client_platform_id":9,"extra_data":{"amount":20000000,"version":"4.0","init_time":1565705102019,"use_trail_stop":false,"auto_margin_call":false,"last_change_reason":"market_order","use_token_for_commission":false},"order_ids":[1335930181],"last_index":7124327955},"orders":[{"instrument_id_escape":"doUSDCHF201908131410PT5MP097274","basic_stoplimit_amount":20.0,"take_profit_price":null,"stop_lose_price":null,"tpsl_extra":null,"instrument_strike_value":972740,"instrument_type":"digital-option","instrument_id":"doUSDCHF201908131410PT5MP097274","instrument_underlying":"USDCHF","instrument_active_id":72,"instrument_expiration":1565705400000,"instrument_strike":0.97274,"instrument_dir":"put","instrument_period":300,"instrument_percent":null,"id":1335930181,"user_id":49006564,"user_balance_id":234839765,"user_group_id":184,"user_balance_type":4,"position_id":735301131,"create_at":1565705102038,"update_at":1565705102206,"execute_at":1565705102354,"side":"buy","type":"market","status":"filled","execute_status":"trade","count":0.380512,"leverage":1,"underlying_price":0.97276,"avg_price":52.560707,"avg_price_enrolled":52.560707,"client_platform_id":9,"limit_price":0.0,"stop_price":null,"currency":"USD","margin":19.99998,"spread":null,"commission_amount":0.0,"commission_amount_enrolled":0.0,"extra_data":{"amount":20000000,"version":"4.0","init_time":1565705102019,"use_trail_stop":false,"auto_margin_call":false,"paid_for_commission":0,"use_token_for_commission":false,"paid_for_commission_enrolled":0},"time_in_force":"good_till_cancel","time_in_force_date":null,"last_index":3655230481}]},"status":2000}
2019-08-13 11:07:22,032 {"name": "sendMessage", "msg": {"name": "get-order", "body": {"order_id": 1335930181}}, "request_id": ""}
2019-08-13 11:07:22,248 {"request_id":"","name":"order","msg":{"instrument_id_escape":"doUSDCHF201908131410PT5MP097274","basic_stoplimit_amount":20.0,"take_profit_price":null,"stop_lose_price":null,"tpsl_extra":null,"instrument_strike_value":972740,"instrument_type":"digital-option","instrument_id":"doUSDCHF201908131410PT5MP097274","instrument_underlying":"USDCHF","instrument_active_id":72,"instrument_expiration":1565705400000,"instrument_strike":0.97274,"instrument_dir":"put","instrument_period":300,"instrument_percent":null,"id":1335930181,"user_id":49006564,"user_balance_id":234839765,"user_group_id":184,"user_balance_type":4,"position_id":735301131,"create_at":1565705102038,"update_at":1565705102206,"execute_at":1565705102354,"side":"buy","type":"market","status":"filled","execute_status":"trade","count":0.380512,"leverage":1,"underlying_price":0.97276,"avg_price":52.560707,"avg_price_enrolled":52.560707,"client_platform_id":9,"limit_price":0.0,"stop_price":null,"currency":"USD","margin":19.99998,"spread":null,"commission_amount":0.0,"commission_amount_enrolled":0.0,"extra_data":{"amount":20000000,"version":"4.0","init_time":1565705102019,"use_trail_stop":false,"auto_margin_call":false,"paid_for_commission":0,"use_token_for_commission":false,"paid_for_commission_enrolled":0},"time_in_force":"good_till_cancel","time_in_force_date":null,"last_index":3655230481},"status":2000}
2019-08-13 11:07:22,254 {"name": "sendMessage", "msg": {"name": "get-position", "body": {"position_id": 735301131}}, "request_id": ""}
2019-08-13 11:07:22,254 {"name":"timeSync","msg":1565705242119}
2019-08-13 11:07:22,254 {"name":"heartbeat","msg":1565705242119}
2019-08-13 11:07:22,255 {"name": "heartbeat", "msg": {"msg": {"heartbeatTime": 1565705242119, "userTime": 1565705242119}}, "request_id": ""}
Traceback (most recent call last):
  File "/Users/valderi/Documents/iqoptionapi/test_com_soros.py", line 326, in <module>
    id)
  File "/Users/valderi/Documents/iqoptionapi/iqoptionapi/stable_api.py", line 714, in check_win_digital
    check, data = self.get_position(buy_order_id)
  File "/Users/valderi/Documents/iqoptionapi/iqoptionapi/stable_api.py", line 845, in get_position
    self.api.get_position(position_id)
  File "/Users/valderi/Documents/iqoptionapi/iqoptionapi/ws/chanels/get_positions.py", line 26, in __call__
    self.send_websocket_request(self.name, data)
  File "/Users/valderi/Documents/iqoptionapi/iqoptionapi/ws/chanels/base.py", line 23, in send_websocket_request
    return self.api.send_websocket_request(name, msg,request_id)
  File "/Users/valderi/Documents/iqoptionapi/iqoptionapi/api.py", line 243, in send_websocket_request
    self.websocket.send(data)
  File "/usr/local/lib/python3.7/site-packages/websocket/_app.py", line 147, in send
    if not self.sock or self.sock.send(data, opcode) == 0:
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 240, in send
    return self.send_frame(frame)
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 265, in send_frame
    l = self._send(data)
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 430, in _send
    return send(self.sock, data)
  File "/usr/local/lib/python3.7/site-packages/websocket/_socket.py", line 117, in send
    return sock.send(data)
  File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 984, in send
    return self._sslobj.write(data)
OSError: [Errno 22] Invalid argument

PS: before the code update I could run for a lot of hours in a row without get any error.

Replace on the last lines: I_want_money.unsubscribe_strike_list(buy)
by:
I_want_money.unsubscribe_strike_list(goal)

@valderind4
Copy link

@valderind4 thank ,i will check id problem

Hello @Lu-Yi-Hsun any news about the problem regarding order id?

@htnlabs
Copy link

htnlabs commented Aug 19, 2019

@valderind4 thank ,i will check id problem

Hello @Lu-Yi-Hsun any news about the problem regarding order id?

News?

@valderind4
Copy link

@valderind4 thank ,i will check id problem

Hello @Lu-Yi-Hsun any news about the problem regarding order id?

News?

I thank so much to @Lu-Yi-Hsun for his great job, but It so important to get the spot price. So far, we can only wait for it.

@valderind4
Copy link

Hello @Lu-Yi-Hsun the API development is stopped? We need just get the return (win or loss) for buy digital spot method because no method that exists right now can get the correct return and the check_digital_win return order id not found since the buy digital spot returns the digital option id instead of the order id, please help us!!!

@valderind4
Copy link

@thiagottjv How is it going Your PHP api Will You put it on Github?

@thiagottjv
Copy link

@valderind4 Unfortunately I wont be making an api on PHP. What I did was just a one page class including the websocket connection and the request to connect. Thats basically it. After that you send requests to subscribe to the candle stream and buy when its time.

@valderind4
Copy link

@valderind4 Unfortunately I wont be making an api on PHP. What I did was just a one page class including the websocket connection and the request to connect. Thats basically it. After that you send requests to subscribe to the candle stream and buy when its time.

Tks for your answser I got what you said, my problem is on getting the return (win or loss).

@Lu-Yi-Hsun
Copy link
Owner

Iq option is update the server ,so some api can not working , I am fix check win for now

@valderind4
Copy link

Iq option is update the server ,so some api can not working , I am fix check win for now

Thank You so much @Lu-Yi-Hsun because check win is, for now, the only thing that makes the API not working for me.

@kkagill
Copy link

kkagill commented Sep 28, 2019

Hi @Lu-Yi-Hsun
Thanks for the great work. Is this fixed yet? buy_order_id is still None though.

@williampasini07
Copy link

williampasini07 commented Feb 25, 2021

Hi @Lu-Yi-Hsun
First of All I want thank you for the iqoptionapi and second I just wanna ask you about how to get the correct profit on digital market, coz i'm using the code below and doesn't work. The result showed me 87% but on IQOption Plataform was 20%. Could you or Anyone that read it, help me with that.

def procura_abertas(tipo):
paridades = API.get_all_open_time()
abertas = []
if tipo != 'digital':
for par in paridades['binary']:
if paridades['binary'][par]['open']:
abertas.append(par)
else:
for par in paridades['digital']:
if paridades['digital'][par]['open']:
abertas.append(par)

return abertas

par = API.get_all_open_time()
if str(modalidade[0]) == 'd' or str(modalidade[0]) == 'D':
for paridade in par['turbo']:
if par['turbo'][paridade]['open'] == True:
profit = False
API.subscribe_strike_list(paridade,1)
while profit == False:
profit = API.get_digital_current_profit(paridade,1)
if profit != False:
profit = int(profit)
API.unsubscribe_strike_list(paridade,1)
print('Opção Digital:', paridade,'-',str(profit),'% está ativa!')
else:
for paridade in par['binary']:
if par['binary'][paridade]['open'] == True:
print('Opção Binária:', paridade,'-',str(payout2(paridade, 'binary')),'% está ativa!')

@vuppalaseshu
Copy link

Hi,

I am using iqoptionapi for my python code. i am still getting error in check_win_digital_v2.Please help me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imp. have been implement at last version
Projects
None yet
Development

No branches or pull requests