-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
154 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,58 @@ | ||
package configtest | ||
|
||
import ( | ||
"github.com/spf13/viper" | ||
"github.com/BurntSushi/toml" | ||
"log" | ||
"path/filepath" | ||
) | ||
|
||
var ( | ||
testDataDir = "../../testdata/" | ||
) | ||
|
||
type Config struct { | ||
BinanceFutures TestConfig `toml:"binancefutures"` | ||
Bitmex TestConfig `toml:"bitmex"` | ||
Bybit TestConfig `toml:"bybit"` | ||
Deribit TestConfig `toml:"deribit"` | ||
Hbdm TestConfig `toml:"hbdm"` | ||
HbdmSwap TestConfig `toml:"hbdmswap"` | ||
OkexFutures TestConfig `toml:"okexfutures"` | ||
OkexSwap TestConfig `toml:"okexswap"` | ||
} | ||
|
||
type TestConfig struct { | ||
AccessKey string | ||
SecretKey string | ||
Passphrase string | ||
Testnet bool | ||
ProxyURL string | ||
AccessKey string `toml:"access_key"` | ||
SecretKey string `toml:"secret_key"` | ||
Passphrase string `toml:"passphrase"` | ||
Testnet bool `toml:"testnet"` | ||
ProxyURL string `toml:"proxy_url"` | ||
} | ||
|
||
func LoadTestConfig(name string) *TestConfig { | ||
viper.SetConfigName("configtest") | ||
viper.AddConfigPath("../../testdata") | ||
err := viper.ReadInConfig() | ||
if err != nil { | ||
fPath := filepath.Join(testDataDir, "configtest.toml") | ||
var cfg Config | ||
if _, err := toml.DecodeFile(fPath, &cfg); err != nil { | ||
log.Panic(err) | ||
} | ||
cfg := &TestConfig{} | ||
items := viper.GetStringMapString(name) | ||
if len(items) == 0 { | ||
log.Panic("test config not found [configtest.yaml]") | ||
} | ||
for key, value := range items { | ||
switch key { | ||
case "access_key": | ||
cfg.AccessKey = value | ||
case "secret_key": | ||
cfg.SecretKey = value | ||
case "passphrase": | ||
cfg.Passphrase = value | ||
case "testnet": | ||
cfg.Testnet = value == "true" | ||
case "proxy_url": | ||
cfg.ProxyURL = value | ||
} | ||
tCfg := &TestConfig{} | ||
switch name { | ||
case "binancefutures": | ||
tCfg = &cfg.BinanceFutures | ||
case "bitmex": | ||
tCfg = &cfg.Bitmex | ||
case "bybit": | ||
tCfg = &cfg.Bybit | ||
case "deribit": | ||
tCfg = &cfg.Deribit | ||
case "hbdm": | ||
tCfg = &cfg.Hbdm | ||
case "hbdmswap": | ||
tCfg = &cfg.HbdmSwap | ||
case "okexfutures": | ||
tCfg = &cfg.OkexFutures | ||
case "okexswap": | ||
tCfg = &cfg.OkexSwap | ||
} | ||
return cfg | ||
return tCfg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package configtest | ||
|
||
import "testing" | ||
|
||
func TestLoadTestConfig(t *testing.T) { | ||
testDataDir = "../testdata/" | ||
tCfg := LoadTestConfig("bybit") | ||
t.Logf("%#v", tCfg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package serve | ||
|
||
import ( | ||
"github.com/BurntSushi/toml" | ||
"testing" | ||
) | ||
|
||
func TestSetupConfig(t *testing.T) { | ||
var c SConfig | ||
if _, err := toml.DecodeFile("../testdata/serve-config-sample.toml", &c); err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
t.Logf("%#v", c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# example: | ||
# proxy_url = "socks5://127.0.0.1:1080" | ||
|
||
[binancefutures] | ||
access_key = "" | ||
secret_key = "" | ||
testnet = true | ||
proxy_url = "" | ||
|
||
[bitmex] | ||
access_key = "" | ||
secret_key = "" | ||
testnet = true | ||
proxy_url = "" | ||
|
||
[bybit] | ||
access_key = "" | ||
secret_key = "" | ||
testnet = true | ||
proxy_url = "" | ||
|
||
[deribit] | ||
access_key = "" | ||
secret_key = "" | ||
testnet = true | ||
proxy_url = "" | ||
|
||
[hbdm] | ||
access_key = "" | ||
secret_key = "" | ||
testnet = false | ||
proxy_url = "socks5://127.0.0.1:1080" | ||
|
||
[hbdmswap] | ||
access_key = "" | ||
secret_key = "" | ||
testnet = false | ||
proxy_url = "socks5://127.0.0.1:1080" | ||
|
||
[okexfutures] | ||
access_key = "" | ||
secret_key = "" | ||
passphrase = "" | ||
testnet = false | ||
proxy_url = "" | ||
|
||
okexswap: | ||
access_key: "" | ||
secret_key: "" | ||
passphrase: "" | ||
testnet: false | ||
proxy_url: "" | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[[exchange]] | ||
name = "deribit" | ||
debug_mode = false | ||
access_key = "" | ||
secret_key = "" | ||
testnet = true | ||
websocket = false | ||
|
||
[option] | ||
log_only = false # 只输出日志 | ||
currency = "BTC" # 货币 BTC | ||
currency_pair = "BTC-PERPETUAL" # BTC |