Skip to content

Commit

Permalink
5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Lu-Yi-Hsun committed Nov 4, 2019
1 parent 230b298 commit 041a7c9
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 4 deletions.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@

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

last update:2019/10/31
last update:2019/11/4

Version:5.0

please donate >< get_digital_spot_profit_after_sale pay me lot of time

https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/125

add [get_digital_spot_profit_after_sale](#getdigitalspotprofitaftersale) api

Version:4.5

Expand Down Expand Up @@ -633,6 +641,29 @@ amount=1
action="call"#put
print(I_want_money.buy_digital_spot(ACTIVES,amount,action,duration))
```

#### <a id=getdigitalspotprofitaftersale>get_digital_spot_profit_after_sale</a>

get Profit After Sale(P/L)
![](image/profit_after_sale.png)
```python
from iqoptionapi.stable_api import IQ_Option
I_want_money=IQ_Option("email","passord")
ACTIVES="EURUSD"
duration=1#minute 1 or 5
amount=100
action="put"#put

I_want_money.subscribe_strike_list(ACTIVES,duration)
id=I_want_money.buy_digital_spot(ACTIVES,amount,action,duration)

while True:
PL=I_want_money.get_digital_spot_profit_after_sale(id)
if PL!=None:
print(PL)

```

#### <a id=getdigitalcurrentprofit>get_digital_current_profit</a>

get current price profit
Expand Down
Binary file added image/profit_after_sale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 87 additions & 1 deletion iqoptionapi/stable_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def nested_dict(n, type):


class IQ_Option:
__version__ = "4.5"
__version__ = "5.0"

def __init__(self, email, password):
self.size = [1, 5, 10, 15, 30, 60, 120, 300, 600, 900, 1800,
Expand All @@ -32,6 +32,7 @@ def __init__(self, email, password):
self.subscribe_candle_all_size = []
self.subscribe_mood = []
# for digit
self.get_digital_spot_profit_after_sale_data=nested_dict(2,int)
self.get_realtime_strike_list_temp_data = {}
self.get_realtime_strike_list_temp_expiration = 0
#
Expand Down Expand Up @@ -822,7 +823,92 @@ def buy_digital_spot(self, active,amount, action, duration):
pass

return self.api.digital_option_placed_id
def get_digital_spot_profit_after_sale(self,position_id):
def get_instrument_id_to_bid(data,instrument_id):
for row in data["msg"]["quotes"]:
if row["symbols"][0]==instrument_id:
return row["price"]["bid"]
return None
#Author:Lu-Yi-Hsun 2019/11/04
#email:[email protected]
#Source code reference
#https://github.com/Lu-Yi-Hsun/Decompiler-IQ-Option/blob/master/Source%20Code/5.27.0/sources/com/iqoption/dto/entity/position/Position.java#L564
while self.get_async_order(position_id)==None:
pass
#___________________/*position*/_________________
position=self.get_async_order(position_id)
#doEURUSD201911040628PT1MPSPT
#z mean check if call or not
if position["instrument_id"].find("MPSPT"):
z=False
elif position["instrument_id"].find("MCSPT"):
z=True
else:
logging.error('get_digital_spot_profit_after_sale position error'+str(position["instrument_id"]))
ACTIVES=position["instrument_underlying"]
amount=max(position["buy_amount"],position["sell_amount"])
start_duration=position["instrument_id"].find("PT")+2
end_duration=start_duration+position["instrument_id"][start_duration:].find("M")

duration=int(position["instrument_id"][start_duration:end_duration])
z2=False


getAbsCount=position["count"]
instrumentStrikeValue=position["instrument_strike_value"]/1000000.0
spotLowerInstrumentStrike=position["extra_data"]["lower_instrument_strike"]/1000000.0
spotUpperInstrumentStrike=position["extra_data"]["upper_instrument_strike"]/1000000.0

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)

f_tmp=get_instrument_id_to_bid(instrument_quites_generated_data,aVar)#https://github.com/Lu-Yi-Hsun/Decompiler-IQ-Option/blob/master/Source%20Code/5.5.1/sources/com/iqoption/dto/entity/position/Position.java#L493
#f is bidprice of lower_instrument_id ,f2 is bidprice of upper_instrument_id
if f_tmp!=None:
self.get_digital_spot_profit_after_sale_data[position_id]["f"]=f_tmp
f=f_tmp
else:
f=self.get_digital_spot_profit_after_sale_data[position_id]["f"]

f2_tmp=get_instrument_id_to_bid(instrument_quites_generated_data,aVar2)
if f2_tmp!=None:
self.get_digital_spot_profit_after_sale_data[position_id]["f2"]=f2_tmp
f2=f2_tmp
else:
f2=self.get_digital_spot_profit_after_sale_data[position_id]["f2"]

if (spotLowerInstrumentStrike != instrumentStrikeValue) and f!=None and f2 !=None:

if (spotLowerInstrumentStrike > instrumentStrikeValue or instrumentStrikeValue > spotUpperInstrumentStrike):
if z:
instrumentStrikeValue = (spotUpperInstrumentStrike - instrumentStrikeValue) / abs(spotUpperInstrumentStrike - spotLowerInstrumentStrike);
f = abs(f2 - f);
else:
instrumentStrikeValue = (instrumentStrikeValue - spotUpperInstrumentStrike) / abs(spotUpperInstrumentStrike - spotLowerInstrumentStrike);
f = abs(f2 - f);

elif z:
f += ((instrumentStrikeValue - spotLowerInstrumentStrike) / (spotUpperInstrumentStrike - spotLowerInstrumentStrike)) * (f2 - f);
else:
instrumentStrikeValue = (spotUpperInstrumentStrike - instrumentStrikeValue) / (spotUpperInstrumentStrike - spotLowerInstrumentStrike);
f -= f2;
f = f2 + (instrumentStrikeValue * f)

if z2:
pass
if f !=None:
#price=f/getRate
#https://github.com/Lu-Yi-Hsun/Decompiler-IQ-Option/blob/master/Source%20Code/5.27.0/sources/com/iqoption/dto/entity/position/Position.java#L603
price=(f/getRate)
#getAbsCount Reference
#https://github.com/Lu-Yi-Hsun/Decompiler-IQ-Option/blob/master/Source%20Code/5.27.0/sources/com/iqoption/dto/entity/position/Position.java#L450
return price*getAbsCount-amount
else:
return None
def buy_digital(self, amount, instrument_id):
self.api.digital_option_placed_id=None
self.api.place_digital_option(instrument_id,amount)
Expand Down
2 changes: 1 addition & 1 deletion iqoptionapi/ws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def on_message(self, message): # pylint: disable=unused-argument
ans={}
for data in message["msg"]["quotes"]:
#FROM IQ OPTION SOURCE CODE
#https://github.com/Lu-Yi-Hsun/Decompiler-IQ-Option/blob/128b30afdf65037f11a0ed52216549c065cb4fbe/Source%20Code/sources/com/iqoption/dto/entity/strike/Quote.java#L91
#https://github.com/Lu-Yi-Hsun/Decompiler-IQ-Option/blob/master/Source%20Code/5.5.1/sources/com/iqoption/dto/entity/strike/Quote.java#L91
if data["price"]["ask"]==None:
ProfitPercent=None
else:
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="4.5",
version="5.0",
packages=find_packages(),
install_requires=["pylint","requests","websocket-client==0.56"],
include_package_data = True,
Expand Down

0 comments on commit 041a7c9

Please sign in to comment.