Skip to content

Commit 04bc6b2

Browse files
committed
3.9.3
1 parent cf0c8d6 commit 04bc6b2

File tree

6 files changed

+87
-25
lines changed

6 files changed

+87
-25
lines changed

README.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22

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

5-
last Version:3.9.2
5+
last update:2019/10/2
66

7-
last update:2019/9/11
7+
last Version:3.9.3
8+
9+
change and fix close digit(close_position) to close_digital_option
10+
11+
fix buy_digital problem
12+
13+
get_order only work for forex..., digital not work
14+
15+
fix close_position api for forex...
16+
17+
fix binary option buy api support python2&python3
18+
19+
820

921
Version:3.9.2
1022

@@ -623,11 +635,11 @@ else:
623635

624636
#### close digital
625637
```python
626-
I_want_money.close_position(id)
638+
I_want_money.close_digital_option(id)
627639
```
628640
#### get digital data
629641
```python
630-
print(I_want_money.get_order(id))
642+
#print(I_want_money.get_order(id))#not work for digital
631643
print(I_want_money.get_positions("digital-option"))
632644
print(I_want_money.get_position_history("digital-option"))
633645
```
@@ -702,7 +714,7 @@ check,order_id=I_want_money.buy_order(instrument_type=instrument_type, instrumen
702714
take_profit_value=take_profit_value, take_profit_kind=take_profit_kind,
703715
use_trail_stop=use_trail_stop, auto_margin_call=auto_margin_call,
704716
use_token_for_commission=use_token_for_commission)
705-
print(I_want_money.get_order(order_id))
717+
print(I_want_money.get_order(order_id))
706718
print(I_want_money.get_positions("crypto"))
707719
print(I_want_money.get_position_history("crypto"))
708720
print(I_want_money.get_available_leverages("crypto","BTCUSD"))
@@ -795,6 +807,8 @@ I_want_money.change_order(ID_Name=ID_Name,order_id=order_id,
795807

796808

797809
#### get_order
810+
811+
798812
get infomation about buy_order_id
799813

800814
return (True/False,get_order,None)

iqoptionapi/api.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
from iqoptionapi.ws.chanels.subscribe import Subscribe_Instrument_Quites_Generated
5353
from iqoptionapi.ws.chanels.unsubscribe import Unsubscribe_Instrument_Quites_Generated
54-
from iqoptionapi.ws.chanels.digital_option import Digital_options_place_digital_option
54+
from iqoptionapi.ws.chanels.digital_option import *
5555
from iqoptionapi.ws.chanels.api_game_getoptions import Getoptions
5656
from iqoptionapi.ws.chanels.sell_option import Sell_Option
5757
from iqoptionapi.ws.chanels.change_tpsl import Change_Tpsl
@@ -128,7 +128,8 @@ class IQOptionAPI(object): # pylint: disable=too-many-instance-attributes
128128
# --for binary option multi buy
129129
buy_multi_result = None
130130
buy_multi_option = {}
131-
131+
#
132+
result=None
132133
# ------------------
133134

134135
def __init__(self, host, username, password, proxies=None):
@@ -525,6 +526,10 @@ def unsubscribe_instrument_quites_generated(self):
525526
def place_digital_option(self):
526527
return Digital_options_place_digital_option(self)
527528

529+
@property
530+
def close_digital_option(self):
531+
return Digital_options_close_position(self)
532+
528533
# ____BUY_for__Forex__&&__stock(cfd)__&&__ctrpto_____
529534
@property
530535
def buy_order(self):

iqoptionapi/expiration.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22
import time
33
from datetime import datetime,timedelta
44

5-
6-
5+
#https://docs.python.org/3/library/datetime.html
6+
#If optional argument tz is None or not specified, the timestamp is converted to the platform’s local date and time, and the returned datetime object is naive.
7+
#time.mktime(dt.timetuple())
8+
def date_to_timestamp(dt):
9+
#local timezone to timestamp support python2 pytohn3
10+
return time.mktime(dt.timetuple())
711
def get_expiration_time(timestamp,duration):
812
#
913
now_date = datetime.fromtimestamp(timestamp)
1014
exp_date=now_date.replace(second=0,microsecond=0)
11-
if (int((exp_date+timedelta(minutes=1)).timestamp())-timestamp)>30:
15+
if (int(date_to_timestamp(exp_date+timedelta(minutes=1)))-timestamp)>30:
1216
exp_date= exp_date+timedelta(minutes=1)
1317

1418
else:
1519
exp_date= exp_date+timedelta(minutes=2)
1620
exp=[]
1721
for _ in range(5):
18-
exp.append(exp_date.timestamp())
22+
exp.append(date_to_timestamp(exp_date))
1923
exp_date= exp_date+timedelta(minutes=1)
2024

2125

@@ -25,8 +29,8 @@ def get_expiration_time(timestamp,duration):
2529
now_date = datetime.fromtimestamp(timestamp)
2630
exp_date=now_date.replace(second=0,microsecond=0)
2731
while index<idx:
28-
if int(exp_date.strftime("%M"))%15==0 and (int(exp_date.timestamp())-int(timestamp))>60*5:
29-
exp.append(exp_date.timestamp())
32+
if int(exp_date.strftime("%M"))%15==0 and (int(date_to_timestamp(exp_date))-int(timestamp))>60*5:
33+
exp.append(date_to_timestamp(exp_date))
3034
index=index+1
3135
exp_date= exp_date+timedelta(minutes=1)
3236

@@ -43,22 +47,22 @@ def get_expiration_time(timestamp,duration):
4347
def get_remaning_time(timestamp):
4448
now_date = datetime.fromtimestamp(timestamp)
4549
exp_date=now_date.replace(second=0,microsecond=0)
46-
if (int((exp_date+timedelta(minutes=1)).timestamp())-timestamp)>30:
50+
if (int(date_to_timestamp(exp_date+timedelta(minutes=1)))-timestamp)>30:
4751
exp_date= exp_date+timedelta(minutes=1)
4852

4953
else:
5054
exp_date= exp_date+timedelta(minutes=2)
5155
exp=[]
5256
for _ in range(5):
53-
exp.append(exp_date.timestamp())
57+
exp.append(date_to_timestamp(exp_date))
5458
exp_date= exp_date+timedelta(minutes=1)
5559
idx=11
5660
index=0
5761
now_date = datetime.fromtimestamp(timestamp)
5862
exp_date=now_date.replace(second=0,microsecond=0)
5963
while index<idx:
60-
if int(exp_date.strftime("%M"))%15==0 and (int(exp_date.timestamp())-int(timestamp))>60*5:
61-
exp.append(exp_date.timestamp())
64+
if int(exp_date.strftime("%M"))%15==0 and (int(date_to_timestamp(exp_date))-int(timestamp))>60*5:
65+
exp.append(date_to_timestamp(exp_date))
6266
index=index+1
6367
exp_date= exp_date+timedelta(minutes=1)
6468

iqoptionapi/stable_api.py

+33-7
Original file line numberDiff line numberDiff line change
@@ -773,11 +773,24 @@ def buy_digital_spot(self, active,amount, action, duration):
773773
return self.api.digital_option_placed_id
774774

775775
def buy_digital(self, amount, instrument_id):
776-
self.api.position_changed = None
777-
return self.buy_order(instrument_type="digital-option",
778-
instrument_id=instrument_id,
779-
side="buy", type="market", amount=amount,
780-
limit_price=0, leverage=1)
776+
self.api.digital_option_placed_id=None
777+
self.api.place_digital_option(instrument_id,amount)
778+
start_t=time.time()
779+
while self.api.digital_option_placed_id==None:
780+
if time.time()-start_t>30:
781+
logging.error('buy_digital loss digital_option_placed_id')
782+
return False,None
783+
return True,self.api.digital_option_placed_id
784+
def close_digital_option(self,position_id):
785+
self.api.result=None
786+
while self.get_async_order(position_id)==None:
787+
pass
788+
position_changed=self.get_async_order(position_id)
789+
self.api.close_digital_option(position_changed["id"])
790+
while self.api.result==None:
791+
pass
792+
return self.api.result
793+
781794
def check_win_digital(self, buy_order_id):
782795
check, data = self.get_position(buy_order_id)
783796
if check:
@@ -976,8 +989,8 @@ def cancel_order(self, buy_order_id):
976989
else:
977990
return False
978991

979-
def close_position(self, buy_order_id):
980-
check, data = self.get_order(buy_order_id)
992+
def close_position(self, position_id):
993+
check, data = self.get_order(position_id)
981994
if data["position_id"] != None:
982995
self.api.close_position_data = None
983996
self.api.close_position(data["position_id"])
@@ -989,6 +1002,19 @@ def close_position(self, buy_order_id):
9891002
return False
9901003
else:
9911004
return False
1005+
def close_position_v2(self,position_id):
1006+
while self.get_async_order(position_id)==None:
1007+
pass
1008+
position_changed=self.get_async_order(position_id)
1009+
self.api.close_position(position_changed["id"])
1010+
while self.api.close_position_data == None:
1011+
pass
1012+
if self.api.close_position_data["status"] == 2000:
1013+
return True
1014+
else:
1015+
return False
1016+
1017+
9921018

9931019
def get_overnight_fee(self, instrument_type, active):
9941020
self.api.overnight_fee = None

iqoptionapi/ws/chanels/digital_option.py

+12
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ def __call__(self,instrument_id,amount):
2121
}
2222
self.send_websocket_request(self.name, data)
2323

24+
class Digital_options_close_position(Base):
25+
name = "sendMessage"
26+
def __call__(self,position_id):
27+
data = {
28+
"name": "digital-options.close-position",
29+
"version":"1.0",
30+
"body":{
31+
"position_id":int(position_id)
32+
}
33+
}
34+
self.send_websocket_request(self.name, data)
35+

iqoptionapi/ws/client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ def on_message(self, wss, message): # pylint: disable=unused-argument
199199
self.api.digital_option_placed_id=message["msg"]["id"]
200200
except:
201201
self.api.digital_option_placed_id="error"
202-
202+
elif message["name"]=="result":
203+
self.api.result=message["msg"]["success"]
203204
elif message["name"]=="instrument-quotes-generated":
204205
Active_name=list(OP_code.ACTIVES.keys())[list(OP_code.ACTIVES.values()).index(message["msg"]["active"])]
205206
period=message["msg"]["expiration"]["period"]

0 commit comments

Comments
 (0)