Giter VIP home page Giter VIP logo

trading-ig's People

Contributors

9gix avatar agijsberts avatar alex1443 avatar bug-or-feature avatar byod0 avatar chiragchhatbar avatar cipher099 avatar dave-vallance avatar dfaligertwood avatar doggyeh avatar dsdinter avatar esteban108 avatar falex69 avatar femtotrader avatar filco306 avatar hklang10 avatar hodeig avatar langlej avatar oliverpolden avatar oneirag avatar redbullpeter avatar robert-john-small avatar rrmxkun avatar sacharbit avatar schwarzkopf avatar skilty avatar szymonwartak avatar xnox avatar zansibal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trading-ig's Issues

Use weswit/lightstreamer python lib instead of igls.py

igls.py from https://github.com/dw/py-lightstreamer/
doesn't seems to be active

If https://github.com/Weswit/Lightstreamer-example-StockList-client-python was a library (which is not for now) it could become possible to do something like

#!/usr/bin/env python
#-*- coding:utf-8 -*-

"""
IG Markets Stream API with Python
2015 FemtoTrader
"""

import sys
import traceback
import logging
from lightstreamer import LSClient, Subscription, compat

import time

from trading_ig import IGService
from trading_ig.config import ConfigEnvVar
#from trading_ig_config import config

# A simple function acting as a Subscription listener
def on_price_update(item_update):
    #print("price: %s " % item_update)
    print("{stock_name:<19}: Time {UPDATE_TIME:<8} - "
          "Bid {BID:>5} - Ask {OFFER:>5}".format(stock_name=item_update["name"], **item_update["values"]))

def on_balance_update(balance_update):
    print("balance: %s " % balance_update)

def main():
    logging.basicConfig(level=logging.INFO)
    #logging.basicConfig(level=logging.DEBUG)

    config = ConfigEnvVar("IG_SERVICE")
    ig_service = IGService(config.username, config.password, config.api_key, config.acc_type)
    ig_session = ig_service.create_session()
    cst = ig_service.crud_session.CLIENT_TOKEN
    xsecuritytoken = ig_service.crud_session.SECURITY_TOKEN
    lightstreamerEndpoint = ig_session[u'lightstreamerEndpoint']
    clientId = ig_session[u'clientId']
    accounts = ig_session[u'accounts']
    # Depending on how many accounts you have with IG the '0' may need to change to select the correct one (spread bet, CFD account etc)
    accountId = accounts[0][u'accountId']
    password = 'CST-%s|XST-%s' % (cst, xsecuritytoken)

    # Establishing a new connection to Lightstreamer Server
    print("Starting connection with %s" % lightstreamerEndpoint)
    #lightstreamer_client = LSClient("http://localhost:8080", "DEMO")
    #lightstreamer_client = LSClient("http://push.lightstreamer.com", "DEMO")
    lightstreamer_client = LSClient(lightstreamerEndpoint, adapter_set="", user=accountId, password=password)
    try:
        lightstreamer_client.connect()
    except Exception as e:
        print("Unable to connect to Lightstreamer Server")
        print(traceback.format_exc())
        sys.exit(1)

    # Making a new Subscription in MERGE mode
    subscription = Subscription(
        mode="MERGE",
        items=['L1:CS.D.GBPUSD.CFD.IP', 'L1:CS.D.USDJPY.CFD.IP'],
        fields=["UPDATE_TIME", "BID", "OFFER", "CHANGE", "MARKET_STATE"],
        )
        #adapter="QUOTE_ADAPTER")


    # Adding the "on_item_update" function to Subscription
    subscription.addlistener(on_price_update)

    # Registering the Subscription
    sub_key_prices = lightstreamer_client.subscribe(subscription)


    # Making an other Subscription in MERGE mode
    subscription = Subscription(
        mode="MERGE",
        items='ACCOUNT:'+accountId,
        fields=["AVAILABLE_CASH"],
        )
    #    #adapter="QUOTE_ADAPTER")


    # Adding the "on_item_update" function to Subscription
    subscription.addlistener(on_balance_update)

    # Registering the Subscription
    sub_key_balance = lightstreamer_client.subscribe(subscription)

    compat.wait_for_input("{0:-^80}\n".format("HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM \
    LIGHTSTREAMER"))

    # Unsubscribing from Lightstreamer by using the subscription key
    #lightstreamer_client.unsubscribe(sub_key_prices)
    #lightstreamer_client.unsubscribe(sub_key_balance)
    lightstreamer_client.unsubscribe()

    # Disconnecting
    lightstreamer_client.disconnect()

if __name__ == '__main__':
    main()

It displays:

$ python sample/ig_stream.py
WARNING:root:No Bunch support for PY3
Starting connection with https://demo-apd.marketdatasystems.com
L1:CS.D.USDJPY.CFD.IP: Time 21:18:46 - Bid 119.888 - Ask 119.903
L1:CS.D.GBPUSD.CFD.IP: Time 21:18:46 - Bid 1.51192 - Ask 1.51202
----------HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM     LIGHTSTREAMER-----------
L1:CS.D.GBPUSD.CFD.IP: Time 21:18:48 - Bid 1.51193 - Ask 1.51203
L1:CS.D.GBPUSD.CFD.IP: Time 21:18:50 - Bid 1.51194 - Ask 1.51204
L1:CS.D.GBPUSD.CFD.IP: Time 21:18:50 - Bid 1.51193 - Ask 1.51203
L1:CS.D.GBPUSD.CFD.IP: Time 21:18:51 - Bid 1.51193 - Ask 1.51203
L1:CS.D.GBPUSD.CFD.IP: Time 21:18:51 - Bid 1.51195 - Ask 1.51205
L1:CS.D.USDJPY.CFD.IP: Time 21:18:51 - Bid 119.889 - Ask 119.904
L1:CS.D.USDJPY.CFD.IP: Time 21:18:51 - Bid 119.890 - Ask 119.905
L1:CS.D.GBPUSD.CFD.IP: Time 21:18:52 - Bid 1.51194 - Ask 1.51204
L1:CS.D.USDJPY.CFD.IP: Time 21:18:51 - Bid 119.890 - Ask 119.905
L1:CS.D.USDJPY.CFD.IP: Time 21:18:53 - Bid 119.889 - Ask 119.904
L1:CS.D.USDJPY.CFD.IP: Time 21:18:53 - Bid 119.890 - Ask 119.905
L1:CS.D.USDJPY.CFD.IP: Time 21:18:53 - Bid 119.889 - Ask 119.904
L1:CS.D.USDJPY.CFD.IP: Time 21:18:54 - Bid 119.890 - Ask 119.905
L1:CS.D.GBPUSD.CFD.IP: Time 21:18:54 - Bid 1.51196 - Ask 1.51206

