Cinderella-Man / hands-on-elixir-and-otp-cryptocurrency-trading-bot

Source code to generate the "Hands-on Elixir & OTP: Cryptocurrency trading bot" book
https://elixircryptobot.com
263 stars 34 forks source link

Code mismatch at 6.4 #10

Closed marcoflcn closed 3 years ago

marcoflcn commented 3 years ago

Hi, I noticed 2 mismatch with map returned by fetch_symbol_settings/1:

  1. The key :symbol added in chapter 5 now is disappeared
  2. In chapter intro we can read

    should never be smaller than double the fee(at the moment of writting transaction fee is 0.1%) that you are paying per transaction

    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!

Cinderella-Man commented 3 years ago

Hi :wave:

Thank you very much for opening an issue.

In regards to the first point - that is a "bug" in the book and I checked with the source code and the symbol is there. I already committed a fix and it will get released in version 0.1.6 - thank you :+1:

Re the second point:

I will try to do my best here, if it's still unclear please feel free to ask further questions as probably it's my bad explanation causing the issue 😉

Let's say that you bought something for $100 per coin, then the price moved to $110 which filled the sell order. When you were selling the coin at $110 you paid 11c (0.1%) fee. Explanation in the book states that you should never have buy_down_interval smaller than 2 times the fee. We can see that by experimenting with buy_down_interval at 0.1% for example. You just sold the coin for $110 paid an 11c fee(you received 109.89) and a new trader wakes up and the price is still $110 so it places a new buy order at the current price - buy_down_interval (109.89) as this order get filled you paid another fee so you don't own full coin but 11c less than full coin. What happened here is you effectively sold and bought and lost 11c in the process without gaining anything - just not selling would leave you with 11c(0.1%) more. You will always lose money if buy_down_interval is below 2*fee as you pay that much for selling + buying.

The value is assigned in section 6.4 is effectively losing money but it's like that to make bot "trade constantly" as price needs to drop a tiny bit to cause further orders to be filled - mainly for ease of testing and showcasing. Probably this should be explained and in the "normal" environment this value should never be smaller than 0.002) - would an inline comment like one for the profit_interval be enough?

I hope it makes more sense now?

marcoflcn commented 3 years ago

It is perfectly clear. Now I also understand why you set that value in the example. I think that add a comment can help to clarify this point.

Thank you so much for your hard work, I'm really glad I can learn and contribute at the same time.

Cinderella-Man commented 3 years ago

I added an inline comment in the code (the same as for the profit_interval value). As mentioned previously this will be released as a part of version 0.1.6.

Thank you very much for contributing to the project :+1: