/tradebot

Primary LanguageElixirMIT LicenseMIT

Tradebot

Tutorial

Apps

Streamer (1)

Chapter 1

Chapter 1 Stream live cryptocurrency prices from the Binance WSS 1.1 Objectives

  • create a new umbrella app
  • create a supervised application inside an umbrella
  • connect to Binance’s WebSocket Stream using the WebSockex module
  • define a TradeEvent struct that will hold incoming data
  • decode incoming events using the Jason module

Connect to Binance API Web Socket Stream (wss)

  • The base endpoint is: wss://stream.binance.com:9443
  • Raw streams are accessed at /ws/<streamName>
  • All symbols for streams are lowercase
  • Stream Name: @trade -> wss://stream.binance.com:9443/ws/xrpusdt@trade

Deps

  • WebSocket To establish a connection to Binance API’s stream

Strategy (2)

Chapter 2 Create a naive trading strategy

a single trader process without supervision 2.1 Objectives

  • create another supervised application inside the umbrella to store our trading strategy
  • define callbacks for events dependent on the state of the trader
  • push events from the streamer app to the naive app

Deps

Run example

# USE TEST NET!
iex> Naive.Trader.start_link(%{symbol: "BTCUSDT", profit_interval: "-0.01"})
iex> Streamer.Binance.start_link("BTCUSDT")

PubSub (3)

Chapter 3

Currently Streamer -send_event-> Naive -GenServer.call-> Naive.Trader (single process) To be able to run in parallel we need to remove the GenServer call process with a single name Also remove the dependency between Streamer and Trader.

Streamer will broadcast and the traders will subscribe

Streamer -broadcast-> PubSub -subscribe-> Trader1 -subscribe-> Trader2 -subscribe-> Trader3

Mock Binance API (4)

Chapter 4

Current:

Trader -oder_limit_buy-> Binance -oder_limit_sell->

Post:

Trader -oder_limit_buy-> Config -> Binance -oder_limit_sell_/ _> BinanceMock

Test

Streamer.start_streaming("BTCUSDT")
Naive.trade("BTCUSDT", "-0.001")