Switch account __set_headers

There is a call in the switch account method of the IGService object that calls self.__set_headers()

When I run the example script, I receive the error:

 File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/trading_ig/rest.py", line 958, in switch_account
    self._set_headers(response.headers, False)
AttributeError: 'IGService' object has no attribute '_set_headers'

Am I missing something obvious or is this a bug?

If I comment out the lines:

account_info = ig_service.switch_account(cfd, False) # not necessary
print(account_info)

Then I am able to run the example.

Stream - create in stream.py objects to manage items, fields...

Items:

MARKET, SPRINT_MARKET, ACCOUNT, TRADE, CHARTTICK, CHART

Mode:

MERGE, DISTINCT

https://labs.ig.com/sample-apps/streaming-companion/index.html
https://labs.ig.com/streaming-api-guide

Market price subscription (price availability subject to account permissions)

MARKET
    id: MARKET:{epic}
    mode: MERGE
    fields:
        BID
        OFFER
        HIGH
        LOW
        MID_OPEN
        CHANGE
        CHANGE_PCT
        MARKET_DELAY
        MARKET_STATE
        UPDATE_TIME

Sprint markets

SPRINT_MARKET
    id: MARKET:{epic}
    mode: MERGE
    fields:
        STRIKE_PRICE
        MARKET_STATE
        ODDS

Account subscription

ACCOUNT
    id: ACCOUNT:{accountid}
    mode: MERGE
    fields:
        PNL
        DEPOSIT
        AVAILABLE_CASH
        PNL_LR
        PNL_NLR
        FUNDS
        MARGIN
        MARGIN_LR
        MARGIN_NLR
        AVAILABLE_TO_DEAL
        EQUITY
        EQUITY_USED

An object oriented approach could be to create in stream.py (or somewhere else) objects to manage items, fields...

Trade subscription
TRADE
id: TRADE:{accountid}
mode: DISTINCT
fields:
CONFIRMS
OPU
WOU

Chart subscriptions - Tick data

CHARTTICK
    id: CHART:{epic}:TICK
    mode: DISTINCT
    fields:
        BID
        OFR
        LTP
        LTV
        TTV
        UTM
        DAY_OPEN_MID
        DAY_NET_CHG_MID
        DAY_PERC_CHG_MID
        DAY_HIGH
        DAY_LOW

Chart subscriptions - Consolidated (candle) data

CHART
    id: CHART:{epic}:{scale} (ex: EPIC:SECOND|1MINUTE|5MINUTE|HOUR)
    mode: MERGE
    fields:
        {scale}
        LTV
        TTV
        UTM
        DAY_OPEN_MID
        DAY_NET_CHG_MID
        DAY_PERC_CHG_MID
        DAY_HIGH
        DAY_LOW
        DAY_PERC_CHG_MID
        DAY_HIGH
        DAY_LOW
        OFR_OPEN
        OFR_HIGH
        OFR_LOW
        OFR_CLOSE
        BID_OPEN
        BID_HIGH
        BID_LOW
        BID_CLOSE
        LTP_OPEN
        LTP_HIGH
        LTP_LOW
        LTP_CLOSE
        DAY_LOW
        CONS_END
        CONS_TICK_COUNT

Some epic examples: 'L1:CS.D.GBPUSD.CFD.IP', 'L1:CS.D.USDJPY.CFD.IP'

Maybe using Enum34 could help

Remove trading_ig from PyPi

Maintaining this pip package is a pain

I dream that one day Python ecosystem will have a convenient package management like Julia have.

Comment like #28 (comment)
make me wonder if I shouldn't remove this package from pip

Your opinion?

KeyError: 'snapshotTime' in fetch_historical_prices_by_epic_and_date_range

epic = 'CS.D.EURUSD.MINI.IP'
resolution = 'm'
start_date = datetime.datetime(2017,9,11,9,5,0)
end_date = datetime.datetime(2017,9,11,10,10,0)
response = ig_service.fetch_historical_prices_by_epic_and_date_range(epic, resolution, start_date, end_date)
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 2442, in get_loc
    return self._engine.get_loc(key)
  File "pandas/_libs/index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5280)
  File "pandas/_libs/index.pyx", line 154, in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5126)
  File "pandas/_libs/hashtable_class_helper.pxi", line 1210, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20523)
  File "pandas/_libs/hashtable_class_helper.pxi", line 1218, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20477)
KeyError: 'snapshotTime'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/trading_ig/rest.py", line 836, in fetch_historical_prices_by_epic_and_date_range
    data['prices'] = self.format_prices(data['prices'])
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/trading_ig/rest.py", line 751, in format_prices
    df = df.set_index('snapshotTime')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/frame.py", line 2830, in set_index
    level = frame[col]._values
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/frame.py", line 1964, in __getitem__
    return self._getitem_column(key)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/frame.py", line 1971, in _getitem_column
    return self._get_item_cache(key)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/generic.py", line 1645, in _get_item_cache
    values = self._data.get(item)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/internals.py", line 3590, in get
    loc = self.items.get_loc(item)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 2444, in get_loc
    return self._engine.get_loc(self._maybe_cast_indexer(key))
  File "pandas/_libs/index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5280)
  File "pandas/_libs/index.pyx", line 154, in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5126)
  File "pandas/_libs/hashtable_class_helper.pxi", line 1210, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20523)
  File "pandas/_libs/hashtable_class_helper.pxi", line 1218, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20477)
