diff --git a/.gitignore b/.gitignore index db1f454..fd31e4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /config_dev.json /config_prod.json -/.idea/ \ No newline at end of file +/.idea/ +/.DS_Store \ No newline at end of file diff --git a/go.mod b/go.mod index bce7672..6b4a7f5 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,8 @@ -module kucoin-api-test +module kucoin-api-demo go 1.14 require ( - github.com/Kucoin/kucoin-go-sdk v1.2.6 github.com/gorilla/websocket v1.4.0 github.com/pkg/errors v0.8.1 github.com/sirupsen/logrus v1.4.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a1db8b4 --- /dev/null +++ b/go.sum @@ -0,0 +1,17 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/main.go b/main.go index 310668d..3879ee8 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "io/ioutil" - "kucoin-api-test/sdk" + "kucoin-api-demo/sdk" "log" "os" "reflect" @@ -14,7 +14,7 @@ import ( var ( kucoin *sdk.ApiService - PATH = "./config.json.example" + PATH = "./config.json" ) func main() { @@ -23,23 +23,24 @@ func main() { var apiSkipVerifyTls bool // read config from json file - file, err := ioutil.ReadFile(PATH) - if err != nil { - log.Fatal("error when read configuration from json file:", err) - return - } var config ApiConfig - // unmarshal config data - err = json.Unmarshal(file, &config) - if err != nil { - log.Fatal("error when unmarshal config from json file:", err) - return + file, er := ioutil.ReadFile(PATH) + if er != nil { + log.Println("Failed to read configuration from json file:", er) + log.Println("Now please input api information manually.") + }else{ + // unmarshal config data + err := json.Unmarshal(file, &config) + if err != nil { + log.Fatal("error when unmarshal config from json file:", err) + return + } } // if we have configuration from json file if len(config.ApiBaseURI) > 0 { apiURI = config.ApiBaseURI } else { - log.Println("please input api base URI,such as:https://api.kumex.com") + log.Println("please input api base URI,such as:https://api.kucoin.com") fmt.Scanf("%s", &apiURI) } @@ -91,6 +92,7 @@ func main() { call(apiMap, apiName, params) } +// initial api configuration information from json file. type ApiConfig struct { ApiBaseURI string `json:ApiBaseURI` ApiKey string `json:ApiKey`