Skip to content

django based myetrade

License

GPL-3.0, GPL-3.0 licenses found

Licenses found

GPL-3.0
LICENSE
GPL-3.0
COPYING
Notifications You must be signed in to change notification settings

pinebud77/myetrade_django

Repository files navigation

Django-based MyEtrade

This is personal test for Django + my trading code. However, this looks like not a good approach at all..
There is no gurantee on your data and integrity. If you try this, it is on your own risk. You'd better not to try this SW. :)

ToDO :

  • think more about algorithms now -_-;
  • bugfix : there are plenty of bugs yet.. (too many bugs!!! too many bugs!! don't try this program!!)

Done :

  • running algorithm on real trading
  • simulation based on daily history
  • several dummy algorithms (of no practical use)
  • graph and report generation
  • BTC : trading through coinbase API (wrapper to coinbase public python lib)
  • stocks : trading through E*TRADE API (my private python API)

Installation :

  1. $ sudo apt install
  2. $ git clone https://github.com/pinebud77/myetrade_django.git
  3. $ sudo pip3 install django requests requests_oauth holidays fake_useragent matplotlib mpld3 requests_oauthlib jinja2 coinbase yfinance
  4. $ cd myetrade_django
  5. generate your own myetrade_django/settings.py : you can refer setting.py.sample
  6. $ git clone https://github.com/pinebud77/python_etrade.git
  7. $ git clone https://github.com/pinebud77/python_coinbase.git
  8. $ python3 manage.py migrate
  9. $ python3 manage.py makemigrations stock
  10. $ python3 manage.py migrate
  11. $ python3 manage.py createsuperuser

Required Variables in settings.py if you want to try coinbase

  • COINBASE_KEY
  • COINBASE_SECRET

Required Variables in settings.py if you want to trid E*TRADE

  • ETRADE_KEY
  • ETRADE_SECRET
  • ETRADE_USERNAME
  • ETRADE_PASSWORD

Setting up Account and Stock :

  • http://localhost:8000/admin/stock/account/ -> add account and setup stock information
  • 'BUDGET RATE IN THE ACCOUNT' means the rate of the stock in the account.
    ex) If budget rate is 0.49, and the net value is 1000.0, the budget for the stock is 490.0
  • the total of the BUDGET RATE for each stocks should not be over 1.0
    ex) you have to consider the trading fee. so, using total 0.95 of tradable money is recommended considering the trading fee
  • Account type and Account id need to be set
    account id can be anyvalue for coinbase account
    account id need to be 0 for simulation account
  • Net value and Cash to trade will be filled when the daily run is called, or when simulation starts
  • stocks need to set if you want to try simulation

Ingesting Stock History Data (for simulation):

  1. $ python3 manage.py runserver
  2. open http://localhost:8000/stock/loaddata/ : this will load daily history data from yahoo finance (stock) or other server (BTC)
  3. your initial cash in the account will reset to 100000.0 on execution of simulation
  4. open http://localhost:8000/stock/simulate/

Getting Performance Graph for the actual run :

Getting Performance Report for the actual run :

  1. open http://localhost:8000/stock/report/
  2. input desired date range for the report
  3. click submit and the .csv file will be downloaded
  4. example report : monkey is the best !!!

Deploying the server with nginx + gunicorn

Running the actual daily job :

  • open http://127.0.0.1:8000/stock/run/ on the same host as the server : this page will return error if the client is not on the same server
  • add cronjob for the user as the following if it works well:
    30 6 * * 1-5 /home/${your_account}/myetrade_django/run_cron.sh
  • This will run your algorithm every 6:30am (because I am at Western area)