KeyError: 'snapshotTime'

create_order_position does not include timeInForce parameter

I'm trying to send a market order by using this code:

response = ig_service.create_open_position(currency_code='GBP', direction='BUY', 
                                           epic='IX.D.DOW.MONTH1.IP', expiry='-', 
                                           force_open='false', guaranteed_stop='false', 
                                           level='', limit_distance='', limit_level='', 
                                           order_type='MARKET', quote_id='', size=0.5, 
                                           stop_distance='', stop_level='')

print(response)

I get this response:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<p>Additionally, a 406 Not Acceptable
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>

I think it may be because there is no timeInForce parameter as on IG's API Companion it's one of the parameters that needs to be filled in?

Metaprogramming

Maybe metaprogramming could be a good idea
http://en.wikipedia.org/wiki/Metaprogramming

Example:

/prices/{epic}/{resolution}?startdate={startdate}&enddate={enddate} 

GET 1 Returns a list of historical prices for the given epic, resolution and date range.

endpoint is /prices/{epic}/{resolution}
url_params are epic and resolution. these parameters could be given using a dict.
params are startdate and enddate. these parameters are ever given using a dict.
action is GET (or 'read')
helpis Returns a list of historical prices for the given epic, resolution and date range.
version is 1 (API version number)

After defining a structure for all API data (API v1 and v2) we should be able to reduce code.

Some input parameters (either url_params or params) need to be converted before API call.
Response also need to be converted (convert to DataFrame, or to dict...)

key of dict for url_params doesn't matter as it's an hidden variable but
key of dict for params matters

from: https://github.com/ig-python/ig-markets-rest-api-python-library/issues/6

LSClient._forward_update_message issue with JSON-formatted responses

Hello

Issue is with this bit:

tok = update_message.split(',')
table, item = int(tok[0]), tok[1]

This works for prices where the format is:

1,1|00:06:28|1.08083|1.08089|0.00017|

in which case table is assigned 1, item is assigned '1|00:06:28|1.08083|1.08089|0.00017|' since the | character is unaffected by the split.

However it does not for TRADE, MARKET, etc where the output is instead JSON-like e.g.:

1,1|{"trailingStep":null,"trailingStopDistance":null,"stopLevel":null,"limitLevel":null,"guaranteedStop":false,"currency":"JPY","expiry":"-","dealIdOrigin":"DIAAAAA89UVURAX","direction":"SELL","epic":"","dealId":"","dealReference":"","dealStatus":"ACCEPTED","level":111.576,"status":"DELETED","size":0,"channel":"WEB","timestamp":"2017-03-21T23:44:27.177"}

