r/UKInvesting • • Dec 24 '17
Python IG Index Bot
Hi All, I have been learning Python as of late and I woke up one morning and decided to give this ago. I have wrote a Scraping Bot for IGIndex. Currently as the markets are closed, Only Crypto's are available and I have been testing it for two days and every trade but one has been in profit. Would anyone like to be a beta testing, It works on the Demo or Real account and should work with any instrument. I am planning to run it Live on Gold as the markets open.
Works on Linux and Windows using Python3.
Update 27/12: Please make sure you do a git pull if you are using this, I notice that 49 people are using git, I have made some minor changes where the profit checking code would not execute in certain situations.
UPDATE - PLEASE GIT CLONE AGAIN 27/12 23:00 - Code Review and changes, Closed all six trades in profit today. Made some minor tweaks after people's comments and my own internal dialog.
Quite happy with the logic of the code, Make a tweak so we are less likely to get stuck on the wrong side of a trade for hours. I need to put a hard stop loss in though at some point to be absolutely sure as I can be.
LATEST CODE PUSHED TO GITHUB 28/12 More robust trade direction code. Seems to work OK now.
LATEST CODE PUSHED TO GITHUB 28/12 @ 20:24,** Very Robust Code Base, Happy with profits generated by this now.
LATEST CODE PUSHED TO GITHUB 30/12 @ 11:03 - Weekend test with Ether (Crypto) because that's the only market that's open. Like I said it works with anything just change the Epic ID, I have tested it with FTSE100, Wall Street, Gold, Silver and GBP/USD and it works. As well as some cryptos but that is just for pure data generation at the weekend, I really don't believe in Crypto's but that is my opinion.
UPDATE - Fixed Small Dependency issue with libs.
LATEST CODE PUSHED @ 31/12 09:35, Few small tweaks, Mainly code tidy up - HAPPY NEW YEAR, Ready to go Live when markets open again next week
Has anyone used this or tested it? What do you all think?
2
u/[deleted] Dec 26 '17 edited Dec 26 '17
Merry Christmas all!! So whilst the main bulk of the script is under active development. This is a bit of code I wanted people to test/use. I needed a more reliable way of determining the movement of an instrument. So I have used the Price and Volume of the last half an hour. You can change it however you like. It's quite easy to understand. Please feel free to comment. I am running this at the moment testing it.
Please feel free to test, This should run and print in the shell when there is a change of direction.
https://gist.github.com/tg12/c23314b81eb0fcebaa398cff2db68f7b
You can use it on any instrument you want, I have hacked this together to check the price of Spot Gold.
2
u/pieandablowie Dec 25 '17
Also interested
2
u/Zakalwee Dec 25 '17
Interested in trying it as well
2
u/SmarseArt Dec 30 '17
that logic though... IG are going to love you guys.
1
u/[deleted] Dec 25 '17
All markets are closed. We should all be nursing a food baby/hungover whatever. So when the markets re open I’ll test it and make some slight adjustments. And I’ll post. You will need a valid
IGINDEX Account and API Key of your own. Python 3 on Windows or Linux Reasonably fast internet connection
1
u/[deleted] Dec 26 '17
Thing's to note.
This has been "Hacked" to work on Spot Gold, It have been tested on Bitcoin and because of the massive swings it is highly profitable. Not sure about Spot Gold, However I wanted to use it with something that has "Low Barriers to entry" Bitcoin and IG index, Well frequently they disable Buying etc and the margin's required and spread's are horrendous (Not limited to IG though so not their fault). This is meant to be for beginners so you can invest a small amount and grow it over time.
I wrote this in Notepad++, I am telling you this because It nicely shows the line numbers so ask if you have a query about a particular bit. Plus it's nice to format code and commenting and commenting stuff is a doddle.
https://notepad-plus-plus.org/
The code is here, It will output some debugging stuff to the console currently.
Line(s) 28/39 - Change your Username/Password and API Key and if you want to use Real money (YOUR OWN RISK!!) or DEMO.
https://labs.ig.com/faq
Line 327 - This is how far to look back to get an idea of market direction. You can change this, I use 2 hours, I have tested it as high as 3 hours and as low as a minute (Which is pretty useless).
https://github.com/tg12/IG-Index-Scalping-Scraping-Bot
1
u/[deleted] Dec 27 '17
Update: Please make sure you do a git pull if you are using this, I notice that 49 people are using git, I have made some minor changes where the profit checking code would not execute in certain situations.
1
u/adogramaci Dec 25 '17
I'd be very interested, I've mostly done automation work in python for work purposes and I'm looking to apply my knowledge in non work related areas for fun and it won't hurt to make profit, right 😁
1
u/Alexjrose Dec 25 '17
I'd be interested :)
1
u/TheRealWhoop Dec 25 '17
Interested!
1
u/vamposa78 Dec 25 '17
Yeap - I’m interested.
1
u/doart3 Dec 25 '17
would love to see it ;) an dcontribute if I can
1
u/oilyholmes Dec 25 '17
What's your method? Be aware that if the market sentiment change it might be that all your trades except one aren't in profit. You can backtest on a few websites if I'm not mistaken. I forget what the websites are.
1
u/nif_makria Dec 25 '17
Do u have a github link ? Happy to contribute to a python project.
1
u/internetf1fan Dec 27 '17 edited Dec 27 '17
How do I run this on Windows? I downloaded Python3 and then opened the .py file in IDLE (GUI) when I ran the file, it came up with module requests not found.
edit: so I downloaded requests module using pip install but when I run it again, I get the following.
Traceback (most recent call last): File "C:\Users\XXX\Downloads\IG-Index-Scalping-Scraping-Bot-master\IG-Index-Scalping-Scraping-Bot-master\p_ig_TEST - Copy.py", line 50, in <module> CST_token = headers_json["CST"] KeyError: 'CST'
Can you help me out?
Cheers.
1
u/badger2800 Dec 27 '17
Have got this going within Pycharm and my IG demo account.
I can confirm that it is doing stuff...quite what though I don't know. I will spend a few days trying to work out what it is intending to do, how it is doing it and whether I am making any monopoly money.
Thanks for making this available, it is really interesting!
1
u/internetf1fan Dec 27 '17
So now that I have got the script running, it appears there is something wrong with your take profit? It opened a short position and in the shell the P/L went positive and it went ASSUME PROFIT and closed position. However when I go into the statements, it's closed at a loss.
1
u/badger2800 Dec 31 '17
I tried the first version and functionally it worked... However I didn't ever consistently record a profit on my demo account.
The two problems I faced is that when it went wrong the loss was reasonably large, and so 10p profit trades made little difference to the overall profit. Secondly, like someone else has said, it needs a check to ensure that the position will close in profit. A number of times the position had swung to slight negative and closed.
A nice feature would be to be able to cancel the script and it closes the current position when it is in profit but doesn't start another.
I will try the new version of the code over the next week and see if I can get better results.
Really interesting concept though. And ripe for adding data from the twitter api to conduct sentiment analysis on specific stocks.
Cheers though. Really interesting.
1
u/vamposa78 Jan 03 '18
Firstly thank you for writing this script - it covered a lot of questions about how the rest apis work. I’ve learned a lot. I pulled the latest last night - aside from the version hitting an exception due to a variable not being defined it works; in that it’s able to place trades And monitor the position. However it’s been unable to generate profit at all - both trades hitting the stops at a loss of 20gbp. Maybe I’m missing a configuration or something but the first version at least sometimes was able to pull profit - although that could be entirely down to the market condition at the time I ran it. The algorithm seems very simple; although I’m going to start looking into back testing ideas I have against fixed time frames. Again thanks for your work!
1
u/badger2800 Dec 24 '17
I am happy to give this a whirl...
I have spent a lot of this year learning python, Linux and also investing in shares.
So your code sounds interesting from all three perspectives...
0
u/[deleted] Dec 25 '17
[deleted] — view deleted comment