Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go Crypto Trading

Yo-An Lin
November 21, 2020

Go Crypto Trading

In the slides, we introduce the background of Bitcoin's origin, explain public finance, and why decentralized finance might work. Lastly, introduce BBGO's trading framework and the strategies.

Yo-An Lin

November 21, 2020
Tweet

More Decks by Yo-An Lin

Other Decks in Technology

Transcript

  1. Yo-An Lin (c9s) 2020 Nov 1 Go Crypto Trading Build

    your own crypto trading bot in few minutes.
  2. How Junk Bond Works? Interest (high yield) Issue corporate bond

    Corporate (Low Credit Rating) Bank Investor High yield bond
  3. Algorithmic trading is a method of executing orders using automated

    pre-programmed trading instructions accounting for variables such as time, price, and volume. This type of trading was developed to make use of the speed and data processing advantages that computers have over human traders.
  4. Quantitative analysis is the use of mathematical and statistical methods

    (mathematical finance) in finance. Those working in the field are quantitative analysts (or, in financial jargon, a quant).
  5. James Simons American mathematician, Billionaire hedge fund manager, Former research

    staff of the Communications Research Division of the Institute for Defense Analyses (IDA)
  6. 根據彭博社億萬富翁指數 (Bloomberg Billionaire Index) 顯⽰,Simons 在 2016 年的⾝家⼤約值 155 億美元左右。根據

    Hedge Fund Research 報導,James Simons 在 2016 年的收入為 16 億美元,位於世界對沖基⾦經理收入榜單⾸位。
  7. • Market neutral strategy • Swing trading strategy • News

    trading strategy • Signal trading strategy • Day trading • ……
  8. Hedging is a strategy for reducing exposure to investment risk.

    An investor can hedge the risk of one investment by taking an offsetting position in another investment. The values of the offsetting investments should be inversely correlated.
  9. BBGO Trading framework • Open Source & Transparency - you

    run what you can see. • KISS principle designed framework - simple, easy to use for users. • Minimalist design strategy interface - ~20 lines go code to implement a new strategy. • One config to rule them all. • Multi-exchange session support. • Run multiple strategies in one process.
  10. Exchange RESTful API WebSocket FIX protocol BBGO Balance Update Trade

    Update Order Update Place Order Matching Engine Order Book Strategy #1 Strategy #2 Strategy #3 Public Market Data
  11. exchangeStrategies: - on: binance bollgrid: symbol: BTCUSDT interval: 5m gridNumber:

    20 quantity: 0.01 profitSpread: 30.0 策略可以掛在任何⼀個交易所
  12. riskControls: sessionBased: # "binance" is the session name that you

    want to configure the risk control binance: # orderExecutor is one of the risk control orderExecutor: # symbol-routed order executor bySymbol: BTCUSDT: # basic risk control order executor basic: minQuoteBalance: 100.0 maxBaseAssetBalance: 3.0 minBaseAssetBalance: 0.0 maxOrderAmount: 1000.0 下單的風險控管
  13. type Strategy struct { Symbol string `json:"symbol"` } func (s

    *Strategy) Subscribe(session *bbgo.ExchangeSession) { } func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { return nil }
  14. func init() { bbgo.RegisterStrategy("skeleton", &Strategy{}) } type Strategy struct {

    Symbol string `json:"symbol"` } func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) { session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"}) } func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { session.Stream.OnKLineClosed(func(kline types.KLine) { _, err := orderExecutor.SubmitOrders(ctx, types.SubmitOrder{ Symbol: kline.Symbol, Side: types.SideTypeBuy, Type: types.OrderTypeMarket, Quantity: 0.01, }) if err != nil { log.WithError(err).Error("submit order error") } }) return nil } 註冊交易策略
  15. func init() { bbgo.RegisterStrategy("skeleton", &Strategy{}) } type Strategy struct {

    Symbol string `json:"symbol"` } func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) { session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"}) } func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { session.Stream.OnKLineClosed(func(kline types.KLine) { _, err := orderExecutor.SubmitOrders(ctx, types.SubmitOrder{ Symbol: kline.Symbol, Side: types.SideTypeBuy, Type: types.OrderTypeMarket, Quantity: 0.01, }) if err != nil { log.WithError(err).Error("submit order error") } }) return nil } 策略的 struct, ⽤來讀設定
  16. func init() { bbgo.RegisterStrategy("skeleton", &Strategy{}) } type Strategy struct {

    Symbol string `json:"symbol"` } func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) { session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"}) } func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { session.Stream.OnKLineClosed(func(kline types.KLine) { _, err := orderExecutor.SubmitOrders(ctx, types.SubmitOrder{ Symbol: kline.Symbol, Side: types.SideTypeBuy, Type: types.OrderTypeMarket, Quantity: 0.01, }) if err != nil { log.WithError(err).Error("submit order error") } }) return nil } 策略訂閱 K-line 資料
  17. func init() { bbgo.RegisterStrategy("skeleton", &Strategy{}) } type Strategy struct {

    Symbol string `json:"symbol"` } func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) { session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"}) } func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { session.Stream.OnKLineClosed(func(kline types.KLine) { _, err := orderExecutor.SubmitOrders(ctx, types.SubmitOrder{ Symbol: kline.Symbol, Side: types.SideTypeBuy, Type: types.OrderTypeMarket, Quantity: 0.01, }) if err != nil { log.WithError(err).Error("submit order error") } }) return nil } K-line 結束就下單