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

Commit

Permalink
Expand CCXT exchanges enabled on Kelp (#121), closes #117
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsaraf authored Mar 13, 2019
1 parent 6f376fa commit 0631bb1
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 111 deletions.
4 changes: 2 additions & 2 deletions cmd/exchanges.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ var exchanagesCmd = &cobra.Command{

func init() {
exchanagesCmd.Run = func(ccmd *cobra.Command, args []string) {
fmt.Printf(" Exchange\t\tSupports Trading\tDescription\n")
fmt.Printf(" Exchange\t\t\tTested\t\tTrading\t\tDescription\n")
fmt.Printf(" --------------------------------------------------------------------------------\n")
exchanges := plugins.Exchanges()
for _, name := range sortedExchangeKeys(exchanges) {
fmt.Printf(" %-14s\t%v\t\t\t%s\n", name, exchanges[name].TradeEnabled, exchanges[name].Description)
fmt.Printf(" %-24s\t%v\t\t%v\t\t%s\n", name, exchanges[name].Tested, exchanges[name].TradeEnabled, exchanges[name].Description)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions plugins/ccxtExchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type ccxtExchange struct {

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

c, e := sdk.MakeInitializedCcxtExchange(ccxtBaseURL, exchangeName, apiKeys[0])
c, e := sdk.MakeInitializedCcxtExchange(exchangeName, apiKeys[0])
if e != nil {
return nil, fmt.Errorf("error making a ccxt exchange: %s", e)
}
Expand Down
16 changes: 8 additions & 8 deletions plugins/ccxtExchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestGetTickerPrice_Ccxt(t *testing.T) {

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

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

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

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

for exchangeName, apiKey := range supportedTradingExchanges {
t.Run(exchangeName, func(t *testing.T) {
testCcxtExchange, e := makeCcxtExchange("http://localhost:3000", exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
if !assert.NoError(t, e) {
return
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestGetOpenOrders_Ccxt(t *testing.T) {
for exchangeName, apiKey := range supportedTradingExchanges {
for _, pair := range tradingPairs {
t.Run(exchangeName, func(t *testing.T) {
testCcxtExchange, e := makeCcxtExchange("http://localhost:3000", exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
if !assert.NoError(t, e) {
return
}
Expand Down Expand Up @@ -322,7 +322,7 @@ func TestAddOrder_Ccxt(t *testing.T) {
},
} {
t.Run(exchangeName, func(t *testing.T) {
testCcxtExchange, e := makeCcxtExchange("http://localhost:3000", exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
if !assert.NoError(t, e) {
return
}
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestCancelOrder_Ccxt(t *testing.T) {
},
} {
t.Run(exchangeName, func(t *testing.T) {
testCcxtExchange, e := makeCcxtExchange("http://localhost:3000", exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
testCcxtExchange, e := makeCcxtExchange(exchangeName, testOrderConstraints, []api.ExchangeAPIKey{apiKey}, false)
if !assert.NoError(t, e) {
return
}
Expand Down
109 changes: 44 additions & 65 deletions plugins/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stellar/go/support/config"
"github.com/stellar/kelp/api"
"github.com/stellar/kelp/model"
"github.com/stellar/kelp/support/sdk"
"github.com/stellar/kelp/support/utils"
)

Expand Down Expand Up @@ -156,78 +157,56 @@ type exchangeFactoryData struct {

// ExchangeContainer contains the exchange factory method along with some metadata
type ExchangeContainer struct {
SortOrder uint8
SortOrder uint16
Description string
TradeEnabled bool
Tested bool
makeFn func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error)
}

// exchanges is a map of all the exchange integrations available
var exchanges = map[string]ExchangeContainer{
"kraken": ExchangeContainer{
SortOrder: 0,
Description: "Kraken is a popular centralized cryptocurrency exchange (https://www.kraken.com/)",
TradeEnabled: true,
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
return makeKrakenExchange(exchangeFactoryData.apiKeys, exchangeFactoryData.simMode)
},
},
"ccxt-kraken": ExchangeContainer{
SortOrder: 1,
Description: "Kraken is a popular centralized cryptocurrency exchange (via ccxt-rest)",
TradeEnabled: false,
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
return makeCcxtExchange(
"http://localhost:3000",
"kraken",
nil,
exchangeFactoryData.apiKeys,
exchangeFactoryData.simMode,
)
},
},
"ccxt-binance": ExchangeContainer{
SortOrder: 2,
Description: "Binance is a popular centralized cryptocurrency exchange (via ccxt-rest)",
TradeEnabled: true,
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
return makeCcxtExchange(
"http://localhost:3000",
"binance",
nil,
exchangeFactoryData.apiKeys,
exchangeFactoryData.simMode,
)
},
},
"ccxt-poloniex": ExchangeContainer{
SortOrder: 3,
Description: "Poloniex is a popular centralized cryptocurrency exchange (via ccxt-rest)",
TradeEnabled: false,
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
return makeCcxtExchange(
"http://localhost:3000",
"poloniex",
nil,
exchangeFactoryData.apiKeys,
exchangeFactoryData.simMode,
)
},
},
"ccxt-bittrex": ExchangeContainer{
SortOrder: 4,
Description: "Bittrex is a popular centralized cryptocurrency exchange (via ccxt-rest)",
TradeEnabled: false,
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
return makeCcxtExchange(
"http://localhost:3000",
"bittrex",
nil,
exchangeFactoryData.apiKeys,
exchangeFactoryData.simMode,
)
var exchanges map[string]ExchangeContainer

func init() {
// marked as tested if key exists in this map (regardless of bool value)
testedCcxtExchanges := map[string]bool{
"binance": true,
}

exchanges = map[string]ExchangeContainer{
"kraken": ExchangeContainer{
SortOrder: 0,
Description: "Kraken is a popular centralized cryptocurrency exchange",
TradeEnabled: true,
Tested: true,
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
return makeKrakenExchange(exchangeFactoryData.apiKeys, exchangeFactoryData.simMode)
},
},
},
}

// add all CCXT exchanges
sortOrderOffset := len(exchanges)
for i, exchangeName := range sdk.ExchangeList {
key := fmt.Sprintf("ccxt-%s", exchangeName)
_, tested := testedCcxtExchanges[exchangeName]
boundExchangeName := exchangeName

exchanges[key] = ExchangeContainer{
SortOrder: uint16(i + sortOrderOffset),
Description: exchangeName + " is automatically added via ccxt-rest",
TradeEnabled: true,
Tested: tested,
makeFn: func(exchangeFactoryData exchangeFactoryData) (api.Exchange, error) {
return makeCcxtExchange(
boundExchangeName,
nil,
exchangeFactoryData.apiKeys,
exchangeFactoryData.simMode,
)
},
}
}
}

// MakeExchange is a factory method to make an exchange based on a given type
Expand Down
Loading

0 comments on commit 0631bb1

Please sign in to comment.