Skip to content

Commit

Permalink
3.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Lu-Yi-Hsun committed Oct 2, 2019
1 parent cf0c8d6 commit 04bc6b2
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 25 deletions.
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

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

last Version:3.9.2
last update:2019/10/2

last update:2019/9/11
last Version:3.9.3

change and fix close digit(close_position) to close_digital_option

fix buy_digital problem

get_order only work for forex..., digital not work

fix close_position api for forex...

fix binary option buy api support python2&python3



Version:3.9.2

Expand Down Expand Up @@ -623,11 +635,11 @@ else:

#### close digital
```python
I_want_money.close_position(id)
I_want_money.close_digital_option(id)
```
#### get digital data
```python
print(I_want_money.get_order(id))
#print(I_want_money.get_order(id))#not work for digital
print(I_want_money.get_positions("digital-option"))
print(I_want_money.get_position_history("digital-option"))
```
Expand Down Expand Up @@ -702,7 +714,7 @@ check,order_id=I_want_money.buy_order(instrument_type=instrument_type, instrumen
take_profit_value=take_profit_value, take_profit_kind=take_profit_kind,
use_trail_stop=use_trail_stop, auto_margin_call=auto_margin_call,
use_token_for_commission=use_token_for_commission)
print(I_want_money.get_order(order_id))
print(I_want_money.get_order(order_id))
print(I_want_money.get_positions("crypto"))
print(I_want_money.get_position_history("crypto"))
print(I_want_money.get_available_leverages("crypto","BTCUSD"))
Expand Down Expand Up @@ -795,6 +807,8 @@ I_want_money.change_order(ID_Name=ID_Name,order_id=order_id,


#### get_order


get infomation about buy_order_id

return (True/False,get_order,None)
Expand Down
9 changes: 7 additions & 2 deletions iqoptionapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

from iqoptionapi.ws.chanels.subscribe import Subscribe_Instrument_Quites_Generated
from iqoptionapi.ws.chanels.unsubscribe import Unsubscribe_Instrument_Quites_Generated
from iqoptionapi.ws.chanels.digital_option import Digital_options_place_digital_option
from iqoptionapi.ws.chanels.digital_option import *
from iqoptionapi.ws.chanels.api_game_getoptions import Getoptions
from iqoptionapi.ws.chanels.sell_option import Sell_Option
from iqoptionapi.ws.chanels.change_tpsl import Change_Tpsl
Expand Down Expand Up @@ -128,7 +128,8 @@ class IQOptionAPI(object): # pylint: disable=too-many-instance-attributes
# --for binary option multi buy
buy_multi_result = None
buy_multi_option = {}

#
result=None
# ------------------

def __init__(self, host, username, password, proxies=None):
Expand Down Expand Up @@ -525,6 +526,10 @@ def unsubscribe_instrument_quites_generated(self):
def place_digital_option(self):
return Digital_options_place_digital_option(self)

@property
def close_digital_option(self):
return Digital_options_close_position(self)

# ____BUY_for__Forex__&&__stock(cfd)__&&__ctrpto_____
@property
def buy_order(self):
Expand Down
24 changes: 14 additions & 10 deletions iqoptionapi/expiration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
import time
from datetime import datetime,timedelta



#https://docs.python.org/3/library/datetime.html
#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.
#time.mktime(dt.timetuple())
def date_to_timestamp(dt):
#local timezone to timestamp support python2 pytohn3
return time.mktime(dt.timetuple())
def get_expiration_time(timestamp,duration):
#
now_date = datetime.fromtimestamp(timestamp)
exp_date=now_date.replace(second=0,microsecond=0)
if (int((exp_date+timedelta(minutes=1)).timestamp())-timestamp)>30:
if (int(date_to_timestamp(exp_date+timedelta(minutes=1)))-timestamp)>30:
exp_date= exp_date+timedelta(minutes=1)

else:
exp_date= exp_date+timedelta(minutes=2)
exp=[]
for _ in range(5):
exp.append(exp_date.timestamp())
exp.append(date_to_timestamp(exp_date))
exp_date= exp_date+timedelta(minutes=1)


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

Expand All @@ -43,22 +47,22 @@ def get_expiration_time(timestamp,duration):
def get_remaning_time(timestamp):
now_date = datetime.fromtimestamp(timestamp)
exp_date=now_date.replace(second=0,microsecond=0)
if (int((exp_date+timedelta(minutes=1)).timestamp())-timestamp)>30:
if (int(date_to_timestamp(exp_date+timedelta(minutes=1)))-timestamp)>30:
exp_date= exp_date+timedelta(minutes=1)

else:
exp_date= exp_date+timedelta(minutes=2)
exp=[]
for _ in range(5):
exp.append(exp_date.timestamp())
exp.append(date_to_timestamp(exp_date))
exp_date= exp_date+timedelta(minutes=1)
idx=11
index=0
now_date = datetime.fromtimestamp(timestamp)
exp_date=now_date.replace(second=0,microsecond=0)
while index<idx:
if int(exp_date.strftime("%M"))%15==0 and (int(exp_date.timestamp())-int(timestamp))>60*5:
exp.append(exp_date.timestamp())
if int(exp_date.strftime("%M"))%15==0 and (int(date_to_timestamp(exp_date))-int(timestamp))>60*5:
exp.append(date_to_timestamp(exp_date))
index=index+1
exp_date= exp_date+timedelta(minutes=1)

Expand Down
40 changes: 33 additions & 7 deletions iqoptionapi/stable_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,11 +773,24 @@ def buy_digital_spot(self, active,amount, action, duration):
return self.api.digital_option_placed_id

def buy_digital(self, amount, instrument_id):
self.api.position_changed = None
return self.buy_order(instrument_type="digital-option",
instrument_id=instrument_id,
side="buy", type="market", amount=amount,
limit_price=0, leverage=1)
self.api.digital_option_placed_id=None
self.api.place_digital_option(instrument_id,amount)
start_t=time.time()
while self.api.digital_option_placed_id==None:
if time.time()-start_t>30:
logging.error('buy_digital loss digital_option_placed_id')
return False,None
return True,self.api.digital_option_placed_id
def close_digital_option(self,position_id):
self.api.result=None
while self.get_async_order(position_id)==None:
pass
position_changed=self.get_async_order(position_id)
self.api.close_digital_option(position_changed["id"])
while self.api.result==None:
pass
return self.api.result

def check_win_digital(self, buy_order_id):
check, data = self.get_position(buy_order_id)
if check:
Expand Down Expand Up @@ -976,8 +989,8 @@ def cancel_order(self, buy_order_id):
else:
return False

def close_position(self, buy_order_id):
check, data = self.get_order(buy_order_id)
def close_position(self, position_id):
check, data = self.get_order(position_id)
if data["position_id"] != None:
self.api.close_position_data = None
self.api.close_position(data["position_id"])
Expand All @@ -989,6 +1002,19 @@ def close_position(self, buy_order_id):
return False
else:
return False
def close_position_v2(self,position_id):
while self.get_async_order(position_id)==None:
pass
position_changed=self.get_async_order(position_id)
self.api.close_position(position_changed["id"])
while self.api.close_position_data == None:
pass
if self.api.close_position_data["status"] == 2000:
return True
else:
return False



def get_overnight_fee(self, instrument_type, active):
self.api.overnight_fee = None
Expand Down
12 changes: 12 additions & 0 deletions iqoptionapi/ws/chanels/digital_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ def __call__(self,instrument_id,amount):
}
self.send_websocket_request(self.name, data)

class Digital_options_close_position(Base):
name = "sendMessage"
def __call__(self,position_id):
data = {
"name": "digital-options.close-position",
"version":"1.0",
"body":{
"position_id":int(position_id)
}
}
self.send_websocket_request(self.name, data)

3 changes: 2 additions & 1 deletion iqoptionapi/ws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def on_message(self, wss, message): # pylint: disable=unused-argument
self.api.digital_option_placed_id=message["msg"]["id"]
except:
self.api.digital_option_placed_id="error"

elif message["name"]=="result":
self.api.result=message["msg"]["success"]
elif message["name"]=="instrument-quotes-generated":
Active_name=list(OP_code.ACTIVES.keys())[list(OP_code.ACTIVES.values()).index(message["msg"]["active"])]
period=message["msg"]["expiration"]["period"]
Expand Down

0 comments on commit 04bc6b2

Please sign in to comment.