Skip to content

Commit

Permalink
Add functionality in order to check if a trade was won or not accordi…
Browse files Browse the repository at this point in the history
…ng to: #17
  • Loading branch information
jacekv authored and n1nj4z33 committed Jan 13, 2018
1 parent 928300b commit 545aeeb
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,16 @@ pip install iqoptionapi
time.sleep(0.5)


Check if a trade has been won or lost:
ou can give the result by using the 'win' variable which returns either 'equal' (if the trade is ongoing or a draw), 'win' (if the trade was a win), or 'loose' (if the trade was a loss)

self.api.listinfodata.current_listinfodata.win

or

self.api.listinfodata.get_listinfodata(foo)

For more information on what you can actually get, you can use this JSON data that I've extracted myself while testing.

"name":"listInfoData","msg":[{"amount":1000000,"id":2095724656,"refund":0,"currency":"USD","currency_char":"$","active_id":1,"active":"EURUSD","value":1.07736,"exp_value":1077360,"dir":"call","created":1489706346,"expired":1489706400,"type_name":"turbo","type":"front.TU","profit":100,"profit_amount":1,"win_amount":1.74,"loose_amount":0,"sum":1,"win":"equal","now":1489706346,"user_id":0,"game_state":0,"profit_income":174,"profit_return":0,"option_type_id":3,"site_id":1,"is_demo":false,"user_balance_id":0,"client_platform_id":9,"re_track":"null","params":null}]}

2 changes: 2 additions & 0 deletions iqoptionapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from iqoptionapi.ws.objects.timesync import TimeSync
from iqoptionapi.ws.objects.profile import Profile
from iqoptionapi.ws.objects.candles import Candles
from iqoptionapi.ws.objects.listinfodata import ListInfoData


# InsecureRequestWarning: Unverified HTTPS request is being made.
Expand All @@ -42,6 +43,7 @@ class IQOptionAPI(object):
timesync = TimeSync()
profile = Profile()
candles = Candles()
listinfodata = ListInfoData()

def __init__(self, host, username, password, proxies=None):
"""
Expand Down
5 changes: 5 additions & 0 deletions iqoptionapi/ws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def on_message(self, wss, message): # pylint: disable=unused-argument
if message["name"] == "candles":
self.api.candles.candles_data = message["msg"]["data"]

if message["name"] == "listInfoData":
listinfodata = lambda: None
listinfodata.__dict__ = message["msg"][0]
self.api.listinfodata.add_listinfodata(listinfodata)

@staticmethod
def on_error(wss, error): # pylint: disable=unused-argument
"""Method to process websocket errors."""
Expand Down
46 changes: 46 additions & 0 deletions iqoptionapi/ws/objects/listinfodata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Module for IQ Option Candles websocket object."""
import json

from collections import OrderedDict

from iqoptionapi.ws.objects.base import Base


class ListInfoData(Base):
def __init__(self):
super(ListInfoData, self).__init__()
self.__name = "listInfoData"
self.__listinfodata_list = OrderedDict()

@property
def listinfodata_list(self):
"""Property to get listinfodata list.
:returns: The list of listinfodata.
"""
return self.__listinfodata_list

@listinfodata_list.setter
def listinfodata_list(self, listinfodata_list):
"""Method to set listinfodata list."""
self.__listinfodata_list = listinfodata_list

@property
def current_listinfodata(self):
"""Method to get current iteminfodata item.
:returns: The object of listinfodata.
"""
return self.listinfodata_list[next(reversed(self.listinfodata_list))]

def get_listinfodata(self, id):
"""Method to get iteminfodata item.
:returns: The object of listinfodata.
"""
return self.listinfodata_list[id]

def add_listinfodata(self, new_listinfodata):
"""Method to add listinfodata."""
#if new_listinfodata.id not in self.listinfodata_list:
self.listinfodata_list[new_listinfodata.id] = new_listinfodata

0 comments on commit 545aeeb

Please sign in to comment.