As a consequence the split will turn the string into a list with multiple rows, and tok[1] will only hold (in this example) the following:
1|{"trailingStep":null

The rest of the information is lost.

Proposed fix: only split the first comma, leave rest of the string as is:
tok = update_message.split(',', 1)

This will not affect prices and resolve the issue. It is also compatible with Python 2 and 3.

Tested/reg-tested locally

Thanks

Drop Python 2.7 support?

Is there still people using Python 2.7 and this library?

Now, I only use Python 3 so we should consider dropping Python 2.7 support.

Any comment?

error.public-api.failure.encryption.required

Hi, in following the examples:

from trading_ig import IGService
from trading_ig_config import Config as config

ig_service = IGService(config.username, config.password, config.api_key, config.acc_type)
print(ig_service)
ig_service.create_session()

i'm getting the following error:

Traceback (most recent call last):
  File "C:/Users/kwtne_000/PycharmProjects/dtr2/data_ig.py", line 6, in <module>
    ig_service.create_session()
  File "C:\Python27\lib\site-packages\trading_ig\rest.py", line 945, in create_session
    response = self._req(action, endpoint, params, session)
  File "C:\Python27\lib\site-packages\trading_ig\rest.py", line 205, in _req
    response = self.crud_session.req(action, endpoint, params, session)
  File "C:\Python27\lib\site-packages\trading_ig\rest.py", line 121, in req
    return d_actions[action](endpoint, params, session)
  File "C:\Python27\lib\site-packages\trading_ig\rest.py", line 72, in _create_first
    self._set_headers(response.headers, True)
  File "C:\Python27\lib\site-packages\trading_ig\rest.py", line 127, in _set_headers
    self.CLIENT_TOKEN = response_headers['CST']
  File "C:\Python27\lib\site-packages\requests\structures.py", line 54, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'cst'

And when i include and if statement in rest.py that checks for 'CST',
like so:

            if 'CST' in response_headers:
                self.CLIENT_TOKEN = response_headers['CST']

My error changes to:

Traceback (most recent call last):
  File "C:/Users/kwtne_000/PycharmProjects/dtr2/data_ig.py", line 6, in <module>
    ig_service.create_session()
  File "C:\Python27\lib\site-packages\trading_ig\rest.py", line 946, in create_session
    data = self.parse_response(response.text)
  File "C:\Python27\lib\site-packages\trading_ig\rest.py", line 223, in parse_response_with_exception
    raise(Exception(response['errorCode']))
Exception: error.public-api.failure.encryption.required

any idea what i'm doing wrong?
credentials are working in the companion app.

Params error in REST create_open_position

With the current code, when using the create_open_position function from REST API, i have the following error:

    {"errorCode":"Failed to de-serialize entity [mediaType=application/json]"}

I solved the issue commenting the following lines in the positions params order:

        params = {
            'currencyCode': currency_code,
            'direction': direction,
            'epic': epic,
            'expiry': expiry,
            'forceOpen': force_open,
            'guaranteedStop': guaranteed_stop,
            'level': level,
            'limitDistance': limit_distance,
            'limitLevel': limit_level,
            'orderType': order_type,
            'quoteId': quote_id,
            'size': size,
            'stopDistance': stop_distance,
            'stopLevel': stop_level#,
            #'timeInForce': None,
            #'trailingStop': None,
            #'trailingStopIncrement': None

        }

Python 3 support

There is no Python 3 support for now

$ python --version
Python 3.4.3 :: Anaconda 2.3.0 (x86_64)

$ python sample.py
Traceback (most recent call last):
  File "sample.py", line 6, in <module>
    import igls,requests,json, time
  File "/Users/femto/ig-markets-stream-api-python-library/igls.py", line 425
    except urllib2.HTTPError, e:
                            ^
SyntaxError: invalid syntax

crash if price enquiry returns no data(empty set)

Currently, format_prices() is called unconditionally after the query is returned from the api.

This causes a traceback because the code cannot handle an empty set. see #59 for example.

I currently get:

epic = 'CS.D.EURUSD.MINI.IP'
resolution = '2H'
start_date = datetime.datetime(2017,9,11,9,0,0)
end_date = datetime.datetime(2017,9,11,9,1,0)
response = ig_service.fetch_historical_prices_by_epic_and_date_range(epic, resolution, start_date, end_date)
print (response)
Traceback (most recent call last):
  File "0-1.py", line 37, in <module>
    response = ig_service.fetch_historical_prices_by_epic_and_date_range(epic, resolution, start_date, end_date)
  File "/home/pi/projects/ig/igapi/trading_ig/rest.py", line 956, in fetch_historical_prices_by_epic_and_date_range
    data['prices'] = self.format_prices(data['prices'])
  File "/home/pi/projects/ig/igapi/trading_ig/rest.py", line 830, in format_prices
    last = prices[0]['lastTradedVolume'] \
IndexError: list index out of range

the IG api gives:

HTTP 200

status: success


cache-control: no-cache, no-store, must-revalidate
content-type: application/json
expires: 0
pragma: no-cache

{
    **"prices": [],**
    "instrumentType": "CURRENCIES",
    "metadata": {
        "allowance": {
            "remainingAllowance": 9995,
            "totalAllowance": 10000,
            "allowanceExpiry": 604061
        },
        "size": 0,
        "pageData": {
            "pageSize": 0,
            "pageNumber": 1,
            "totalPages": 0
        }
    }
}

502 bad gateway is not detected

The server can issue 502 bad gateway at random.
I see this a lot after the close of business on Friday.
Re-trying the same code continually will sometimes respond OK, sometimes 502.

Currently the module will fail downstream with some random pandas fault or subscript out of range where the actual fault was a not OK response.

I will create a patch to explicitly handle responses which are not OK and to report their actual status codes.

Limitations on historical 1 Minute data using REST API?

Hi,

Thanks for the contribution.

When I attempt to print to console historical data using the fetch_historical_prices_by_epic_and_date_range function, the resulting data is compressed. Eg. to print one day of 1 Minute data, it is returned in book-ended 30-data-point chunks (as below). There is no such concern for printing a large quantity of Daily data.

Example:

ask prices:
Open High Low Close
DateTime
2017:11:10-00:00:00 1.16471 1.16471 1.16448 1.16455
2017:11:10-00:01:00 1.16454 1.16488 1.16448 1.16485
2017:11:10-00:02:00 1.16486 1.16512 1.16479 1.16479
2017:11:10-00:03:00 1.16480 1.16489 1.16474 1.16485
2017:11:10-00:04:00 1.16483 1.16494 1.16480 1.16489
2017:11:10-00:05:00 1.16488 1.16497 1.16486 1.16489
2017:11:10-00:06:00 1.16490 1.16512 1.16489 1.16500
2017:11:10-00:07:00 1.16499 1.16503 1.16494 1.16499
2017:11:10-00:08:00 1.16500 1.16515 1.16493 1.16509
2017:11:10-00:09:00 1.16508 1.16517 1.16497 1.16516
2017:11:10-00:10:00 1.16515 1.16527 1.16509 1.16523
2017:11:10-00:11:00 1.16522 1.16532 1.16516 1.16517
2017:11:10-00:12:00 1.16516 1.16522 1.16503 1.16503
2017:11:10-00:13:00 1.16504 1.16542 1.16497 1.16532
2017:11:10-00:14:00 1.16531 1.16537 1.16518 1.16523
2017:11:10-00:15:00 1.16524 1.16526 1.16514 1.16518
2017:11:10-00:16:00 1.16519 1.16521 1.16508 1.16516
2017:11:10-00:17:00 1.16515 1.16519 1.16504 1.16509
2017:11:10-00:18:00 1.16508 1.16518 1.16508 1.16510
2017:11:10-00:19:00 1.16511 1.16516 1.16498 1.16498
2017:11:10-00:20:00 1.16497 1.16501 1.16487 1.16488
2017:11:10-00:21:00 1.16489 1.16493 1.16481 1.16488
2017:11:10-00:22:00 1.16487 1.16493 1.16479 1.16488
2017:11:10-00:23:00 1.16487 1.16506 1.16487 1.16504
2017:11:10-00:24:00 1.16499 1.16503 1.16493 1.16494
2017:11:10-00:25:00 1.16495 1.16509 1.16494 1.16504
2017:11:10-00:26:00 1.16505 1.16512 1.16498 1.16504
2017:11:10-00:27:00 1.16505 1.16507 1.16491 1.16496
2017:11:10-00:28:00 1.16495 1.16503 1.16491 1.16499
2017:11:10-00:29:00 1.16497 1.16503 1.16495 1.16498
... ... ... ... ...
2017:11:10-21:29:00 1.16653 1.16657 1.16648 1.16653
2017:11:10-21:30:00 1.16654 1.16654 1.16652 1.16653
2017:11:10-21:31:00 1.16657 1.16657 1.16648 1.16649
2017:11:10-21:32:00 1.16648 1.16649 1.16648 1.16649
2017:11:10-21:33:00 1.16648 1.16659 1.16648 1.16654
2017:11:10-21:34:00 1.16653 1.16659 1.16652 1.16653
2017:11:10-21:35:00 1.16658 1.16660 1.16653 1.16655
2017:11:10-21:36:00 1.16654 1.16658 1.16652 1.16657
2017:11:10-21:37:00 1.16652 1.16657 1.16648 1.16648
2017:11:10-21:38:00 1.16649 1.16649 1.16648 1.16648
2017:11:10-21:39:00 1.16647 1.16657 1.16647 1.16657
2017:11:10-21:40:00 1.16652 1.16657 1.16651 1.16652
2017:11:10-21:41:00 1.16653 1.16654 1.16648 1.16648
2017:11:10-21:42:00 1.16652 1.16654 1.16647 1.16649
2017:11:10-21:43:00 1.16648 1.16650 1.16648 1.16649
2017:11:10-21:44:00 1.16648 1.16649 1.16647 1.16648
2017:11:10-21:45:00 1.16649 1.16658 1.16648 1.16653
2017:11:10-21:46:00 1.16648 1.16657 1.16646 1.16649
2017:11:10-21:47:00 1.16648 1.16657 1.16647 1.16655
2017:11:10-21:48:00 1.16656 1.16658 1.16647 1.16657
2017:11:10-21:49:00 1.16658 1.16695 1.16654 1.16694
2017:11:10-21:50:00 1.16692 1.16694 1.16661 1.16670
2017:11:10-21:51:00 1.16671 1.16677 1.16664 1.16670
2017:11:10-21:52:00 1.16671 1.16678 1.16668 1.16672
2017:11:10-21:53:00 1.16678 1.16678 1.16662 1.16663
2017:11:10-21:54:00 1.16662 1.16663 1.16654 1.16659
2017:11:10-21:55:00 1.16660 1.16663 1.16649 1.16653
2017:11:10-21:56:00 1.16652 1.16655 1.16648 1.16650
2017:11:10-21:57:00 1.16651 1.16661 1.16648 1.16652
2017:11:10-21:58:00 1.16654 1.16673 1.16651 1.16655

[1315 rows x 4 columns]

Error on LIVE, not on DEMO: KeyError: 'cst'

Dear @femtotrader,
DEMO version is ok. When I change from DEMO to LIVE (username, password etc... are changed), I get the folloging error: KeyError: 'cst' (see below).

Any help?
Thank you in advance,
Gilberto

This is the error output:

KeyError                                  Traceback (most recent call last)
<ipython-input-10-de3f99b49acd> in <module>()
     74 
     75 if __name__ == '__main__':
---> 76     main()

<ipython-input-10-de3f99b49acd> in main()
     34 
     35     ig_stream_service = IGStreamService(ig_service)
---> 36     ig_session = ig_stream_service.create_session()
     37     accountId = ig_session[u'accounts'][0][u'accountId']
     38     ig_stream_service.connect(accountId)

/Users/gb/anaconda/lib/python3.5/site-packages/trading_ig/stream.py in create_session(self)
     19 
     20     def create_session(self):
---> 21         ig_session = self.ig_service.create_session()
     22         self.ig_session = ig_session
     23         return ig_session

/Users/gb/anaconda/lib/python3.5/site-packages/trading_ig/rest.py in create_session(self, session)
    942         action = 'create'
    943         # this is the first create (BASIC_HEADERS)
--> 944         response = self._req(action, endpoint, params, session)
    945         data = self.parse_response(response.text)
    946         self.ig_session = data # store IG session

/Users/gb/anaconda/lib/python3.5/site-packages/trading_ig/rest.py in _req(self, action, endpoint, params, session)
    202         """Creates a CRUD request and returns response"""
    203         session = self._get_session(session)
--> 204         response = self.crud_session.req(action, endpoint, params, session)
    205         return response
    206 

/Users/gb/anaconda/lib/python3.5/site-packages/trading_ig/rest.py in req(self, action, endpoint, params, session)
    119             'delete': self.delete
    120         }
