Skip to content

Commit

Permalink
v3.7 strike list&current price
Browse files Browse the repository at this point in the history
  • Loading branch information
Lu-Yi-Hsun committed Aug 12, 2019
1 parent d5fcd68 commit 3f8de22
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 20 deletions.
40 changes: 30 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

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

last Version:3.6.4
last Version:3.7

last update:2019/4/27
last update:2019/8/13

version 3.6.4

[add multi buy function](#buymulti)
[buy current price](#buydigitalspot)

[change strike_list api](#strikelist)
need duration time
```python
subscribe_strike_list(ACTIVES,duration)
unsubscribe_strike_list(ACTIVES,duration)
```
---
## About API

Expand Down Expand Up @@ -387,7 +391,7 @@ I_want_money=IQ_Option("email","password")
ACTIVES="EURUSD"
duration=1#minute 1 or 5
amount=1
I_want_money.subscribe_strike_list(ACTIVES)
I_want_money.subscribe_strike_list(ACTIVES,duration)
#get strike_list
data=I_want_money.get_realtime_strike_list(ACTIVES, duration)
print("get strike data")
Expand Down Expand Up @@ -429,11 +433,11 @@ if buy_check:
else:
print("you loose")
break
I_want_money.unsubscribe_strike_list(ACTIVES)
I_want_money.unsubscribe_strike_list(ACTIVES,duration)
else:
print("fail to buy,please run again")
```
#### Get all strike list data
#### <a id=strikelist>Get all strike list data</a>

##### Data format

Expand All @@ -450,13 +454,29 @@ import time
I_want_money=IQ_Option("email","password")
ACTIVES="EURUSD"
duration=1#minute 1 or 5
I_want_money.subscribe_strike_list(ACTIVES)
I_want_money.subscribe_strike_list(ACTIVES,duration)
while True:
data=I_want_money.get_realtime_strike_list(ACTIVES, duration)
for price in data:
print("price",price,data[price])
time.sleep(5)
I_want_money.unsubscribe_strike_list(ACTIVES)
I_want_money.unsubscribe_strike_list(ACTIVES,duration)
```

#### <a id=buydigitalspot>buy_digital_spot</a>

buy the digit in current price

```python
from iqoptionapi.stable_api import IQ_Option

I_want_money=IQ_Option("email","password")

ACTIVES="EURUSD"
duration=1#minute 1 or 5
amount=1
action="call"#put
print(I_want_money.buy_digital_spot(ACTIVES,amount,action,duration))
```

#### Buy digit
Expand Down
8 changes: 6 additions & 2 deletions iqoptionapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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.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 @@ -110,6 +110,8 @@ class IQOptionAPI(object): # pylint: disable=too-many-instance-attributes
close_position_data=None
overnight_fee=None
#---for real time
digital_option_placed_id=None

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 @@ -445,7 +447,9 @@ def subscribe_instrument_quites_generated(self):
def unsubscribe_instrument_quites_generated(self):
return Unsubscribe_Instrument_Quites_Generated(self)


@property
def place_digital_option(self):
return Digital_options_place_digital_option(self)

#____BUY_for__Forex__&&__stock(cfd)__&&__ctrpto_____
@property
Expand Down
38 changes: 33 additions & 5 deletions iqoptionapi/stable_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import time
import logging
import operator
import datetime
import pytz
from collections import defaultdict


Expand All @@ -16,7 +18,7 @@ def nested_dict(n, type):


class IQ_Option:
__version__ = "3.6.4"
__version__ = "3.7"

def __init__(self, email, password):
self.size = [1, 5, 10, 15, 30, 60, 120, 300, 600, 900, 1800,
Expand Down Expand Up @@ -632,12 +634,12 @@ def get_strike_list(self, ACTIVES, duration):
return self.api.strike_list, None
return self.api.strike_list, ans

def subscribe_strike_list(self, ACTIVE):
self.api.subscribe_instrument_quites_generated(ACTIVE)
def subscribe_strike_list(self, ACTIVE,expiration_period):
self.api.subscribe_instrument_quites_generated(ACTIVE,expiration_period)

def unsubscribe_strike_list(self, ACTIVE):
def unsubscribe_strike_list(self, ACTIVE,expiration_period):
del self.api.instrument_quites_generated_data[ACTIVE]
self.api.unsubscribe_instrument_quites_generated(ACTIVE)
self.api.unsubscribe_instrument_quites_generated(ACTIVE,expiration_period)

def get_realtime_strike_list(self, ACTIVE, duration):
while True:
Expand Down Expand Up @@ -674,6 +676,32 @@ def get_realtime_strike_list(self, ACTIVE, duration):
pass

return ans
#thank thiagottjv
#https://github.com/Lu-Yi-Hsun/iqoptionapi/issues/65#issuecomment-513998357
def buy_digital_spot(self, active,amount, action, duration):
#Expiration time need to be formatted like this: YYYYMMDDHHII
#And need to be on GMT time

UTC=datetime.datetime.utcnow()
dateFormated = str(UTC.strftime("%Y%m%d%H"))+str(int(UTC.strftime("%M"))+duration )

#Type - P or C
if action == 'put':
action = 'P'
elif action=='call':
action = 'C'
else:
logging.error('buy_digital_spot active error')
return -1
#doEURUSD201907191250PT5MPSPT
instrument_id = "do" + active + dateFormated + "PT" + str(duration) + "M" + action + "SPT"
self.api.digital_option_placed_id=None

self.api.place_digital_option(instrument_id,amount)
while self.api.digital_option_placed_id==None:
pass

return self.api.digital_option_placed_id

def buy_digital(self, amount, instrument_id):
self.api.position_changed = None
Expand Down
23 changes: 23 additions & 0 deletions iqoptionapi/ws/chanels/digital_option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#python

import datetime
import time
from iqoptionapi.ws.chanels.base import Base

#work for forex digit cfd(stock)

class Digital_options_place_digital_option(Base):
name = "sendMessage"
def __call__(self,instrument_id,amount):
data = {
"name": "digital-options.place-digital-option",
"version":"1.0",
"body":{
"user_balance_id":int(self.api.profile.balance_id),
"instrument_id":str(instrument_id),
"amount":str(amount)

}
}
self.send_websocket_request(self.name, data)

3 changes: 2 additions & 1 deletion iqoptionapi/ws/chanels/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ def __call__(self, active_id):
class Subscribe_Instrument_Quites_Generated(Base):
name = "subscribeMessage"

def __call__(self,ACTIVE):
def __call__(self,ACTIVE,expiration_period):
data = {
"name": "instrument-quotes-generated",
"params":{
"routingFilters":{
"active":int(OP_code.ACTIVES[ACTIVE]),
"expiration_period":int(expiration_period*60),
"kind":"digital-option",

},
Expand Down
3 changes: 2 additions & 1 deletion iqoptionapi/ws/chanels/unsubscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ def __call__(self, active_id,size=1):
class Unsubscribe_Instrument_Quites_Generated(Base):
name = "unsubscribeMessage"

def __call__(self,ACTIVE):
def __call__(self,ACTIVE,expiration_period):
data = {
"name": "instrument-quotes-generated",
"params":{
"routingFilters":{
"active":int(OP_code.ACTIVES[ACTIVE]),
"expiration_period":int(expiration_period*60),
"kind":"digital-option",
},
},
Expand Down
6 changes: 6 additions & 0 deletions iqoptionapi/ws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ def on_message(self, wss, message): # pylint: disable=unused-argument
self.api.position_changed=message
elif message["name"]=="auto-margin-call-changed":
self.api.auto_margin_call_changed_respond=message
elif message["name"]=="digital-option-placed":
try:
self.api.digital_option_placed_id=message["msg"]["id"]
except:
self.api.digital_option_placed_id="error"

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
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="3.6.4",
version="3.7",
packages=find_packages(),
install_requires=["pylint","requests","websocket-client==0.47"],
include_package_data = True,
Expand Down

0 comments on commit 3f8de22

Please sign in to comment.