Skip to content

Commit c101af1

Browse files
committed
5.2
1 parent 6e3526a commit c101af1

File tree

7 files changed

+118
-6
lines changed

7 files changed

+118
-6
lines changed

README.md

+51-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,23 @@
55

66
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.me/iqoptionapi)
77

8-
last update:2019/11/22
8+
last update:2019/11/26
9+
10+
11+
Version:5.2
12+
13+
add
14+
15+
https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/152
16+
17+
[get_commission_change](#getcommissionchange) api
18+
[subscribe_commission_changed](#getcommissionchange) api
19+
[unsubscribe_commission_changed](#getcommissionchange) api
20+
21+
fix
22+
23+
https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/144
24+
925

1026
Version:5.1
1127
add[get_option_open_by_other_pc](#getoptionopenbyotherpc) api
@@ -331,6 +347,40 @@ while I_want_money.get_async_order(id)==None:
331347
order_data=I_want_money.get_async_order(id)
332348
print(I_want_money.get_async_order(id))
333349
```
350+
#### <a id=getcommissionchange>get_commission_change</a>
351+
352+
353+
instrument_type: "binary-option"/"turbo-option"/"digital-option"/"crypto"/"forex"/"cfd"
354+
355+
I_want_money.subscribe_commission_changed(instrument_type)
356+
I_want_money.get_commission_change(instrument_type)
357+
I_want_money.unsubscribe_commission_changed(instrument_type)
358+
359+
Sample code
360+
361+
```python
362+
import time
363+
from iqoptionapi.stable_api import IQ_Option
364+
I_want_money=IQ_Option("email","password")
365+
#instrument_type: "binary-option"/"turbo-option"/"digital-option"/"crypto"/"forex"/"cfd"
366+
instrument_type=["binary-option","turbo-option","digital-option","crypto","forex","cfd"]
367+
for ins in instrument_type:
368+
I_want_money.subscribe_commission_changed(ins)
369+
print("Start stream please wait profit change...")
370+
while True:
371+
for ins in instrument_type:
372+
commissio_data=I_want_money.get_commission_change(ins)
373+
if commissio_data!={}:
374+
for active_name in commissio_data:
375+
if commissio_data[active_name]!={}:
376+
the_min_timestamp=min(commissio_data[active_name].keys())
377+
commissio=commissio_data[active_name][the_min_timestamp]
378+
profit=(100-commissio)/100
379+
print("instrument_type: "+str(ins)+" active_name: "+str(active_name)+" profit change to: "+str(profit))
380+
#Data have been update so need del
381+
del I_want_money.get_commission_change(ins)[active_name][the_min_timestamp]
382+
time.sleep(1)
383+
```
334384

335385

336386
### For Options
@@ -1376,7 +1426,6 @@ I_want_money.change_balance(MODE)
13761426

13771427
---
13781428

1379-
13801429

13811430

13821431

iqoptionapi/api.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class IQOptionAPI(object): # pylint: disable=too-many-instance-attributes
111111
digital_option_placed_id = None
112112

113113
microserviceName_binary_options_name_option={}
114-
114+
subscribe_commission_changed_data=nested_dict(2,dict)
115115
real_time_candles = nested_dict(3, dict)
116116
real_time_candles_maxdict_table = nested_dict(2, dict)
117117
candle_generated_check = nested_dict(2, dict)
@@ -446,6 +446,13 @@ def Subscribe_Top_Assets_Updated(self):
446446
def Unsubscribe_Top_Assets_Updated(self):
447447
return Unsubscribe_top_assets_updated(self)
448448

449+
@property
450+
def Subscribe_Commission_Changed(self):
451+
return Subscribe_commission_changed(self)
452+
@property
453+
def Unsubscribe_Commission_Changed(self):
454+
return Unsubscribe_commission_changed(self)
455+
449456
# --------------------------------------------------------------------------------
450457
# -----------------------------------------------------------------------------------
451458

iqoptionapi/stable_api.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import operator
88

99
from collections import defaultdict
10+
from collections import deque
1011
from iqoptionapi.expiration import get_expiration_time,get_remaning_time
1112
from datetime import datetime,timedelta
1213

@@ -19,7 +20,7 @@ def nested_dict(n, type):
1920

2021

2122
class IQ_Option:
22-
__version__ = "5.1"
23+
__version__ = "5.2"
2324

2425
def __init__(self, email, password):
2526
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):
563564
return self.api.top_assets_updated_data[instrument_type]
564565
else:
565566
return None
567+
568+
#------------------------commission_________
569+
#instrument_type: "binary-option"/"turbo-option"/"digital-option"/"crypto"/"forex"/"cfd"
570+
def subscribe_commission_changed(self,instrument_type):
571+
572+
self.api.Subscribe_Commission_Changed(instrument_type)
573+
def unsubscribe_commission_changed(self,instrument_type):
574+
self.api.Unsubscribe_Commission_Changed(instrument_type)
575+
def get_commission_change(self,instrument_type):
576+
return self.api.subscribe_commission_changed_data[instrument_type]
577+
566578
# -----------------------------------------------
567579

568580
# -----------------traders_mood----------------------
@@ -865,6 +877,10 @@ def get_instrument_id_to_bid(data,instrument_id):
865877
aVar=position["extra_data"]["lower_instrument_id"]
866878
aVar2=position["extra_data"]["upper_instrument_id"]
867879
getRate=position["currency_rate"]
880+
#https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/144#issue-518901797
881+
#float division by zero
882+
if spotUpperInstrumentStrike - spotLowerInstrumentStrike==0:
883+
return None
868884

869885
#___________________/*position*/_________________
870886
instrument_quites_generated_data=self.get_instrument_quites_generated_data(ACTIVES, duration)

iqoptionapi/ws/chanels/subscribe.py

+20
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,23 @@ def __call__(self, instrument_type):
8787
"version":"1.2"
8888
}
8989
self.send_websocket_request(self.name, data)
90+
91+
92+
93+
"""
94+
{"name":"subscribeMessage","request_id":"s_114","msg":{"name":"commission-changed","version":"1.0","params":{"routingFilters":{"instrument_type":"digital-option","user_group_id":1}}}}
95+
"""
96+
#instrument_type: "binary-option"/"turbo-option"/"digital-option"/"crypto"/"forex"/"cfd"
97+
class Subscribe_commission_changed(Base):
98+
name = "subscribeMessage"
99+
def __call__(self, instrument_type):
100+
101+
data = {"name":"commission-changed",
102+
"params":{
103+
"routingFilters":{
104+
"instrument_type":str(instrument_type)
105+
}
106+
},
107+
"version":"1.0"
108+
}
109+
self.send_websocket_request(self.name, data)

iqoptionapi/ws/chanels/unsubscribe.py

+14
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,17 @@ def __call__(self, instrument_type):
8484
"version":"1.2"
8585
}
8686
self.send_websocket_request(self.name, data)
87+
88+
class Unsubscribe_commission_changed(Base):
89+
name = "unsubscribeMessage"
90+
def __call__(self, instrument_type):
91+
92+
data = {"name":"commission-changed",
93+
"params":{
94+
"routingFilters":{
95+
"instrument_type":str(instrument_type)
96+
}
97+
},
98+
"version":"1.0"
99+
}
100+
self.send_websocket_request(self.name, data)

iqoptionapi/ws/client.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ def on_message(self, message): # pylint: disable=unused-argument
7878
msg=v
7979
self.dict_queue_add(self.api.real_time_candles,maxdict,active,size,from_,msg)
8080
self.api.candle_generated_all_size_check[active]=True
81-
81+
elif message["name"]=="commission-changed":
82+
instrument_type=message["msg"]["instrument_type"]
83+
active_id=message["msg"]["active_id"]
84+
Active_name=list(OP_code.ACTIVES.keys())[list(OP_code.ACTIVES.values()).index(active_id)]
85+
commission=message["msg"]["commission"]["value"]
86+
self.api.subscribe_commission_changed_data[instrument_type][Active_name][self.api.timesync.server_timestamp]=int(commission)
87+
8288
#######################################################
8389
#______________________________________________________
8490
#######################################################

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="iqoptionapi",
6-
version="5.1",
6+
version="5.2",
77
packages=find_packages(),
88
install_requires=["pylint","requests","websocket-client==0.56"],
99
include_package_data = True,

0 commit comments

Comments
 (0)