--> 121         return d_actions[action](endpoint, params, session)
    122 
    123     def _set_headers(self, response_headers, update_cst):

/Users/gb/anaconda/lib/python3.5/site-packages/trading_ig/rest.py in _create_first(self, endpoint, params, session)
     70                                 data=json.dumps(params),
     71                                 headers=self.HEADERS['BASIC'])
---> 72         self._set_headers(response.headers, True)
     73         self.create = self._create_logged_in
     74         return response

/Users/gb/anaconda/lib/python3.5/site-packages/trading_ig/rest.py in _set_headers(self, response_headers, update_cst)
    124         """Sets headers"""
    125         if update_cst:
--> 126             self.CLIENT_TOKEN = response_headers['CST']
    127 
    128         if 'X-SECURITY-TOKEN' in response_headers:

/Users/gb/anaconda/lib/python3.5/site-packages/requests/structures.py in __getitem__(self, key)
     52 
     53     def __getitem__(self, key):
---> 54         return self._store[key.lower()][1]
     55 
     56     def __delitem__(self, key):

KeyError: 'cst'

This is the main code (modules and credentials account imports are omitted):

#!/usr/bin/env python
#-*- coding:utf-8 -*-

"""
IG Markets Stream API sample with Python
2015 FemtoTrader
"""

import time
import sys
import traceback
import logging

from trading_ig import (IGService, IGStreamService)
#from trading_ig.config import config
from trading_ig.lightstreamer import Subscription


# A simple function acting as a Subscription listener
def on_prices_update(item_update):
    # print("price: %s " % item_update)
    print("{stock_name:<19}: Time {UPDATE_TIME:<8} - "
          "Bid {BID:>5} - Ask {OFFER:>5}".format(stock_name=item_update["name"], **item_update["values"]))

def on_account_update(balance_update):
    print("balance: %s " % balance_update)

