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

Commit 3c9af0c

Browse files
authored
allow setting custom URL for CCXT-rest server (#167), closes #131
1 parent 5416d78 commit 3c9af0c

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

cmd/trade.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/stellar/kelp/support/monitoring"
2424
"github.com/stellar/kelp/support/networking"
2525
"github.com/stellar/kelp/support/prefs"
26+
"github.com/stellar/kelp/support/sdk"
2627
"github.com/stellar/kelp/support/utils"
2728
"github.com/stellar/kelp/trader"
2829
)
@@ -423,6 +424,14 @@ func runTradeCmd(options inputs) {
423424
}
424425
}
425426

427+
if botConfig.CcxtRestURL != nil {
428+
e := sdk.SetBaseURL(*botConfig.CcxtRestURL)
429+
if e != nil {
430+
logger.Fatal(l, fmt.Errorf("unable to set CCXT-rest URL to '%s': %s", *botConfig.CcxtRestURL, e))
431+
}
432+
}
433+
l.Infof("using CCXT-rest URL: %s\n", sdk.GetBaseURL())
434+
426435
ieif := plugins.MakeIEIF(botConfig.IsTradingSdex())
427436
network := utils.ParseNetwork(botConfig.HorizonURL)
428437
exchangeShim, sdex := makeExchangeShimSdex(

examples/configs/trader/sample_trader.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ FILL_TRACKER_DELETE_CYCLES_THRESHOLD=0
4848
# the url for your horizon instance. If this url contains the string "test" then the bot assumes it is using the test network.
4949
HORIZON_URL="https://horizon-testnet.stellar.org"
5050

51+
# the URL to use for your CCXT-rest instance. Defaults to http://localhost:3000 if unset
52+
#CCXT_REST_URL="http://localhost:3000"
53+
5154
# specify parameters for how we compute the operation fee from the /fee_stats endpoint
5255
[FEE]
5356
# trigger when "ledger_capacity_usage" in /fee_stats is >= this value

support/sdk/ccxt.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@ import (
1616
)
1717

1818
// ccxtBaseURL should not have suffix of '/'
19-
const ccxtBaseURL = "http://localhost:3000"
19+
var ccxtBaseURL = "http://localhost:3000"
20+
21+
// SetBaseURL allows setting the base URL for ccxt
22+
func SetBaseURL(baseURL string) error {
23+
if strings.HasSuffix(baseURL, "/") {
24+
return fmt.Errorf("invalid format for baseURL, should not end with trailing '/': %s", baseURL)
25+
}
26+
ccxtBaseURL = baseURL
27+
return nil
28+
}
29+
30+
// GetBaseURL returns the base URL for ccxt
31+
func GetBaseURL() string {
32+
return ccxtBaseURL
33+
}
2034

2135
// Ccxt Rest SDK (https://github.com/franz-see/ccxt-rest, https://github.com/ccxt/ccxt/)
2236
type Ccxt struct {

trader/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type BotConfig struct {
3232
FillTrackerSleepMillis uint32 `valid:"-" toml:"FILL_TRACKER_SLEEP_MILLIS"`
3333
FillTrackerDeleteCyclesThreshold int64 `valid:"-" toml:"FILL_TRACKER_DELETE_CYCLES_THRESHOLD"`
3434
HorizonURL string `valid:"-" toml:"HORIZON_URL"`
35+
CcxtRestURL *string `valid:"-" toml:"CCXT_REST_URL"`
3536
Fee *FeeConfig `valid:"-" toml:"FEE"`
3637
CentralizedPricePrecisionOverride *int8 `valid:"-" toml:"CENTRALIZED_PRICE_PRECISION_OVERRIDE"`
3738
CentralizedVolumePrecisionOverride *int8 `valid:"-" toml:"CENTRALIZED_VOLUME_PRECISION_OVERRIDE"`

0 commit comments

Comments
 (0)