GithubHelp home page GithubHelp logo

cinderella-man / hedgehog Goto Github PK

View Code? Open in Web Editor NEW
88.0 8.0 18.0 372 KB

Source code for the "Hands-on Elixir & OTP: Cryptocurrency Trading Bot" course

Home Page: https://www.youtube.com/playlist?list=PLxsE19GnjC5Nv1CbeKOiS5YqGqw35aZFJ

Elixir 100.00%
elixir-lang binance-api binance algotrading

hedgehog's Introduction

Hedgehog

Repository created to follow along with the Create a cryptocurrency trading bot in Elixir course.

Each subsequent video has an assigned git branch that stores a state of the code after it.

For anyone interested in an written version of the course, it's available free online at elixircryptobot.com.

Limit of Liability/Disclaimer of Warranty

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Intial setup

  1. Install the required dependencies:
$ mix deps.get
...
  1. Start Postgres instance inside docker:
$ docker-compose up -d
Creating hedgehog_db_1 ... done
  1. Create, migrate and seed databases inside the Postgres instance:
$ mix setup

Further setup (danger zone)

Inside the configuration file(config/config.exs) there's a setting(config :naive, binance_client) specifying which Binance client should be used. By default, it's the BinanceMock module that won't connect to the Binance exchange at all neither it will require any access configuration as it stores orders in memory.

To connect to the Binance exchange and make real trades the configuration needs to be changed to the Binance client:

# /config/config.exs:L25
binance_client: BinanceMock, => binance_client: Binance,

as well as api_key and secret_key need to be set:

# /config/config.exs:L49
config :binance,
  api_key: "insert value here",
  secret_key: "insert value here"

Running

iex -S mix

# connect to the Binance and stream into PubSub
Streamer.start_streaming("xrpusdt")

# to store trade_events in db
DataWarehouse.start_storing("trade_events", "xrpusdt")

# to store orders in db
DataWarehouse.start_storing("orders", "xrpusdt")

# turn on naive strategy
Naive.start_trading("XRPUSDT")

Postgres cheat sheet

psql -U postgres -h 127.0.0.1
Password for user postgres: postgres
...
postgres=# \c data_warehouse
...
postgres=# \x
...
data_warehouse=# SELECT COUNT(*) FROM trade_events;
...
data_warehouse=# SELECT COUNT(*) FROM orders;

Loading backtesting data

cd /tmp

wget https://github.com/Cinderella-Man/binance-trade-events/raw/master/XRPUSDT/XRPUSDT-2019-06-03.csv.gz

gunzip XRPUSDT-2019-06-03.csv.gz

PGPASSWORD=postgres psql -Upostgres -h localhost -ddata_warehouse  -c "\COPY trade_events FROM '/tmp/XRPUSDT-2019-06-03.csv' WITH (FORMAT csv, delimiter ';');"

Running backtesting

DataWarehouse.start_storing("orders", "xrpusdt")

Naive.start_trading("XRPUSDT")

DataWarehouse.publish_data(%{
  type: :trade_events,
  symbol: "XRPUSDT",
  from: "2019-06-02",
  to: "2019-06-04",
  interval: 5
})

Running integration test

MIX_ENV=test mix test.integration

hedgehog's People

Contributors

cinderella-man 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hedgehog's Issues

Using Binance demo exchange

Hey mate, great work with your videos!
I was wondering if you managed to use the Binance demo exchange? I tried without success as it looks like no orders are generated even from very common symbols...

Maybe I missed something, if you managed to make it work, I would love some insights or even a video about it as I think it's important to evolve in a safe demo account when working on this project rather than on the real thing.

Thanks!

Use kafka topics instead of postgres for storing events.

Hi @frathon,

I wanted to suggest Kafka because it's made for these types of events we have to deal with in trading etc...
I thought it might be a better suggestion than Postgres maybe?

You probably already know about it of course but for whoever reads this and does not know this is what Kafka is:

https://www.youtube.com/watch?v=FKgi3n-FyNU

PS:
This docker-compose below worked out great for me:
https://github.com/wurstmeister/kafka-docker/blob/master/docker-compose-single-broker.yml

Handshake failure during database seed run

Just in case someone else experiences that error while trying to run the seed scripts:

TLS :client: In state :wait_cert_cr at ssl_handshake.erl:1889 generated CLIENT ALERT: Fatal - Handshake Failure
 - {:bad_cert, :hostname_check_failed}
** (MatchError) no match of right hand side value: {:error, {:http_error, %HTTPoison.Error{id: nil, reason: {:tls_alert, {:handshake_failure, 'TLS client: In state wait_cert_cr at ssl_handshake.erl:1889 generated CLIENT ALERT: Fatal - Handshake Failure\n {bad_cert,hostname_check_failed}'}}}}}
    priv/seed_settings.exs:11: (file)
    (elixir 1.11.1) lib/code.ex:931: Code.require_file/2
    (mix 1.11.1) lib/mix/tasks/run.ex:146: Mix.Tasks.Run.run/5
    (mix 1.11.1) lib/mix/tasks/run.ex:86: Mix.Tasks.Run.run/1

Solved it by updating the binance, websockex, postgrex, jason and ecto_sql dependencies.
Can't confirm which one was causing the issue but I would guess it would be enough to update to the latest binance version.

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.