def main():
    logging.basicConfig(level=logging.INFO)
    # logging.basicConfig(level=logging.DEBUG)

    #ig_service = IGService(config.username, config.password, config.api_key, config.acc_type)
    ig_service = IGService(username, password, api_key, acc_type)

    ig_stream_service = IGStreamService(ig_service)
    ig_session = ig_stream_service.create_session()
    accountId = ig_session[u'accounts'][0][u'accountId']
    ig_stream_service.connect(accountId)

    # Making a new Subscription in MERGE mode
    subcription_prices = Subscription(
        mode="MERGE",
        items=['L1:CS.D.GBPUSD.CFD.IP', 'L1:CS.D.USDJPY.CFD.IP'],
        fields=["UPDATE_TIME", "BID", "OFFER", "CHANGE", "MARKET_STATE"],
        )
        #adapter="QUOTE_ADAPTER")


    # Adding the "on_price_update" function to Subscription
    subcription_prices.addlistener(on_prices_update)

    # Registering the Subscription
    sub_key_prices = ig_stream_service.ls_client.subscribe(subcription_prices)


    # Making an other Subscription in MERGE mode
    subscription_account = Subscription(
        mode="MERGE",
        items='ACCOUNT:'+accountId,
        fields=["AVAILABLE_CASH"],
        )
    #    #adapter="QUOTE_ADAPTER")

    # Adding the "on_balance_update" function to Subscription
    subscription_account.addlistener(on_account_update)

    # Registering the Subscription
    sub_key_account = ig_stream_service.ls_client.subscribe(subscription_account)

    input("{0:-^80}\n".format("HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM \
    LIGHTSTREAMER"))

    # Disconnecting
    ig_stream_service.disconnect()

if __name__ == '__main__':
    main()

[SSL: CERTIFICATE_VERIFY_FAILED]

Hi,
i am testing stream_ig.py
and I got this issue

OError: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)

ideas?

thanks

TypeError: sequence item 1: expected str instance, bytes found

When run sample/main.py

Sometimes, it raises the following exception

$ python sample/main.py
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): demo-api.ig.com
INFO:ig_stream:Starting connection with https://demo-apd.marketdatasystems.com
ERROR:ig_stream:Unable to connect to Lightstreamer Server
ERROR:ig_stream:Traceback (most recent call last):
  File "/Users/femto/github/ig-python/ig-markets-stream-api-python-library/trading_ig_stream/ig_stream.py", line 38, in connect
    self.ls_client.connect()
  File "/Users/femto/github/ig-python/ig-markets-stream-api-python-library/trading_ig_stream/lightstreamer/__init__.py", line 206, in connect
    logger.error("Server response error: \n%s" % "".join(lines))
TypeError: sequence item 1: expected str instance, bytes found

running again "fix" this problem

Fetch historical prices broken

Simple issue with using API call to fetch historical prices. Sorry if this has been reported?

from datetime import datetime, timedelta

start_date = datetime.now() - timedelta(hours=24)
end_date = datetime.now()
p_res = ig_service.fetch_historical_prices_by_epic_and_date_range('CS.D.EURUSD.CFD.IP', '1Min', start_date, end_date, ig_session)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/trading_ig-0.0.6-py3.4.egg/trading_ig/rest.py", line 876, in fetch_historical_prices_by_epic_and_date_range
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/trading_ig-0.0.6-py3.4.egg/trading_ig/rest.py", line 207, in _req
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/trading_ig-0.0.6-py3.4.egg/trading_ig/rest.py", line 124, in req
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/trading_ig-0.0.6-py3.4.egg/trading_ig/rest.py", line 95, in read
TypeError: get() takes no keyword arguments

Process finished with exit code 1

Market data not printed

Hi, I tried the sample with my account, and the log has such error:

TransientError: ERROR -1: Invalid account type

I used my LIVE account, which works fine with REST api and minute data, but I want to have tick data with stream api. The account information is exactly the same.

So, could anyone give me some hint?

Thanks

Use JSON or YAML files for config

It will be nice to use JSON or YAML files for config

but we still need config via environment variable (because of continuous integration with Travis-CI)

os.getenv(..., ...)

Maybe we should have a look at Traits / Traitlets
http://traitlets.readthedocs.org/en/latest/config.html

from traitlets.config.configurable import Configurable
from traitlets import Integer, Float, Unicode, Bool

class Config(Configurable):
    username = Unicode(u'demo-username', config=True)
    password = Unicode(u'yourpassword', config=True)
    api_key = Unicode("0"*40, config=True)
    acc_type = Unicode("DEMO", config=True) # LIVE / DEMO
    acc_number = Unicode("AB0AB", config=True)

fetch_historical_prices_by_epic_and_num_points exception during exception handling

response = ig_service.fetch_historical_prices_by_epic_and_num_points(epic, resolution, num_points)
  File "C:\Python35-32\lib\site-packages\trading_ig-0.0.6-py3.5.egg\trading_ig\rest.py", line 837, in fetch_historical_prices_by_epic_and_num_points
  File "C:\Python35-32\lib\site-packages\trading_ig-0.0.6-py3.5.egg\trading_ig\rest.py", line 754, in format_prices
  File "C:\Python35-32\lib\site-packages\pandas\core\frame.py", line 2917, in set_index
    level = frame[col]._values
  File "C:\Python35-32\lib\site-packages\pandas\core\frame.py", line 2059, in __getitem__
    return self._getitem_column(key)
  File "C:\Python35-32\lib\site-packages\pandas\core\frame.py", line 2066, in _getitem_column
    return self._get_item_cache(key)
  File "C:\Python35-32\lib\site-packages\pandas\core\generic.py", line 1386, in _get_item_cache
    values = self._data.get(item)
  File "C:\Python35-32\lib\site-packages\pandas\core\internals.py", line 3541, in get
    loc = self.items.get_loc(item)
  File "C:\Python35-32\lib\site-packages\pandas\indexes\base.py", line 2136, in get_loc
    return self._engine.get_loc(self._maybe_cast_indexer(key))
  File "pandas\index.pyx", line 139, in pandas.index.IndexEngine.get_loc (pandas\index.c:4443)
  File "pandas\index.pyx", line 161, in pandas.index.IndexEngine.get_loc (pandas\index.c:4289)
  File "pandas\src\hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13733)
  File "pandas\src\hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13687)
KeyError: 'snapshotTimeUTC'

Question: Lightstreamer.py commits

Hello,
Just wondering, do you accept commits to the lightstreamer.py file? Since it looks like it was created by 3rd party (Lightstreamer Srl.), I guess that you may want to keep in sync with them?

