2021-12-09 04:13:35 +00:00
|
|
|
# Adding New Exchange
|
|
|
|
|
2021-12-09 04:17:56 +00:00
|
|
|
Open an issue and paste the following checklist to that issue.
|
|
|
|
|
|
|
|
You should send multiple small pull request to implement them.
|
2021-12-09 04:13:35 +00:00
|
|
|
|
|
|
|
**Please avoid sending a pull request with huge changes**
|
|
|
|
|
|
|
|
## Checklist
|
|
|
|
|
2021-12-27 16:21:07 +00:00
|
|
|
Exchange Interface - minimum requirement for trading
|
2021-12-09 04:13:35 +00:00
|
|
|
|
|
|
|
- [ ] QueryMarkets
|
|
|
|
- [ ] QueryTickers
|
2021-12-27 16:21:07 +00:00
|
|
|
- [ ] QueryOpenOrders
|
2021-12-09 04:13:35 +00:00
|
|
|
- [ ] SubmitOrders
|
2021-12-27 16:21:07 +00:00
|
|
|
- [ ] CancelOrders
|
|
|
|
- [ ] NewStream
|
|
|
|
|
|
|
|
Trading History Service Interface - used for syncing user trading data
|
|
|
|
|
|
|
|
- [ ] QueryClosedOrders
|
|
|
|
- [ ] QueryTrades
|
|
|
|
|
|
|
|
Back-testing service - kline data is used for back-testing
|
|
|
|
|
|
|
|
- [ ] QueryKLines
|
2021-12-09 04:13:35 +00:00
|
|
|
|
|
|
|
Convert functions:
|
|
|
|
|
|
|
|
- [ ] MarketData convert functions
|
|
|
|
- [ ] toGlobalMarket
|
|
|
|
- [ ] toGlobalTicker
|
|
|
|
- [ ] toGlobalKLine
|
|
|
|
- [ ] UserData convert functions
|
|
|
|
- [ ] toGlobalOrder
|
|
|
|
- [ ] toGlobalTrade
|
|
|
|
- [ ] toGlobalAccount
|
2021-12-09 04:17:05 +00:00
|
|
|
- [ ] toGlobalBalance
|
2021-12-09 04:13:35 +00:00
|
|
|
|
|
|
|
Stream
|
|
|
|
|
|
|
|
- [ ] UserDataStream
|
|
|
|
- [ ] Trade message parser
|
|
|
|
- [ ] Order message parser
|
|
|
|
- [ ] Account message parser
|
|
|
|
- [ ] Balance message parser
|
|
|
|
- [ ] MarketDataStream
|
|
|
|
- [ ] OrderBook message parser (or depth)
|
2021-12-09 04:16:47 +00:00
|
|
|
- [ ] KLine message parser (required for backtesting)
|
|
|
|
- [ ] Public trade message parser (optional)
|
|
|
|
- [ ] Ticker message parser (optional)
|
2021-12-09 04:18:44 +00:00
|
|
|
- [ ] ping/pong handling.
|
|
|
|
- [ ] heart-beat hanlding or keep-alive handling.
|
2021-12-09 04:13:35 +00:00
|
|
|
- [ ] handling reconnect
|
|
|
|
|
2021-12-09 04:16:47 +00:00
|
|
|
Database
|
|
|
|
|
|
|
|
- [ ] Add a new kline table for the exchange (this is required for back-testing)
|
|
|
|
- [ ] Add MySQL migration SQL
|
|
|
|
- [ ] Add SQLite migration SQL
|
|
|
|
|
2021-12-09 04:13:35 +00:00
|
|
|
Exchange Factory
|
|
|
|
|
|
|
|
- [ ] Add the exchange constructor to the exchange instance factory function.
|
|
|
|
- [ ] Add extended fields to the ExchangeSession struct. (optional)
|
2021-12-21 16:31:00 +00:00
|
|
|
|
|
|
|
# Implementation
|
|
|
|
|
|
|
|
Go to `pkg/types/exchange.go` and add your exchange type:
|
|
|
|
|
|
|
|
```
|
|
|
|
const (
|
|
|
|
ExchangeMax = ExchangeName("max")
|
|
|
|
ExchangeBinance = ExchangeName("binance")
|
|
|
|
ExchangeFTX = ExchangeName("ftx")
|
|
|
|
ExchangeOKEx = ExchangeName("okex")
|
|
|
|
ExchangeKucoin = ExchangeName("kucoin")
|
|
|
|
ExchangeBacktest = ExchangeName("backtest")
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|
Go to `pkg/cmd/cmdutil/exchange.go` and add your exchange to the factory
|
|
|
|
|
|
|
|
```
|
|
|
|
func NewExchangeStandard(n types.ExchangeName, key, secret, passphrase, subAccount string) (types.Exchange, error) {
|
|
|
|
switch n {
|
|
|
|
|
|
|
|
case types.ExchangeFTX:
|
|
|
|
return ftx.NewExchange(key, secret, subAccount), nil
|
|
|
|
|
|
|
|
case types.ExchangeBinance:
|
|
|
|
return binance.New(key, secret), nil
|
|
|
|
|
|
|
|
case types.ExchangeOKEx:
|
|
|
|
return okex.New(key, secret, passphrase), nil
|
|
|
|
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-12-25 16:27:52 +00:00
|
|
|
## Testing order book stream
|
|
|
|
|
|
|
|
```shell
|
|
|
|
godotenv -f .env.local -- go run ./cmd/bbgo orderbook --config config/bbgo.yaml --session kucoin --symbol BTCUSDT
|
|
|
|
```
|
2021-12-22 17:54:53 +00:00
|
|
|
|
|
|
|
## Testing user data stream
|
|
|
|
|
|
|
|
```shell
|
2021-12-25 16:27:52 +00:00
|
|
|
godotenv -f .env.local -- go run ./cmd/bbgo --config config/bbgo.yaml userdatastream --session kucoin
|
|
|
|
```
|
|
|
|
|
|
|
|
### Testing order submit
|
|
|
|
|
|
|
|
```shell
|
|
|
|
godotenv -f .env.local -- go run ./cmd/bbgo submit-order --session=kucoin --symbol=BTCUSDT --side=buy --price=18000 --quantity=0.001
|
2021-12-25 17:27:22 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Testing open orders query
|
|
|
|
|
|
|
|
```shell
|
|
|
|
godotenv -f .env.local -- go run ./cmd/bbgo list-orders --session kucoin --symbol=BTCUSDT open
|
|
|
|
godotenv -f .env.local -- go run ./cmd/bbgo list-orders --session kucoin --symbol=BTCUSDT closed
|
|
|
|
```
|
|
|
|
|
|
|
|
### Testing order cancel
|
|
|
|
|
|
|
|
```shell
|
|
|
|
godotenv -f .env.local -- go run ./cmd/bbgo cancel-order --session kucoin --order-uuid 61c745c44592c200014abdcf
|
|
|
|
```
|