Skip to content

Commit

Permalink
fix: Make server config for each exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Aug 22, 2024
1 parent 4b596b3 commit f0ca9e2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
10 changes: 5 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const (
)

type Exchange struct {
Name pool.ExchangeName `yaml:"name"`
NodeUrls []string `yaml:"node_urls"`
Pools []pool.Pool `yaml:"pools"`
Name pool.ExchangeName `yaml:"name"`
NodeUrls []string `yaml:"node_urls"`
Pools []pool.Pool `yaml:"pools"`
Server server.ServerConfig `yaml:"server"`
}

type Config struct {
Exchanges []Exchange `yaml:"exchanges"`
Server server.ServerConfig `yaml:"server"`
Exchanges []Exchange `yaml:"exchanges"`
}

func ParseConfig(filePath string) (*Config, error) {
Expand Down
16 changes: 10 additions & 6 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ exchanges:
- base: "WBTC"
quote: "WETH"
address: "testAddress1"
server:
listen_addr: "http://localhost:8080"
- name: camelot
node_urls:
- http://node2.com
pools:
- base: "WETH"
quote: "USDC"
address: "testAddress2"
server:
listen_addr: "http://localhost:8080"
server:
listen_addr: "http://localhost:8081"
`))
if err != nil {
t.Fatal(err)
Expand All @@ -59,11 +61,11 @@ server:

assert.Equal(t, "WBTC/WETH", config.Exchanges[0].Pools[0].ExchangePair())
assert.Equal(t, "testAddress1", config.Exchanges[0].Pools[0].Address)
assert.Equal(t, "http://localhost:8080", config.Exchanges[0].Server.ListenAddr)

assert.Equal(t, "WETH/USDC", config.Exchanges[1].Pools[0].ExchangePair())
assert.Equal(t, "testAddress2", config.Exchanges[1].Pools[0].Address)

assert.Equal(t, "http://localhost:8080", config.Server.ListenAddr)
assert.Equal(t, "http://localhost:8081", config.Exchanges[1].Server.ListenAddr)
}

func TestInvalidExchanges(t *testing.T) {
Expand All @@ -82,15 +84,17 @@ exchanges:
- base: "WBTC"
quote: "WETH"
address: "testAddress1"
server:
listen_addr: "http://localhost:8080"
- name: camelot
node_urls:
- http://node2.com
pools:
- base: "WETH"
quote: "USDC"
address: "testAddress2"
server:
listen_addr: "http://localhost:8080"
server:
listen_addr: "http://localhost:8081"
`))
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
// Start and maintain connection to blockchain nodes
client.MaintainConnection(exchange, i, ctx, logger)

s, err := server.NewServer(logger, cfg.Server, cfg.AssetPairs(exchange), registerBaseHealthCheck)
s, err := server.NewServer(logger, exchange.Server, cfg.AssetPairs(exchange), registerBaseHealthCheck)
if err != nil {
logger.Error().Err(err).Msg("error creating server")
cancel()
Expand Down
31 changes: 25 additions & 6 deletions sample-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ exchanges:
base_decimal: 18
quote_decimal: 18
invert_price: false
server:
listen_addr: "0.0.0.0:5005"
write_timeout: "20s"
read_timeout: "20s"
broadcast_interval: "5s"
- name: "camelot"
node_urls:
- "YOUR NODE URL HERE"
Expand All @@ -62,6 +67,11 @@ exchanges:
base_decimal: 6
quote_decimal: 6
invert_price: false
server:
listen_addr: "0.0.0.0:5006"
write_timeout: "20s"
read_timeout: "20s"
broadcast_interval: "5s"
- name: "balancer"
node_urls:
- "YOUR NODE URL HERE"
Expand Down Expand Up @@ -114,6 +124,11 @@ exchanges:
base_decimal: 18
quote_decimal: 18
invert_price: false
server:
listen_addr: "0.0.0.0:5007"
write_timeout: "20s"
read_timeout: "20s"
broadcast_interval: "5s"
- name: "pancake"
node_urls:
- "YOUR NODE URL HERE"
Expand All @@ -124,6 +139,11 @@ exchanges:
base_decimal: 18
quote_decimal: 18
invert_price: false
server:
listen_addr: "0.0.0.0:5008"
write_timeout: "20s"
read_timeout: "20s"
broadcast_interval: "5s"
- name: "curve"
node_urls:
- "YOUR NODE URL HERE"
Expand All @@ -134,9 +154,8 @@ exchanges:
base_decimal: 18
quote_decimal: 18
invert_price: false

server:
listen_addr: "0.0.0.0:5005"
write_timeout: "20s"
read_timeout: "20s"
broadcast_interval: "5s"
server:
listen_addr: "0.0.0.0:5009"
write_timeout: "20s"
read_timeout: "20s"
broadcast_interval: "5s"

0 comments on commit f0ca9e2

Please sign in to comment.