From 61f77b435abb4f410a7f6fea41000f8b5ae6f166 Mon Sep 17 00:00:00 2001 From: lu-yi-hsun Date: Mon, 9 Sep 2019 21:25:45 +0800 Subject: [PATCH] add get_position_history_v2 --- README.md | 37 ++++++++++++++++++++++++- iqoptionapi/api.py | 26 +++++++++-------- iqoptionapi/stable_api.py | 12 ++++++++ iqoptionapi/ws/chanels/get_positions.py | 15 ++++++++++ iqoptionapi/ws/client.py | 2 ++ 5 files changed, 80 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1635cefe..448be7ac 100644 --- a/README.md +++ b/README.md @@ -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 @@ -792,7 +793,41 @@ return (True/False,position_history,None) ```python I_want_money.get_position_history(instrument_type) ``` +#### get_position_history_v2 + +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 diff --git a/iqoptionapi/api.py b/iqoptionapi/api.py index 87bd4c63..5e939934 100644 --- a/iqoptionapi/api.py +++ b/iqoptionapi/api.py @@ -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 @@ -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 @@ -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 @@ -393,19 +395,18 @@ 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)} - } + } } ) ) @@ -413,8 +414,8 @@ def subscribe_position_changed(self,name,instrument_type,request_id): 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), @@ -428,7 +429,6 @@ def setOptions(self,request_id,sendResults): # -------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------- - @property def setactives(self): """Property for get IQ Option websocket setactives chanel. @@ -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) @@ -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) diff --git a/iqoptionapi/stable_api.py b/iqoptionapi/stable_api.py index cce4bbef..1a4818b5 100644 --- a/iqoptionapi/stable_api.py +++ b/iqoptionapi/stable_api.py @@ -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( diff --git a/iqoptionapi/ws/chanels/get_positions.py b/iqoptionapi/ws/chanels/get_positions.py index da8d3a0a..ea760306 100644 --- a/iqoptionapi/ws/chanels/get_positions.py +++ b/iqoptionapi/ws/chanels/get_positions.py @@ -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) \ No newline at end of file diff --git a/iqoptionapi/ws/client.py b/iqoptionapi/ws/client.py index 7612747b..78ee7593 100644 --- a/iqoptionapi/ws/client.py +++ b/iqoptionapi/ws/client.py @@ -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":