Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit 0631bb1

Browse files
authored
Expand CCXT exchanges enabled on Kelp (#121), closes #117
1 parent 6f376fa commit 0631bb1

6 files changed

Lines changed: 93 additions & 111 deletions

File tree

cmd/exchanges.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ var exchanagesCmd = &cobra.Command{
1515

1616
func init() {
1717
exchanagesCmd.Run = func(ccmd *cobra.Command, args []string) {
18-
fmt.Printf(" Exchange\t\tSupports Trading\tDescription\n")
18+
fmt.Printf(" Exchange\t\t\tTested\t\tTrading\t\tDescription\n")
1919
fmt.Printf(" --------------------------------------------------------------------------------\n")
2020
exchanges := plugins.Exchanges()
2121
for _, name := range sortedExchangeKeys(exchanges) {
22-
fmt.Printf(" %-14s\t%v\t\t\t%s\n", name, exchanges[name].TradeEnabled, exchanges[name].Description)
22+
fmt.Printf(" %-24s\t%v\t\t%v\t\t%s\n", name, exchanges[name].Tested, exchanges[name].TradeEnabled, exchanges[name].Description)
2323
}
2424
}
2525
}

plugins/ccxtExchange.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type ccxtExchange struct {
2626

2727
// makeCcxtExchange is a factory method to make an exchange using the CCXT interface
2828
func makeCcxtExchange(
29-
ccxtBaseURL string,
3029
exchangeName string,
3130
orderConstraintOverrides map[model.TradingPair]model.OrderConstraints,
3231
apiKeys []api.ExchangeAPIKey,
@@ -40,7 +39,7 @@ func makeCcxtExchange(
4039
return nil, fmt.Errorf("need exactly 1 ExchangeAPIKey")
4140
}
4241

43-
c, e := sdk.MakeInitializedCcxtExchange(ccxtBaseURL, exchangeName, apiKeys[0])
42+
c, e := sdk.MakeInitializedCcxtExchange(exchangeName, apiKeys[0])
4443
if e != nil {
4544
return nil, fmt.Errorf("error making a ccxt exchange: %s", e)
4645
}

plugins/ccxtExchange_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestGetTickerPrice_Ccxt(t *testing.T) {
2828

2929
for _, exchangeName := range supportedExchanges {
3030
t.Run(exchangeName, func(t *testing.T) {
31-
testCcxtExchange, e := makeCcxtExchange("http://localhost:3000", exchangeName, testOrderConstraints, []api.ExchangeAPIKey{emptyAPIKey}, false)
31+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{emptyAPIKey}, false)
3232
if !assert.NoError(t, e) {
3333
return
3434
}
@@ -55,7 +55,7 @@ func TestGetOrderBook_Ccxt(t *testing.T) {
5555

5656
for _, exchangeName := range supportedExchanges {
5757
t.Run(exchangeName, func(t *testing.T) {
58-
testCcxtExchange, e := makeCcxtExchange("http://localhost:3000", exchangeName, testOrderConstraints, []api.ExchangeAPIKey{emptyAPIKey}, false)
58+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{emptyAPIKey}, false)
5959
if !assert.NoError(t, e) {
6060
return
6161
}
@@ -88,7 +88,7 @@ func TestGetTrades_Ccxt(t *testing.T) {
8888

8989
for _, exchangeName := range supportedExchanges {
9090
t.Run(exchangeName, func(t *testing.T) {
91-
testCcxtExchange, e := makeCcxtExchange("http://localhost:3000", exchangeName, testOrderConstraints, []api.ExchangeAPIKey{emptyAPIKey}, false)
91+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{emptyAPIKey}, false)
9292
if !assert.NoError(t, e) {
9393
return
9494
}
@@ -113,7 +113,7 @@ func TestGetTradeHistory_Ccxt(t *testing.T) {
113113

114114
for exchangeName, apiKey := range supportedTradingExchanges {
115115
t.Run(exchangeName, func(t *testing.T) {
116-
testCcxtExchange, e := makeCcxtExchange("http://localhost:3000", exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
116+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
117117
if !assert.NoError(t, e) {
118118
return
119119
}
@@ -171,7 +171,7 @@ func TestGetAccountBalances_Ccxt(t *testing.T) {
171171

172172
for exchangeName, apiKey := range supportedTradingExchanges {
173173
t.Run(exchangeName, func(t *testing.T) {
174-
testCcxtExchange, e := makeCcxtExchange("http://localhost:3000", exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
174+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
175175
if !assert.NoError(t, e) {
176176
return
177177
}
@@ -216,7 +216,7 @@ func TestGetOpenOrders_Ccxt(t *testing.T) {
216216
for exchangeName, apiKey := range supportedTradingExchanges {
217217
for _, pair := range tradingPairs {
218218
t.Run(exchangeName, func(t *testing.T) {
219-
testCcxtExchange, e := makeCcxtExchange("http://localhost:3000", exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
219+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
220220
if !assert.NoError(t, e) {
221221
return
222222
}
@@ -322,7 +322,7 @@ func TestAddOrder_Ccxt(t *testing.T) {
322322
},
323323
} {
324324
t.Run(exchangeName, func(t *testing.T) {
325-
testCcxtExchange, e := makeCcxtExchange("http://localhost:3000", exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
325+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
326326
if !assert.NoError(t, e) {
327327
return
328328
}
@@ -372,7 +372,7 @@ func TestCancelOrder_Ccxt(t *testing.T) {
372372
},
373373
} {
374374
t.Run(exchangeName, func(t *testing.T) {
375-
testCcxtExchange, e := makeCcxtExchange("http://localhost:3000", exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
375+
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
376376
if !assert.NoError(t, e) {
377377
return
378378
}

plugins/factory.go

Lines changed: 44 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/stellar/go/support/config"
99
"github.com/stellar/kelp/api"
1010
"github.com/stellar/kelp/model"
11+
"github.com/stellar/kelp/support/sdk"
1112
"github.com/stellar/kelp/support/utils"
1213
)
1314

@@ -156,78 +157,56 @@ type exchangeFactoryData struct {
156157

157158
// ExchangeContainer contains the exchange factory method along with some metadata
158159
type ExchangeContainer struct {
159-
SortOrder uint8
160+
SortOrder uint16
160161
Description string
161162
TradeEnabled bool
163+
Tested bool
162164
makeFn func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error)
163165
}
164166

165167
// exchanges is a map of all the exchange integrations available
166-
var exchanges = map[string]ExchangeContainer{
167-
"kraken": ExchangeContainer{
168-
SortOrder: 0,
169-
Description: "Kraken is a popular centralized cryptocurrency exchange (https://www.kraken.com/)",
170-
TradeEnabled: true,
171-
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
172-
return makeKrakenExchange(exchangeFactoryData.apiKeys, exchangeFactoryData.simMode)
173-
},
174-
},
175-
"ccxt-kraken": ExchangeContainer{
176-
SortOrder: 1,
177-
Description: "Kraken is a popular centralized cryptocurrency exchange (via ccxt-rest)",
178-
TradeEnabled: false,
179-
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
180-
return makeCcxtExchange(
181-
"http://localhost:3000",
182-
"kraken",
183-
nil,
184-
exchangeFactoryData.apiKeys,
185-
exchangeFactoryData.simMode,
186-
)
187-
},
188-
},
189-
"ccxt-binance": ExchangeContainer{
190-
SortOrder: 2,
191-
Description: "Binance is a popular centralized cryptocurrency exchange (via ccxt-rest)",
192-
TradeEnabled: true,
193-
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
194-
return makeCcxtExchange(
195-
"http://localhost:3000",
196-
"binance",
197-
nil,
198-
exchangeFactoryData.apiKeys,
199-
exchangeFactoryData.simMode,
200-
)
201-
},
202-
},
203-
"ccxt-poloniex": ExchangeContainer{
204-
SortOrder: 3,
205-
Description: "Poloniex is a popular centralized cryptocurrency exchange (via ccxt-rest)",
206-
TradeEnabled: false,
207-
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
208-
return makeCcxtExchange(
209-
"http://localhost:3000",
210-
"poloniex",
211-
nil,
212-
exchangeFactoryData.apiKeys,
213-
exchangeFactoryData.simMode,
214-
)
215-
},
216-
},
217-
"ccxt-bittrex": ExchangeContainer{
218-
SortOrder: 4,
219-
Description: "Bittrex is a popular centralized cryptocurrency exchange (via ccxt-rest)",
220-
TradeEnabled: false,
221-
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
222-
return makeCcxtExchange(
223-
"http://localhost:3000",
224-
"bittrex",
225-
nil,
226-
exchangeFactoryData.apiKeys,
227-
exchangeFactoryData.simMode,
228-
)
168+
var exchanges map[string]ExchangeContainer
169+
170+
func init() {
171+
// marked as tested if key exists in this map (regardless of bool value)
172+
testedCcxtExchanges := map[string]bool{
173+
"binance": true,
174+
}
175+
176+
exchanges = map[string]ExchangeContainer{
177+
"kraken": ExchangeContainer{
178+
SortOrder: 0,
179+
Description: "Kraken is a popular centralized cryptocurrency exchange",
180+
TradeEnabled: true,
181+
Tested: true,
182+
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
183+
return makeKrakenExchange(exchangeFactoryData.apiKeys, exchangeFactoryData.simMode)
184+
},
229185
},
230-
},
186+
}
187+
188+
// add all CCXT exchanges
189+
sortOrderOffset := len(exchanges)
190+
for i, exchangeName := range sdk.ExchangeList {
191+
key := fmt.Sprintf("ccxt-%s", exchangeName)
192+
_, tested := testedCcxtExchanges[exchangeName]
193+
boundExchangeName := exchangeName
194+
195+
exchanges[key] = ExchangeContainer{
196+
SortOrder: uint16(i + sortOrderOffset),
197+
Description: exchangeName + " is automatically added via ccxt-rest",
198+
TradeEnabled: true,
199+
Tested: tested,
200+
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
201+
return makeCcxtExchange(
202+
boundExchangeName,
203+
nil,
204+
exchangeFactoryData.apiKeys,
205+
exchangeFactoryData.simMode,
206+
)
207+
},
208+
}
209+
}
231210
}
232211

233212
// MakeExchange is a factory method to make an exchange based on a given type

0 commit comments

Comments
 (0)