Skip to content

Commit

Permalink
add get_position_history_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Lu-Yi-Hsun committed Sep 9, 2019
1 parent 31af01d commit 61f77b4
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 12 deletions.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Version:3.8
[Check Asset if open or not](#checkopen)

[fix digital check win](#checkwindigitalv2)


[better !! get_position_history_v2](#getpositionhistoryv2)


Version:3.7
Expand Down Expand Up @@ -792,7 +793,41 @@ return (True/False,position_history,None)
```python
I_want_money.get_position_history(instrument_type)
```
#### <a id=getpositionhistoryv2>get_position_history_v2</a>

instrument_type="crypto","forex","fx-option","turbo-option","multi-option","cfd","digital-option"

get_position_history_v2(instrument_type,limit,offset,start,end)

```python
from iqoptionapi.stable_api import IQ_Option
import logging
import random
import time
import datetime
logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(message)s')
I_want_money=IQ_Option("email","password")

#instrument_type="crypto","forex","fx-option","turbo-option","multi-option","cfd","digital-option"
instrument_type="digital-option"
limit=2#How many you want to get
offset=0#offset from end time,if end time is 0,it mean get the data from now
start=0#start time Timestamp
end=0#Timestamp
data=I_want_money.get_position_history_v2(instrument_type,limit,offset,start,end)

print(data)

#--------- this will get data start from 2019/7/1(end) to 2019/1/1(start) and only get 2(limit) data and offset is 0
instrument_type="digital-option"
limit=2#How many you want to get
offset=0#offset from end time,if end time is 0,it mean get the data from now
start=int(time.mktime(datetime.datetime.strptime("2019/1/1", "%Y/%m/%d").timetuple()))
end=int(time.mktime(datetime.datetime.strptime("2019/7/1", "%Y/%m/%d").timetuple()))
data=I_want_money.get_position_history_v2(instrument_type,limit,offset,start,end)
print(data)

```

#### get_available_leverages

Expand Down
26 changes: 15 additions & 11 deletions iqoptionapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from iqoptionapi.ws.chanels.get_positions import Get_positions
from iqoptionapi.ws.chanels.get_positions import Get_position
from iqoptionapi.ws.chanels.get_positions import Get_position_history
from iqoptionapi.ws.chanels.get_positions import Get_position_history_v2
from iqoptionapi.ws.chanels.get_available_leverages import Get_available_leverages
from iqoptionapi.ws.chanels.cancel_order import Cancel_order
from iqoptionapi.ws.chanels.close_position import Close_position
Expand Down Expand Up @@ -94,7 +95,7 @@ class IQOptionAPI(object): # pylint: disable=too-many-instance-attributes
instrument_quites_generated_data = nested_dict(2, dict)
instrument_quites_generated_timestamp = nested_dict(2, dict)
strike_list = None
position_changed_data={}
position_changed_data = {}
game_betinfo = Game_betinfo_data()
instruments = None
financial_information = None
Expand All @@ -106,6 +107,7 @@ class IQOptionAPI(object): # pylint: disable=too-many-instance-attributes
position = None
deferred_orders = None
position_history = None
position_history_v2 = None
available_leverages = None
order_canceled = None
close_position_data = None
Expand Down Expand Up @@ -393,28 +395,27 @@ def unsubscribe(self):
def unsubscribe_all_size(self):
return Unsubscribe_candles(self)


def subscribe_position_changed(self,name,instrument_type,request_id):
#instrument_type="multi-option","crypto","forex","cfd"
#name="position-changed","trading-fx-option.position-changed",digital-options.position-changed
def subscribe_position_changed(self, name, instrument_type, request_id):
# instrument_type="multi-option","crypto","forex","cfd"
# name="position-changed","trading-fx-option.position-changed",digital-options.position-changed
logger = logging.getLogger(__name__)
data = json.dumps(dict(name="subscribeMessage",
request_id=str(request_id),
msg={"name": name,
"version": "1.0",
"params": {
"routingFilters":{"instrument_type":str(instrument_type)}
"routingFilters": {"instrument_type": str(instrument_type)}

}
}
}
)
)

logger.debug(data)
self.websocket.send(data)

def setOptions(self,request_id,sendResults):
#sendResults True/False
def setOptions(self, request_id, sendResults):
# sendResults True/False
logger = logging.getLogger(__name__)
data = json.dumps(dict(name="setOptions",
request_id=str(request_id),
Expand All @@ -428,7 +429,6 @@ def setOptions(self,request_id,sendResults):
# --------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------


@property
def setactives(self):
"""Property for get IQ Option websocket setactives chanel.
Expand All @@ -449,7 +449,7 @@ def getcandles(self):

def get_api_option_init_all(self):
logger = logging.getLogger(__name__)

data = json.dumps(dict(name="api_option_init_all",
msg=""))
logger.debug(data)
Expand Down Expand Up @@ -558,6 +558,10 @@ def get_position(self):
def get_position_history(self):
return Get_position_history(self)

@property
def get_position_history_v2(self):
return Get_position_history_v2(self)

@property
def get_available_leverages(self):
return Get_available_leverages(self)
Expand Down
12 changes: 12 additions & 0 deletions iqoptionapi/stable_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,18 @@ def get_position_history(self, instrument_type):
else:
return False, None

def get_position_history_v2(self, instrument_type,limit,offset,start,end):
#instrument_type=crypto forex fx-option multi-option cfd digital-option turbo-option
self.api.position_history_v2 = None
self.api.get_position_history_v2(instrument_type,limit,offset,start,end)
while self.api.position_history_v2 == None:
pass

if self.api.position_history_v2["status"] == 2000:
return True, self.api.position_history_v2["msg"]
else:
return False, None

def get_available_leverages(self, instrument_type, actives):
self.api.available_leverages = None
self.api.get_available_leverages(
Expand Down
15 changes: 15 additions & 0 deletions iqoptionapi/ws/chanels/get_positions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,19 @@ def __call__(self,instrument_type):
}
self.send_websocket_request(self.name, data)

class Get_position_history_v2(Base):
name = "sendMessage"
def __call__(self,instrument_types,limit,offset,start=0,end=0):
data = {
"name":"portfolio.get-history-positions",
"body":{
"instrument_types":[instrument_types],
"limit":limit,
"offset":offset,
"start":start,
"end":end,
"user_balance_id":int(self.api.profile.balance_id)
}
}
self.send_websocket_request(self.name, data)

2 changes: 2 additions & 0 deletions iqoptionapi/ws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ def on_message(self, wss, message): # pylint: disable=unused-argument

elif message["name"]=="position-history":
self.api.position_history=message
elif message["name"]=="history-positions":
self.api.position_history_v2=message
elif message["name"]=="available-leverages":
self.api.available_leverages=message
elif message["name"]=="order-canceled":
Expand Down

0 comments on commit 61f77b4

Please sign in to comment.