Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Automated cryptocurrency trading

40 views

Published on

How I tried to automated cryptocurrency trading

Published in: Engineering
  • Be the first to comment

  • Be the first to like this

Automated cryptocurrency trading

  1. 1. Automated cryptocurrency trading VilniusPHP 0x40 Žilvinas Kuusas, 2018
  2. 2. Žilvinas Kuusas Lead developer @ Estina ISIGN.io e-signature solutions VilniusPHP.lt | CleanPHP.lt | NoTrollsAllowed.com t: @kuusas e: zilvinas@kuusas.lt About me
  3. 3. How did it all begin?
  4. 4. 2x in 1 month
  5. 5. Our office gems: crypto miner
  6. 6. 3 paths of crypto world ● Buy some cryptos and HODL for long ● Buy and TRADE for profit (buy low, sell high) ● Build a rig and MINE
  7. 7. When you have no patience ● HODL ● MINE ● TRADE !
  8. 8. Why cryptocurrencies is so attractive for wannabe traders? ● Huge price fluctuations ● No entrance fee ● No regulations ● No limits ● Market always goes up(despite some bloody periods)
  9. 9. Day trading Pros ● It’s fun ● Fast $$$ Cons ● Daily commitment ● Discipline ● Skills ● Human factors ● MANUAL LABOR
  10. 10. THE BOT
  11. 11. Is it legal? YES
  12. 12. Trading platforms offers API ● Bittrex ● Bitfinex ● Kraken ● Binance ● Bitstamp ● ... ● Buy and Sell ● Withdraw ● Get market data ● Websockets for LIVE data
  13. 13. What bot can do for you? ● High-frequency trading ● Arbitrage ● Scalping ● Swing trading ● Stop-loss protection ● Indicating ● Alerting
  14. 14. Existing open source solutions Bot Technology Notes Gekko JavaScript, Node Not suitable for high-frequency trading Bowhead PHP, Laravel Spaghetti monster Lack of backtesting tools ccxt JavaScript, Node (generates Python and PHP) Supports 98 APIs Missing trading strategies freqtrade Python Found yesterday No backtesting
  15. 15. Existing paid solutions Bot Price Notes MetaTrader 4 Has marketplace of robots and indicators Powerful, but uses invented programming language. Has bunch of free bots to use. Gunbot Starting 0.075 BTC It works. CryptoTrader Starting 0.0016 BTC / month Cheap, hard to make it work to generate expected profit. BTC Robot Starting 9.99 $ / month Cheap, hard to make it work to generate expected profit. 60 days back guarantee
  16. 16. Plan ● Select platform ● Collect data ● Trading strategy ● Implementation ● Backtesting ● Production
  17. 17. Select platform Platform Reliability Maker (Limit order) Taker (Market order) Bitfinex + 0.1% 0.2% Kraken - 0.15% 0.15% Binance + 0.1% 0.1% Bitstamp + 0.25% 0.25% Poloniex + 0.15% 0.25% Bitthumb + 0.15% 0.15% Bittrex + 0.25% 0.25%
  18. 18. $ git clone https://github.com/joeldg/bowhead $ vi .env $ mysql .. < app/Scripts/DBdump.sql $ php artisan bowhead:websocket_bitfinex Collect data What we need: ● OHLC data ○ Open ○ High ○ Low ○ Close ● Volume data For given time frame: ● 1 min ● 5 min ● 15 min ● 30 min ● 1 h
  19. 19. Collect data $ git clone https://github.com/joeldg/bowhead $ vi .env $ mysql .. < app/Scripts/DBdump.sql $ php artisan bowhead:websocket_bitfinex
  20. 20. Collect data 24/7 We need a server! ● Digital Ocean 10 $ / m ● Centos 7 ● Ansible playbook: ○ PHP 7.2 ! ○ mysql ○ supervisord ○ cronjob to periodically restart services
  21. 21. Strategy - what should my bot do? ● Buy low, sell high ● React to all ups and downs ● Do it 24/7
  22. 22. My strategy choice - scalping
  23. 23. BUY SELL BUY BUY BUY BUY BUY BUY BUY SELL SELL SELL SELL SELL SELL SELL SELL Buy low, sell high
  24. 24. Implementation #1
  25. 25. Implementation ● When to buy? - BUY signal. ○ Place order - Call API. ● When to sell? - SELL signal. ○ Place order - Call API.
  26. 26. Technical Analysis implementation...
  27. 27. Reusing existing tools ● Using Bowhead bot predefined strategies ○ Requires PHP Trader extension ● SOURCE CreateOrderCommand.php
  28. 28. Backtesting
  29. 29. Start with: ● BTC ($50) ● ETH ($50) ● LTC ($50) ● BCH ($50) Go live! 12 hours results: ● BTC ... ● ETH ... ● LTC ... ● BCH ...
  30. 30. Start with: ● BTC ($50) ● ETH ($50) ● LTC ($50) ● BCH ($50) Go live! 12 hours results: ● BTC $49.8 ● ETH $48.2 ● LTC $47.6 ● BCH $52.3
  31. 31. Start with: ● BTC ($50) ● ETH ($50) ● LTC ($50) ● BCH ($50) Go live! 24 hours results: ● BTC $47.9 ● ETH $49.1 ● LTC $44.3 ● BCH $54.3
  32. 32. WAIT, WHAT !?!?..
  33. 33. Debugging I see nothing...
  34. 34. Backtesting: visualisation
  35. 35. Problems ● Orders not filled on time ● Outdated data ● Backtested and live code are not the same
  36. 36. Backtesting: visualisation
  37. 37. Implementation #2
  38. 38. My very own algorithm ● Buy on green ● Sell on red
  39. 39. My very own algorithm
  40. 40. Backtesting
  41. 41. Go live! Never happened.
  42. 42. Implementation #3
  43. 43. Learning technical analysis ● What is a buy signal ● What is a sell signal
  44. 44. Understanding Technical Analysis tools ● Moving Average (MA) ● Exponential Moving Average (EMA)
  45. 45. More TA tools ● Average Directional Index - ADX ● Relative Strength Index - RSI ● Money Flow Index - MFI ● Moving Average Convergence Divergence - MACD
  46. 46. Performance of latest algorithm Market growth: ~ +6% Bot earnings: ~ +9.6%
  47. 47. TA tools in PHP trader_ma($data['close'], $period); trader_ema($data['close'], $period); trader_macd($data['close'], $period1, $period2); trader_rsi($data['close'], $period) trader_adx($data['high'], $data['low'], $data['close'], $period); trader_mfi($data['high'], $data['low'], $data['close'], $data['volume'], $period)
  48. 48. @NOTES
  49. 49. Risk management Risk-reward ratio
  50. 50. Stop-loss Secure your $
  51. 51. Cryptocurrency market is unpredictable Technical analysis tools and various patterns - what works on stock markets, regular currencies trading, not necessarily will work with cryptos.
  52. 52. Algorithm Optimisation Testing tons of parameters to find the best combination for given market situation.
  53. 53. Emotionless trading? Bot inherits emotions from his creator.
  54. 54. Backtesting Technical analysis tools and various patterns - what works on stock markets, regular currencies trading, not necessarily will work with cryptos. And once again - market trend must be taken to account.
  55. 55. Version control Version all the things!
  56. 56. Ačiū! Coming soon: github.com/kuusas/ ...
  57. 57. [Spoiler alert] Dirbantys Estinoje botą gauna pirmi.

×