Skip to content

Commit

Permalink
5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Lu-Yi-Hsun committed Nov 26, 2019
1 parent 6e3526a commit c101af1
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 6 deletions.
53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
```
#### <a id=getcommissionchange>get_commission_change</a>


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
Expand Down Expand Up @@ -1376,7 +1426,6 @@ I_want_money.change_balance(MODE)

---





9 changes: 8 additions & 1 deletion iqoptionapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

# --------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------

Expand Down
18 changes: 17 additions & 1 deletion iqoptionapi/stable_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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----------------------
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions iqoptionapi/ws/chanels/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 14 additions & 0 deletions iqoptionapi/ws/chanels/unsubscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 7 additions & 1 deletion iqoptionapi/ws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

#######################################################
#______________________________________________________
#######################################################
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c101af1

Please sign in to comment.