diff --git a/README.md b/README.md index 78a388e2..4526a6e9 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,23 @@ [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.me/iqoptionapi) -last update:2019/11/22 +last update:2019/11/26 + + +Version:5.2 + +add + +https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/152 + +[get_commission_change](#getcommissionchange) api +[subscribe_commission_changed](#getcommissionchange) api +[unsubscribe_commission_changed](#getcommissionchange) api + +fix + +https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/144 + Version:5.1 add[get_option_open_by_other_pc](#getoptionopenbyotherpc) api @@ -331,6 +347,40 @@ while I_want_money.get_async_order(id)==None: order_data=I_want_money.get_async_order(id) print(I_want_money.get_async_order(id)) ``` +#### get_commission_change + + +instrument_type: "binary-option"/"turbo-option"/"digital-option"/"crypto"/"forex"/"cfd" + +I_want_money.subscribe_commission_changed(instrument_type) +I_want_money.get_commission_change(instrument_type) +I_want_money.unsubscribe_commission_changed(instrument_type) + +Sample code + +```python +import time +from iqoptionapi.stable_api import IQ_Option +I_want_money=IQ_Option("email","password") +#instrument_type: "binary-option"/"turbo-option"/"digital-option"/"crypto"/"forex"/"cfd" +instrument_type=["binary-option","turbo-option","digital-option","crypto","forex","cfd"] +for ins in instrument_type: + I_want_money.subscribe_commission_changed(ins) +print("Start stream please wait profit change...") +while True: + for ins in instrument_type: + commissio_data=I_want_money.get_commission_change(ins) + if commissio_data!={}: + for active_name in commissio_data: + if commissio_data[active_name]!={}: + the_min_timestamp=min(commissio_data[active_name].keys()) + commissio=commissio_data[active_name][the_min_timestamp] + profit=(100-commissio)/100 + print("instrument_type: "+str(ins)+" active_name: "+str(active_name)+" profit change to: "+str(profit)) + #Data have been update so need del + del I_want_money.get_commission_change(ins)[active_name][the_min_timestamp] + time.sleep(1) +``` ### For Options @@ -1376,7 +1426,6 @@ I_want_money.change_balance(MODE) --- - diff --git a/iqoptionapi/api.py b/iqoptionapi/api.py index b124df29..cd56a8e8 100644 --- a/iqoptionapi/api.py +++ b/iqoptionapi/api.py @@ -111,7 +111,7 @@ class IQOptionAPI(object): # pylint: disable=too-many-instance-attributes digital_option_placed_id = None microserviceName_binary_options_name_option={} - + subscribe_commission_changed_data=nested_dict(2,dict) real_time_candles = nested_dict(3, dict) real_time_candles_maxdict_table = nested_dict(2, dict) candle_generated_check = nested_dict(2, dict) @@ -446,6 +446,13 @@ def Subscribe_Top_Assets_Updated(self): def Unsubscribe_Top_Assets_Updated(self): return Unsubscribe_top_assets_updated(self) + @property + def Subscribe_Commission_Changed(self): + return Subscribe_commission_changed(self) + @property + def Unsubscribe_Commission_Changed(self): + return Unsubscribe_commission_changed(self) + # -------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------- diff --git a/iqoptionapi/stable_api.py b/iqoptionapi/stable_api.py index a17cb483..04b01389 100644 --- a/iqoptionapi/stable_api.py +++ b/iqoptionapi/stable_api.py @@ -7,6 +7,7 @@ import operator from collections import defaultdict +from collections import deque from iqoptionapi.expiration import get_expiration_time,get_remaning_time from datetime import datetime,timedelta @@ -19,7 +20,7 @@ def nested_dict(n, type): class IQ_Option: - __version__ = "5.1" + __version__ = "5.2" def __init__(self, email, password): self.size = [1, 5, 10, 15, 30, 60, 120, 300, 600, 900, 1800, @@ -563,6 +564,17 @@ def get_top_assets_updated(self,instrument_type): return self.api.top_assets_updated_data[instrument_type] else: return None + +#------------------------commission_________ +#instrument_type: "binary-option"/"turbo-option"/"digital-option"/"crypto"/"forex"/"cfd" + def subscribe_commission_changed(self,instrument_type): + + self.api.Subscribe_Commission_Changed(instrument_type) + def unsubscribe_commission_changed(self,instrument_type): + self.api.Unsubscribe_Commission_Changed(instrument_type) + def get_commission_change(self,instrument_type): + return self.api.subscribe_commission_changed_data[instrument_type] + # ----------------------------------------------- # -----------------traders_mood---------------------- @@ -865,6 +877,10 @@ def get_instrument_id_to_bid(data,instrument_id): aVar=position["extra_data"]["lower_instrument_id"] aVar2=position["extra_data"]["upper_instrument_id"] getRate=position["currency_rate"] + #https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/144#issue-518901797 + #float division by zero + if spotUpperInstrumentStrike - spotLowerInstrumentStrike==0: + return None #___________________/*position*/_________________ instrument_quites_generated_data=self.get_instrument_quites_generated_data(ACTIVES, duration) diff --git a/iqoptionapi/ws/chanels/subscribe.py b/iqoptionapi/ws/chanels/subscribe.py index 73727b84..7b9a0f3b 100644 --- a/iqoptionapi/ws/chanels/subscribe.py +++ b/iqoptionapi/ws/chanels/subscribe.py @@ -87,3 +87,23 @@ def __call__(self, instrument_type): "version":"1.2" } self.send_websocket_request(self.name, data) + + + +""" +{"name":"subscribeMessage","request_id":"s_114","msg":{"name":"commission-changed","version":"1.0","params":{"routingFilters":{"instrument_type":"digital-option","user_group_id":1}}}} +""" +#instrument_type: "binary-option"/"turbo-option"/"digital-option"/"crypto"/"forex"/"cfd" +class Subscribe_commission_changed(Base): + name = "subscribeMessage" + def __call__(self, instrument_type): + + data = {"name":"commission-changed", + "params":{ + "routingFilters":{ + "instrument_type":str(instrument_type) + } + }, + "version":"1.0" + } + self.send_websocket_request(self.name, data) \ No newline at end of file diff --git a/iqoptionapi/ws/chanels/unsubscribe.py b/iqoptionapi/ws/chanels/unsubscribe.py index d19c9b96..3a55189b 100644 --- a/iqoptionapi/ws/chanels/unsubscribe.py +++ b/iqoptionapi/ws/chanels/unsubscribe.py @@ -84,3 +84,17 @@ def __call__(self, instrument_type): "version":"1.2" } self.send_websocket_request(self.name, data) + +class Unsubscribe_commission_changed(Base): + name = "unsubscribeMessage" + def __call__(self, instrument_type): + + data = {"name":"commission-changed", + "params":{ + "routingFilters":{ + "instrument_type":str(instrument_type) + } + }, + "version":"1.0" + } + self.send_websocket_request(self.name, data) \ No newline at end of file diff --git a/iqoptionapi/ws/client.py b/iqoptionapi/ws/client.py index bbc2b752..9bce41f8 100644 --- a/iqoptionapi/ws/client.py +++ b/iqoptionapi/ws/client.py @@ -78,7 +78,13 @@ def on_message(self, message): # pylint: disable=unused-argument msg=v self.dict_queue_add(self.api.real_time_candles,maxdict,active,size,from_,msg) self.api.candle_generated_all_size_check[active]=True - + elif message["name"]=="commission-changed": + instrument_type=message["msg"]["instrument_type"] + active_id=message["msg"]["active_id"] + Active_name=list(OP_code.ACTIVES.keys())[list(OP_code.ACTIVES.values()).index(active_id)] + commission=message["msg"]["commission"]["value"] + self.api.subscribe_commission_changed_data[instrument_type][Active_name][self.api.timesync.server_timestamp]=int(commission) + ####################################################### #______________________________________________________ ####################################################### diff --git a/setup.py b/setup.py index cc8733e6..7bee7376 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="iqoptionapi", - version="5.1", + version="5.2", packages=find_packages(), install_requires=["pylint","requests","websocket-client==0.56"], include_package_data = True,