This repository is the home of Hands-on Elixir & OTP: Cryptocurrency trading bot book.
Want to learn Elixir & OTP by creating a real-world project?
With “Hands-on Elixir & OTP: Cryptocurrency trading bot”, you will gain hands-on experience by writing an interesting software project from scratch. We will explore all the key abstractions and essential principles through iterative implementation improvements.
We will start by creating a new umbrella application, subscribing to WebSocket streams, implementing a basic trading flow, and focusing on improving it by expanding on the topics like supervision trees, resiliency, refactoring using macros, utilising the Registry, testing and others.
This book is 80% complete - chapters 1-17 are finished, and I’ll add more content soon. It’s also a loosely written representation of the Hands-on Elixir & OTP: Cryptocurrency trading bot video course released on YouTube.
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International CC BY-NC-SA 4.0.
Limit of Liability/Disclaimer of Warranty
THIS BOOK IS NOT FINANCIAL ADVICE
THE SOFTWARE/BOOK 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/BOOK OR THE USE OR OTHER DEALINGS IN THE SOFTWARE/BOOK.
Contributing, Errata and Source code {-}
The book is written using R Markdown(it's a very similar syntax to the GitHub markdown but supports many more features including code execution, etc.) and converted to final form (for example PDF) using the bookdown app. This means that editing a chapter is as simple as editing the markdown source of that chapter.
There are two repositories related to this book(both hosted on Github):
- source code of the book itself
- code written across the book where the final code of each chapter has its own branch
In regards to contributions - I would love to follow the standard process of forking, making changes, opening PR(please look is there a branch for the next version and point to it instead of main
), merging, and releasing a new version of the book.
This books has also the GitHub Discussions enabled for both the book's repo as well as source code's repo, please feel welcome to start any discussions related to book there.
Chapter 2: Use gitignored secrets.exs for Binance keys
Updated:
This PR updates the section where we set the Binance API keys in order to avoid accidentally checking these keys into source control. We put the Binance config in a new
config/secrets.exs
which is added to.gitignore
and included inconfig/config.exs
if it exists usingimport_config
.Originally:
I appreciate that this is maybe a bit opinionated, but I think it's worth showing a source-control-safe method of setting the keys for Binance. I'm following the book in a public repo and wouldn't want my keys in that repo. In this PR I'm using environment variables in
config/runtime.exs
. I've chosen to useruntime.exs
in case the guide gets into compiling later on - compile time environment variable resolution is quite confusing/unexpected IMO. I've demonstrated setting these environment variables in the following test run.Unable to start Streamer app with Phoenix.PubSub
I've been following along the book as a practice method until I found myself blocked with the following issue: Environment: Elixir 1.11.4 Erlang/OTP 23
Relevant code snippet
Expected:
iex -S mix
starts the application correctly.Actual result:
iex -S mix
produces error:** (Mix) Could not start application streamer: Streamer.Application.start(:normal, []) returned an error: shutdown: failed to start child: Phoenix.PubSub.Supervisor ** (EXIT) shutdown: failed to start child: Phoenix.PubSub.PG2 ** (EXIT) exited in: :gen_server.call(Phoenix.PubSub, {:join_local, Streamer.PubSub.Adapter, #PID<0.251.0>}, :infinity) ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
Besides changing the Elixir/OTP versions, I see no way of debugging this. Any idea?
Typo at the end of 2.3.2 (i think)
Reading through your book. Really enjoying it so far. I came across this piece of code at the end of 2.3.2
However the commentary that is provided immediate after is a little confusing. For instance there is this quote,
We started by calculating the gross_buy_price which is a sum of buy price together with the fee that we paid on top of it.
I do not see gross_buy_price, but perhaps that was intended to be
original_price
, however theoriginal_price
variable is not calculate with a sum like the above quote states it isD.mult(D.new(buy_price), fee)
. There is another quote that is similar,As we will be charged a fee for selling, we need to add the fee again on top of this target sell price(gross_target_price).
Again, that is referring to the line
gross_target_price = D.mult(net_target_price, fee)
which is also a multiplication and not a sum.Code mismatch at 6.4
Hi, I noticed 2 mismatch with map returned by
fetch_symbol_settings/1
:The key
:symbol
added in chapter 5 now is disappearedIn chapter intro we can read
The value assigned is 0.0001 but I expect 2 times 0.1% and so 0.002. I probably misunderstood how you assigned this value. Can you clarify me this point?
Thank you!
Update single to double quotes inside config secrets.exs import code
Hello there 😀.
This change was introduced on the source code repo, and this PR intends to reflect the exact change in the book.
See: https://github.com/Cinderella-Man/hands-on-elixir-and-otp-cryptocurrency-trading-bot-source-code/commit/19ffb3676742a48814e8275843020927a827270a
Fix `postgrex` version spell
Core: https://github.com/frathon/hands-on-elixir-and-otp-cryptocurrency-trading-bot/pull/22/files#diff-8a524efdf9e62755d23c18299df4a9c21c290ede690f63c2930b884043571c41R107
Other is auto format
Change from step to step_size
By the end of the sub-chapter 7.5 "Calculate quantity" on the function declaration for calculate_quantity, you are using in the body just "step" instead of "step_size".
Best regards
Small grammar change
"Financial Advice" for some reason is never singular, to a native English speaker this sounds wrong. You could give advice but not an advice, I guess one of the many weirdnesses of English because you can give a talk or give a tutorial but not give an advice. It makes no sense.
V0.4.1
This release contains a refreshing of all drawings throughout the book(including reformatting when size changed) + fixes to chapter 18 and 19 (lack of proper syntax highlighting)
Chapters 18, 19 and 20
A result of months of work (primarily personal growth and questioning my own understanding of things like "functional programming"):
Additionally, some changes around the book, including fixing links, adding aliases for easier reading etc.
V0.3.0
Updates:
integration
Currently, the book is 226 pages long :rocket: