Skip to content

Commit

Permalink
Merge pull request #178 from dwighthalpert/master
Browse files Browse the repository at this point in the history
Fix buy and multi buy
  • Loading branch information
Lu-Yi-Hsun authored Dec 24, 2019
2 parents 3bc5d68 + d83e54b commit b7b8dbb
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 239 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ build/
dist/
*.egg-info/
.vscode/
/.vs
test.py
77 changes: 8 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,7 @@

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


## public version someday i will be back.

last update:2019/11/28

Version:5.2.1
roll back get_digital_spot_profit_after_sale some code

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

last update:2019/11/22

Version:5.1
add[get_option_open_by_other_pc](#getoptionopenbyotherpc) api
Expand Down Expand Up @@ -354,40 +331,6 @@ 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 All @@ -409,11 +352,7 @@ ACTIVES="EURUSD"
ACTION="call"#or "put"
expirations_mode=1

check,id=I_want_money.buy(Money,ACTIVES,ACTION,expirations_mode)
if check:
print("!buy!")
else:
print("buy fail")
I_want_money.buy(Money,ACTIVES,ACTION,expirations_mode)
```

```python
Expand All @@ -422,7 +361,7 @@ I_want_money.buy(Money,ACTIVES,ACTION,expirations)
#ACTIVES:sample input "EURUSD" OR "EURGBP".... you can view by get_all_ACTIVES_OPCODE
#ACTION:"call"/"put" type(str)
#expirations:input minute,careful too large will false to buy(Closed market time)thank Darth-Carrotpie's code (int)https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/6
#return:if sucess return (True,id_number) esle return(Fale,None)
#return:(None/id_number):if sucess return (id_number) esle return(None) 2.1.5 change this
```
#### <a id=buymulti>buy_multi</a>

Expand Down Expand Up @@ -528,11 +467,10 @@ an other way to fix that(implement by get_betinfo)
input by int

```python
from iqoptionapi.stable_api import IQ_Option
I_want_money=IQ_Option("email","password")
check,id = I_want_money.buy(1, "EURUSD", "call", 1)
print("start check win please wait")
print(I_want_money.check_win_v2(id))
I_want_money.check_win_v2(23243221)
#""you need to get id_number from buy function""
#I_want_money.check_win_v2(id_number)
#this function will do loop check your bet until if win/equal/loose
```

---
Expand Down Expand Up @@ -1438,6 +1376,7 @@ I_want_money.change_balance(MODE)

---





8 changes: 0 additions & 8 deletions iqoptionapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ 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,13 +445,6 @@ 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
20 changes: 2 additions & 18 deletions iqoptionapi/stable_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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 @@ -20,7 +19,7 @@ def nested_dict(n, type):


class IQ_Option:
__version__ = "5.2.1"
__version__ = "5.1"

def __init__(self, email, password):
self.size = [1, 5, 10, 15, 30, 60, 120, 300, 600, 900, 1800,
Expand Down Expand Up @@ -564,17 +563,6 @@ 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 @@ -621,10 +609,7 @@ def check_win_v2(self, id_number):
while True:
check, data = self.get_betinfo(id_number)
if check:
try:
return data["result"]["data"][str(id_number)]["win"]
except:
pass
return data["result"]["data"][str(id_number)]["win"]
time.sleep(self.suspend)
# -------------------get infomation only for binary option------------------------

Expand Down Expand Up @@ -877,7 +862,6 @@ 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"]


#___________________/*position*/_________________
instrument_quites_generated_data=self.get_instrument_quites_generated_data(ACTIVES, duration)
Expand Down
2 changes: 1 addition & 1 deletion iqoptionapi/ws/chanels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, api):
"""
self.api = api

def send_websocket_request(self, name, msg,request_id=""):
def send_websocket_request(self, name, msg, request_id=""):
"""Send request to IQ Option server websocket.
:param str name: The websocket chanel name.
Expand Down
70 changes: 19 additions & 51 deletions iqoptionapi/ws/chanels/buyv2.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
"""Module for IQ Option buyV2 websocket chanel."""
import datetime
import time
from iqoptionapi.ws.chanels.base import Base
import logging
from iqoptionapi.expiration import get_expiration_time
from datetime import datetime,timedelta


class Buyv2(Base):
"""Class for IQ option buy websocket chanel."""
# pylint: disable=too-few-public-methods

name = "buyV2"
name = "sendMessage"

def __call__(self, price, active, direction,duration):
"""Method to send message to buyv2 websocket chanel.
Expand All @@ -19,57 +16,28 @@ def __call__(self, price, active, direction,duration):
:param active: The buying active.
:param direction: The buying direction.
"""
# thank Darth-Carrotpie's code
#https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/6

exp,idx=get_expiration_time(int(self.api.timesync.server_timestamp),duration)
exp, idx = get_expiration_time(int(self.api.timesync.server_timestamp),duration)

if idx<5:
option="turbo"
if idx < 5:
option = 3 # turbo
else:
option="binary"


option = 1 # non-turbo / binary

data = {
"price": price,
"act": active,
"exp":int(exp),
"type": option,
"direction": direction.lower(),
"user_balance_id":int(self.api.profile.balance_id),
"time": self.api.timesync.server_timestamp
"name": "binary-options.open-option",
"version": "1.0",
"body": {
"user_balance_id": int(self.api.profile.balance_id),
"active_id": active,
"option_type_id": option,
"direction": direction.lower(),
"expired": int(exp),
"refund_value": 0,
"price": price,
"value": 0, # Preset to 0, don't worry won't affect the actual buy contract
"profit_percent": 0 # IQOption accept any value lower than the actual percent, don't worry it won't affect actual earning
}
}

self.send_websocket_request(self.name, data)

# thank Darth-Carrotpie's code
#https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/6
""" def get_expiration_time(self, duration):
exp=int(self.api.timesync.server_timestamp)
if duration>=1 and duration<=5:
option="turbo"
#Round to next full minute
#datetime.datetime.now().second>30
if (exp % 60) > 30:
exp = exp - (exp % 60) + 60*(duration+1)
else:
exp = exp - (exp % 60)+60*(duration)
elif duration > 5:
option = "binary"
period = int(round(duration / 15))
tmp_exp = exp - (exp % 60)#nuima sekundes
tmp_exp = tmp_exp - (tmp_exp%3600)#nuimam minutes
j=0
while exp > tmp_exp + (j)*15*60:#find quarter
j = j+1
if exp - tmp_exp > 5 * 60:
quarter = tmp_exp + (j)*15*60
exp = quarter + period*15*60
else:
quarter = tmp_exp + (j+1)*15*60
exp = quarter + period*15*60
else:
logging.error("ERROR get_expiration_time DO NOT LESS 1")
exit(1)
return exp, option"""
62 changes: 17 additions & 45 deletions iqoptionapi/ws/chanels/buyv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,31 @@
import logging

from iqoptionapi.expiration import get_expiration_time


class Buyv3(Base):

name = "sendMessage"

def __call__(self, price, active, direction, duration,request_id):

# thank Darth-Carrotpie's code
# https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/6
exp,idx=get_expiration_time(int(self.api.timesync.server_timestamp),duration)
if idx<=5:
option = 3#"turbo"
if idx <= 5:
option = 3 # turbo
else:
option = 1#"binary"
option = 1 # non-turbo / binary
data = {
"body": {"price": price,
"active_id": active,
"expired": int(exp),
"direction": direction.lower(),
"option_type_id":option,
},
"name": "binary-options.open-option",
"version": "1.0"
"version": "1.0",
"body": {
"user_balance_id": int(self.api.profile.balance_id),
"active_id": active,
"option_type_id": option,
"direction": direction.lower(),
"expired": int(exp),
"refund_value": 0,
"price": price,
"value": 0, # Preset to 0, don't worry won't affect the actual buy contract
"profit_percent": 0 # IQOption accept any value lower than the actual percent, don't worry it won't affect actual earning
}
}
self.send_websocket_request(self.name, data,str(request_id))
"""
# thank Darth-Carrotpie's code
# https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/6
def get_expiration_time(self, duration):
exp = time.time()
if duration >= 1 and duration <= 5:
option = 3#"turbo"
# Round to next full minute
# datetime.datetime.now().second>30
if (exp % 60) > 30:
exp = exp - (exp % 60) + 60*(duration+1)
else:
exp = exp - (exp % 60)+60*(duration)
elif duration > 5:
option = 1#"binary"
period = int(round(duration / 15))
tmp_exp = exp - (exp % 60) # nuima sekundes
tmp_exp = tmp_exp - (tmp_exp % 3600) # nuimam minutes
j = 0
while exp > tmp_exp + (j)*15*60: # find quarter
j = j+1
if exp - tmp_exp > 5 * 60:
quarter = tmp_exp + (j)*15*60
exp = quarter + period*15*60
else:
quarter = tmp_exp + (j+1)*15*60
exp = quarter + period*15*60
else:
logging.error("ERROR get_expiration_time DO NOT LESS 1")
exit(1)
return exp, option
"""
Loading

0 comments on commit b7b8dbb

Please sign in to comment.