I noticed that the error reporting for lighstreamer is not too helpful. When an error occurs, the _control() method just returns the first line of the error which just says "ERROR".

I have an edit to return the full error when it happens but also just return 'OK' when there is not. I can submit a pull request if you are interested.

Cheers

Stream API - Do not receive anything for account, confirms, OPU etc.

Hi again,

I tried to use the stream API based on the stream_ig.py file in the sample folder. Price update part works perfectly, on the other hand the account update part does not. In debug mode, i only get PROBE from lightstreamer (i tried to update account by closing positions and making a deposit and still nothing received). The following message repeat indefinitely

DEBUG:trading_ig.lightstreamer:Waiting for a new message
DEBUG:trading_ig.lightstreamer:Received message ---> <PROBE>
DEBUG:trading_ig.lightstreamer:PROBE message

In the same way, i cannot get the TRADE part working, i do not get any reception whith the following parameters:

        subscription_trades = Subscription(
            mode="DISTINCT",
            items='TRADE:'+self.accountId,
            fields=["CONFIRMS","OPU", "WOU"],
            )

thanks for your help,

Seems not to work with share dealing account (even if ok with spread betting)

Hi,

I am testing the API library with my two IG accounts.

When I set my "SPREAD BETTING" account as default on the IG platform, I receive the right output:

`

import os
import sys
from trading_ig import IGService
from trading_ig.config import config
ig_service = IGService(config.username, config.password, config.api_key, config.acc_type)
ig_service.create_session()
{u'reroutingEnvironment': None, etc... etc... : u'https://apd.marketdatasystems.com'}
`

However, When I set my "SHARE DEALING" account as default on the IG platform, I receive an error as below:

`

import os
import sys
from trading_ig import IGService
from trading_ig.config import config
ig_service = IGService(config.username, config.password, config.api_key, config.acc_type)
ig_service.create_session()
Traceback (most recent call last):
File "", line 1, in
File "build/bdist.linux-x86_64/egg/trading_ig/rest.py", line 946, in create_session
File "build/bdist.linux-x86_64/egg/trading_ig/rest.py", line 204, in _req
File "build/bdist.linux-x86_64/egg/trading_ig/rest.py", line 121, in req
File "build/bdist.linux-x86_64/egg/trading_ig/rest.py", line 72, in _create_first
File "build/bdist.linux-x86_64/egg/trading_ig/rest.py", line 126, in _set_headers
File "/home/massi/.local/lib/python2.7/site-packages/requests/structures.py", line 56, in getitem
return self._store[key.lower()][1]
KeyError: 'cst'
`

Any idea of what is triggering the issue?

PEP8 cleanup

A PEP8 cleanup is required

$ flake8 --ignore E501 trading_ig
trading_ig/__init__.py:13:1: F401 '.version.__author__' imported but unused
trading_ig/__init__.py:13:1: F401 '.version.__version__' imported but unused
trading_ig/__init__.py:13:1: F401 '.version.__license__' imported but unused
trading_ig/__init__.py:13:1: F401 '.version.__url__' imported but unused
trading_ig/__init__.py:13:1: F401 '.version.__credits__' imported but unused
trading_ig/__init__.py:13:1: F401 '.version.__status__' imported but unused
trading_ig/__init__.py:13:1: F401 '.version.__copyright__' imported but unused
trading_ig/__init__.py:13:1: F401 '.version.__maintainer__' imported but unused
trading_ig/__init__.py:13:1: F401 '.version.__email__' imported but unused
trading_ig/__init__.py:17:1: F401 '.rest.IGService' imported but unused
trading_ig/__init__.py:18:1: F401 '.stream.IGStreamService' imported but unused
trading_ig/config.py:12:1: E302 expected 2 blank lines, found 1
trading_ig/config.py:20:9: F841 local variable 'env_var' is assigned to but never used
trading_ig/config.py:21:31: F821 undefined name '_env_var'
trading_ig/lightstreamer.py:24:1: E302 expected 2 blank lines, found 1
trading_ig/lightstreamer.py:27:1: E302 expected 2 blank lines, found 1
trading_ig/lightstreamer.py:174:14: E121 continuation line under-indented for hanging indent
trading_ig/lightstreamer.py:191:14: E121 continuation line under-indented for hanging indent
trading_ig/lightstreamer.py:192:14: E123 closing bracket does not match indentation of opening bracket's line
trading_ig/lightstreamer.py:390:13: E128 continuation line under-indented for visual indent
trading_ig/lightstreamer.py:391:13: E128 continuation line under-indented for visual indent
trading_ig/lightstreamer.py:396:5: E303 too many blank lines (2)
trading_ig/lightstreamer.py:399:13: E128 continuation line under-indented for visual indent
trading_ig/rest.py:18:1: E302 expected 2 blank lines, found 1
trading_ig/rest.py:21:1: E302 expected 2 blank lines, found 1
trading_ig/rest.py:59:35: E261 at least two spaces before inline comment
trading_ig/rest.py:155:1: E303 too many blank lines (3)
trading_ig/rest.py:186:37: E261 at least two spaces before inline comment
trading_ig/rest.py:199:35: E261 at least two spaces before inline comment
trading_ig/rest.py:210:5: E266 too many leading '#' for block comment
trading_ig/rest.py:228:5: E266 too many leading '#' for block comment
trading_ig/rest.py:232:5: E266 too many leading '#' for block comment
trading_ig/rest.py:232:5: E303 too many blank lines (3)
trading_ig/rest.py:261:5: E266 too many leading '#' for block comment
trading_ig/rest.py:265:5: E266 too many leading '#' for block comment
trading_ig/rest.py:265:5: E303 too many blank lines (3)
trading_ig/rest.py:267:37: E251 unexpected spaces around keyword / parameter equals
trading_ig/rest.py:267:39: E251 unexpected spaces around keyword / parameter equals
trading_ig/rest.py:346:5: E266 too many leading '#' for block comment
trading_ig/rest.py:350:5: E266 too many leading '#' for block comment
trading_ig/rest.py:350:5: E303 too many blank lines (3)
trading_ig/rest.py:364:43: E251 unexpected spaces around keyword / parameter equals
trading_ig/rest.py:364:45: E251 unexpected spaces around keyword / parameter equals
trading_ig/rest.py:471:43: E251 unexpected spaces around keyword / parameter equals
trading_ig/rest.py:471:45: E251 unexpected spaces around keyword / parameter equals
trading_ig/rest.py:594:5: E266 too many leading '#' for block comment
trading_ig/rest.py:598:5: E266 too many leading '#' for block comment
trading_ig/rest.py:598:5: E303 too many blank lines (3)
trading_ig/rest.py:758:43: E231 missing whitespace after ','
trading_ig/rest.py:882:5: E266 too many leading '#' for block comment
trading_ig/rest.py:886:5: E266 too many leading '#' for block comment
trading_ig/rest.py:886:5: E303 too many blank lines (3)
trading_ig/rest.py:964:5: E266 too many leading '#' for block comment
trading_ig/rest.py:968:5: E266 too many leading '#' for block comment
trading_ig/rest.py:968:5: E303 too many blank lines (3)
trading_ig/rest.py:989:31: E261 at least two spaces before inline comment
trading_ig/rest.py:1005:5: E266 too many leading '#' for block comment
trading_ig/rest.py:1009:5: E266 too many leading '#' for block comment
trading_ig/rest.py:1009:5: E303 too many blank lines (3)
trading_ig/rest.py:1047:5: E266 too many leading '#' for block comment
trading_ig/stream.py:14:1: E302 expected 2 blank lines, found 1
trading_ig/stream.py:29:9: F841 local variable 'clientId' is assigned to but never used
trading_ig/stream.py:34:9: E265 block comment should start with '# '
trading_ig/stream.py:35:9: E265 block comment should start with '# '
trading_ig/stream.py:46:61: E261 at least two spaces before inline comment
trading_ig/utils.py:13:5: F811 redefinition of unused 'pd' from line 8
trading_ig/utils.py:13:5: F401 'pandas as pd' imported but unused
trading_ig/utils.py:21:5: F401 'munch.munchify' imported but unused
trading_ig/utils.py:28:1: E302 expected 2 blank lines, found 1
trading_ig/utils.py:34:30: E231 missing whitespace after ':'
trading_ig/utils.py:35:30: E231 missing whitespace after ':'
trading_ig/utils.py:36:30: E231 missing whitespace after ':'
trading_ig/utils.py:37:30: E231 missing whitespace after ':'
trading_ig/utils.py:38:31: E231 missing whitespace after ':'
trading_ig/utils.py:39:31: E231 missing whitespace after ':'
trading_ig/utils.py:68:17: F811 redefinition of unused 'pd' from line 13
trading_ig/utils.py:95:1: E302 expected 2 blank lines, found 1
trading_ig/utils.py:100:9: F821 undefined name 'os'

