harwee / IQOption-Api

** Unmaintained ** I have rewritten some of the functionality using async if you are want to use the updated code you can use the code from `async` branch
Apache License 2.0
53 stars 54 forks source link

How to get all trades win / losses #10

Closed zmedia786 closed 5 years ago

zmedia786 commented 6 years ago

Hello i want to get the recent trades if they are won or lost and also the amount. If you can kindly help me.

SeanStayn commented 6 years ago

You can add this function to the api.py file:

def get_position_history(self, instrument_type=""):
        if instrument_type != "":
            self.send_socket_message("sendMessage", {"name": "get-position-history", "version": "1.0", "body": {"user_balance_id": self.active_account_id, "instrument_type": instrument_type}})
            return
        for instrument_type in self.instruments_categories:
            self.send_socket_message("sendMessage", {"name": "get-position-history", "version": "1.0", "body": {"user_balance_id": self.active_account_id, "instrument_type": instrument_type}})

In def on_socket_message(self, socket, message): you can add:

elif messagename == "position-history":
            self.parse_position_history_message(msg)

And you can parse the messages like this:

def parse_position_history_message(self, message):
        if message['total'] != 0:
            #historyAsPositionObjectsDict = {}
            #for histPos in message['history']:
            #    historyAsPositionObjectsDict[histPos['id']] = Position(histPos)
            #self.position_history[message['history'][0]['instrument_type']] = historyAsPositionObjectsDict

            self.position_history[message['history'][0]['instrument_type']] = message['history']

With this, you will get an dict which contains on the first level the instrument_type (forex,cfd,...) and on the next level the positions..

This is the history which you can see in the iqoption traderoom.. If you want the complete history, you should wrap this page: https://eu.iqoption.com/de/trading

cdgn-coding commented 5 years ago

is this issue being taken?