diff --git a/example/config.toml b/example/config.toml index bc960c9b..35beb622 100644 --- a/example/config.toml +++ b/example/config.toml @@ -5,5 +5,6 @@ mode="test" host="0.0.0.0:8080" [api] -haobase_host = "http://127.0.0.1:8082" -haoquote_host = "http://127.0.0.1:8081" \ No newline at end of file +haobase_host = "//127.0.0.1:8082" +haoquote_host = "//127.0.0.1:8081" +haoquote_ws_host = "ws//127.0.0.1:8081" \ No newline at end of file diff --git a/example/demo.html b/example/demo.html index 9c1da32d..1c4dd425 100644 --- a/example/demo.html +++ b/example/demo.html @@ -282,9 +282,14 @@ var symbol = "{{ .symbol }}"; var latest_price = ""; - var PORT = parseInt(window.location.port) + 1; - var APIHOST = "//"+window.location.hostname+":"+PORT; - var WSHOST = "ws://"+window.location.hostname+":"+PORT; + + + + var API_HAOBASE_HOST = {{ .haobase_host | unsafe }}; + var API_HAOQUOTE_HOST = {{ .haoquote_host | unsafe }}; + var WSHOST = {{ .ws_host | unsafe}}; + + if(symbol=="usdjpy"){ kchart.setPriceVolumePrecision(3, 2); }else if(symbol=="eurusd"){ @@ -322,10 +327,13 @@ var mtype = $("input[name='mtype']:checked").val(); $.ajax({ - url: "/api/new_order", + url: "/api/v1/base/order/create", type: "post", dataType: "json", contentType: "application/json", + beforeSend: function(r) { + r.setRequestHeader("User-Id", Cookies.get("user_id")); + }, data: function () { var data = { symbol: symbol, diff --git a/example/example.go b/example/example.go index 981aff42..5ebf29b5 100644 --- a/example/example.go +++ b/example/example.go @@ -1,7 +1,7 @@ package main import ( - "log" + "html/template" "net/http" "os" "strings" @@ -12,7 +12,6 @@ import ( "github.com/spf13/viper" "github.com/urfave/cli/v2" "github.com/yzimhao/trading_engine/utils/app" - "github.com/zehuamama/balancer/proxy" _ "net/http/pprof" @@ -85,25 +84,15 @@ func main() { func startWeb(host string) { web = gin.New() + web.SetFuncMap(template.FuncMap{ + "unsafe": func(str string) template.HTML { + return template.HTML(str) + }, + }) + web.LoadHTMLGlob("./*.html") web.StaticFS("/statics", http.Dir("./statics")) - //代理交易系统的后端接口,实际应用中可以用nginx直接代理 - web.Any("/api/v1/base/*any", func(ctx *gin.Context) { - httpProxy, err := proxy.NewHTTPProxy([]string{viper.GetString("api.haobase_host")}, "round-robin") - if err != nil { - log.Fatalf("create proxy error: %s", err) - } - httpProxy.ServeHTTP(ctx.Writer, ctx.Request) - }) - web.Any("/api/v1/quote/*any", func(ctx *gin.Context) { - httpProxy, err := proxy.NewHTTPProxy([]string{viper.GetString("api.haoquote_host")}, "round-robin") - if err != nil { - log.Fatalf("create proxy error: %s", err) - } - httpProxy.ServeHTTP(ctx.Writer, ctx.Request) - }) - web.GET("/:symbol", func(c *gin.Context) { support := []string{"usdjpy", "eurusd"} symbol := strings.ToLower(c.Param("symbol")) @@ -114,7 +103,10 @@ func startWeb(host string) { } c.HTML(200, "demo.html", gin.H{ - "symbol": symbol, + "haobase_host": viper.GetString("api.haobase_host"), + "haoquote_host": viper.GetString("api.haoquote_host"), + "ws_host": viper.GetString("api.haoquote_ws_host"), + "symbol": symbol, }) })