good_till_date cannot be null in create_working_order

Hi again,

In the REST api, in the create_working_order method, parameter good_till_date is converted to date. I noticed that this parameter is not mandatory and can be null.

I would suggest to replace in the trading_ig/rest.py file on line 518

good_till_date = conv_datetime(good_till_date, 1)

by

if good_till_date != None:
            good_till_date = conv_datetime(good_till_date, 1)

RemoteDisconnected after REST API call

Doing a REST API call as part of my app flow. The app has a stream subscription too. I get an error saying the remote end closed connection without response. This could happen after a random amount of time, in this case the app had been running for about 10hours.

I'd prefer to avoid any manual monitoring of this and restart the app, right now I don't understand the root cause of this behaviour. Is IG shutting one off after a X amount of REST API calls? I'd approximate that the app is doing 1-2 REST API calls per minute. If I'd hit any limit, I'd expect an error code and message (as it's documented).

Traceback (most recent call last):
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/urllib3/connectionpool.py", line 387, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/urllib3/connectionpool.py", line 383, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.5/http/client.py", line 1198, in getresponse
    response.begin()
  File "/usr/lib/python3.5/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.5/http/client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/urllib3/util/retry.py", line 357, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/urllib3/packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/urllib3/connectionpool.py", line 387, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/urllib3/connectionpool.py", line 383, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.5/http/client.py", line 1198, in getresponse
    response.begin()
  File "/usr/lib/python3.5/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.5/http/client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 307, in <module>
    main()
 **.........app code to fetch open position............**
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/trading_ig-0.0.6-py3.5.egg/trading_ig/rest.py", line 430, in fetch_open_positions
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/trading_ig-0.0.6-py3.5.egg/trading_ig/rest.py", line 218, in _req
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/trading_ig-0.0.6-py3.5.egg/trading_ig/rest.py", line 133, in req
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/trading_ig-0.0.6-py3.5.egg/trading_ig/rest.py", line 104, in read
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/requests/sessions.py", line 521, in get
    return self.request('GET', url, **kwargs)
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/home/linaro/IGT/venv/igt/lib/python3.5/site-packages/requests/adapters.py", line 490, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

Lightstreamer SYNC ERROR

Hello,

I randomly get the following error:

Server response error: 
SYNC ERROR
Exception in thread STREAM-CONN-THREAD-1:
Traceback (most recent call last):
  File "C:\Python36-32\Lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Python36-32\Lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python36-32\lib\site-packages\trading_ig-0.0.6-py3.6.egg\trading_ig\lightstreamer.py", line 386, in _receive
    self.bind()
  File "C:\Python36-32\lib\site-packages\trading_ig-0.0.6-py3.6.egg\trading_ig\lightstreamer.py", line 210, in bind
    self._handle_stream(stream_line)
  File "C:\Python36-32\lib\site-packages\trading_ig-0.0.6-py3.6.egg\trading_ig\lightstreamer.py", line 238, in _handle_stream
    raise IOError()
OSError

Maybe we could add rebind = True in lightstreamer.py as for the "LOOP ERROR" ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.