wr 6 éve
szülő
commit
08422d607b
3 módosított fájl, 121 hozzáadás és 104 törlés
  1. 116 101
      server/cmd/webproxy/main.go
  2. 2 2
      server/cmd/webproxys/main.go
  3. 3 1
      server/tick/ds_bty.go

+ 116 - 101
server/cmd/webproxy/main.go

@@ -126,6 +126,100 @@ func readConf() (*Conf, error) {
 	return conf, nil
 }
 
+func getStringSTK(stk SpecialTick, insId string) StringSpecialTick {
+	sstk := StringSpecialTick{
+		Timestamp: fmt.Sprintf("%d", stk.Timestamp),
+		Open:      fmt.Sprintf("%.4f", stk.Open),
+	}
+	switch insId {
+	case "bty_BCCBTC":
+		sstk.Last = fmt.Sprintf("%.4f", stk.Last)
+		sstk.High = fmt.Sprintf("%.4f", stk.High)
+		sstk.Low = fmt.Sprintf("%.4f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.4f", stk.Volume)
+	case "bty_ETHBTC":
+		sstk.Last = fmt.Sprintf("%.5f", stk.Last)
+		sstk.High = fmt.Sprintf("%.5f", stk.High)
+		sstk.Low = fmt.Sprintf("%.5f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.3f", stk.Volume)
+	case "bty_ETCBTC":
+		sstk.Last = fmt.Sprintf("%.6f", stk.Last)
+		sstk.High = fmt.Sprintf("%.6f", stk.High)
+		sstk.Low = fmt.Sprintf("%.6f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
+	case "bty_ZECBTC":
+		sstk.Last = fmt.Sprintf("%.5f", stk.Last)
+		sstk.High = fmt.Sprintf("%.5f", stk.High)
+		sstk.Low = fmt.Sprintf("%.5f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.3f", stk.Volume)
+	case "bty_LTCBTC":
+		sstk.Last = fmt.Sprintf("%.6f", stk.Last)
+		sstk.High = fmt.Sprintf("%.6f", stk.High)
+		sstk.Low = fmt.Sprintf("%.6f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
+	case "bty_BTCUSDT":
+		sstk.Last = fmt.Sprintf("%.2f", stk.Last)
+		sstk.High = fmt.Sprintf("%.2f", stk.High)
+		sstk.Low = fmt.Sprintf("%.2f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.4f", stk.Volume)
+	case "bty_BCCUSDT":
+		sstk.Last = fmt.Sprintf("%.2f", stk.Last)
+		sstk.High = fmt.Sprintf("%.2f", stk.High)
+		sstk.Low = fmt.Sprintf("%.2f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.4f", stk.Volume)
+	case "bty_ETHUSDT":
+		sstk.Last = fmt.Sprintf("%.2f", stk.Last)
+		sstk.High = fmt.Sprintf("%.2f", stk.High)
+		sstk.Low = fmt.Sprintf("%.2f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.3f", stk.Volume)
+	case "bty_ETCUSDT":
+		sstk.Last = fmt.Sprintf("%.2f", stk.Last)
+		sstk.High = fmt.Sprintf("%.2f", stk.High)
+		sstk.Low = fmt.Sprintf("%.2f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
+	case "bty_ZECUSDT":
+		sstk.Last = fmt.Sprintf("%.2f", stk.Last)
+		sstk.High = fmt.Sprintf("%.2f", stk.High)
+		sstk.Low = fmt.Sprintf("%.2f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.3f", stk.Volume)
+	case "bty_LTCUSDT":
+		sstk.Last = fmt.Sprintf("%.2f", stk.Last)
+		sstk.High = fmt.Sprintf("%.2f", stk.High)
+		sstk.Low = fmt.Sprintf("%.2f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
+	case "bty_YCCUSDT":
+		fallthrough
+	case "bty_BTYUSDT":
+		sstk.Last = fmt.Sprintf("%.4f", stk.Last)
+		sstk.High = fmt.Sprintf("%.4f", stk.High)
+		sstk.Low = fmt.Sprintf("%.4f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.1f", stk.Volume)
+	case "bty_BTCSUSDT":
+		sstk.Last = fmt.Sprintf("%.2f", stk.Last)
+		sstk.High = fmt.Sprintf("%.2f", stk.High)
+		sstk.Low = fmt.Sprintf("%.2f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
+	case "bty_SCUSDT":
+		sstk.Last = fmt.Sprintf("%.6f", stk.Last)
+		sstk.High = fmt.Sprintf("%.6f", stk.High)
+		sstk.Low = fmt.Sprintf("%.6f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.0f", stk.Volume)
+	case "bty_BTSUSDT":
+		sstk.Last = fmt.Sprintf("%.4f", stk.Last)
+		sstk.High = fmt.Sprintf("%.4f", stk.High)
+		sstk.Low = fmt.Sprintf("%.4f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
+	case "bty_DCRUSDT":
+		sstk.Last = fmt.Sprintf("%.2f", stk.Last)
+		sstk.High = fmt.Sprintf("%.2f", stk.High)
+		sstk.Low = fmt.Sprintf("%.2f", stk.Low)
+		sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
+	default:
+	}
+
+	return sstk
+}
+
 func dayHandler(w http.ResponseWriter, r *http.Request) {
 	//cb := r.FormValue("callback")
 	typ := r.FormValue("type")
@@ -134,20 +228,29 @@ func dayHandler(w http.ResponseWriter, r *http.Request) {
 
 	insId := typ + "_" + symbol
 	candles, err := clientDown.GetLastCandles(insId, market.D1, 1)
-	if err != nil || len(candles) == 0 {
+	if err != nil {
+		http.Error(w, "server get data failed", http.StatusInternalServerError)
+		return
+	}
+	if len(candles) == 0 {
+		_, candles, _ = clientDown.GetHistory(insId, market.D1, -1, -1)
+	}
+	if len(candles) == 0 {
 		http.Error(w, "server get data failed", http.StatusInternalServerError)
 		return
-	} else {
-		//fmt.Println("day", len(candles))
-		stk := SpecialTick{Timestamp: candles[0].Timestamp / 1000, Open: candles[0].Open, High: candles[0].High,
-			Low: candles[0].Low, Last: candles[0].Close, Volume: candles[0].RealVolums}
-		b, err := json.Marshal(&stk)
-		if err != nil {
-			http.Error(w, "json encoding error", http.StatusInternalServerError)
-			return
-		}
-		io.WriteString(w, string(b))
 	}
+	stk := SpecialTick{Timestamp: candles[0].Timestamp / 1000, Open: candles[0].Open, High: candles[0].High,
+		Low: candles[0].Low, Last: candles[0].Close, Volume: candles[0].RealVolums}
+	sstk := getStringSTK(stk, insId)
+	b, err := json.Marshal(&sstk)
+	if err != nil {
+		http.Error(w, "json encoding error", http.StatusInternalServerError)
+		return
+	}
+	w.Header().Set("Access-Control-Allow-Origin", "*")
+	w.Header().Add("Access-Control-Allow-Headers", "Content-Type")
+	w.Header().Set("content-type", "application/json")
+	io.WriteString(w, string(b))
 }
 
 func h24Handler(w http.ResponseWriter, r *http.Request) {
@@ -208,96 +311,8 @@ func h24Handler(w http.ResponseWriter, r *http.Request) {
 			}
 		}
 
-		sstk := &StringSpecialTick{
-			Timestamp: fmt.Sprintf("%d", stk.Timestamp),
-			Open:      fmt.Sprintf("%.4f", stk.Open),
-		}
-		switch insId {
-		case "bty_BCCBTC":
-			sstk.Last = fmt.Sprintf("%.4f", stk.Last)
-			sstk.High = fmt.Sprintf("%.4f", stk.High)
-			sstk.Low = fmt.Sprintf("%.4f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.4f", stk.Volume)
-		case "bty_ETHBTC":
-			sstk.Last = fmt.Sprintf("%.5f", stk.Last)
-			sstk.High = fmt.Sprintf("%.5f", stk.High)
-			sstk.Low = fmt.Sprintf("%.5f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.3f", stk.Volume)
-		case "bty_ETCBTC":
-			sstk.Last = fmt.Sprintf("%.6f", stk.Last)
-			sstk.High = fmt.Sprintf("%.6f", stk.High)
-			sstk.Low = fmt.Sprintf("%.6f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
-		case "bty_ZECBTC":
-			sstk.Last = fmt.Sprintf("%.5f", stk.Last)
-			sstk.High = fmt.Sprintf("%.5f", stk.High)
-			sstk.Low = fmt.Sprintf("%.5f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.3f", stk.Volume)
-		case "bty_LTCBTC":
-			sstk.Last = fmt.Sprintf("%.6f", stk.Last)
-			sstk.High = fmt.Sprintf("%.6f", stk.High)
-			sstk.Low = fmt.Sprintf("%.6f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
-		case "bty_BTCUSDT":
-			sstk.Last = fmt.Sprintf("%.2f", stk.Last)
-			sstk.High = fmt.Sprintf("%.2f", stk.High)
-			sstk.Low = fmt.Sprintf("%.2f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.4f", stk.Volume)
-		case "bty_BCCUSDT":
-			sstk.Last = fmt.Sprintf("%.2f", stk.Last)
-			sstk.High = fmt.Sprintf("%.2f", stk.High)
-			sstk.Low = fmt.Sprintf("%.2f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.4f", stk.Volume)
-		case "bty_ETHUSDT":
-			sstk.Last = fmt.Sprintf("%.2f", stk.Last)
-			sstk.High = fmt.Sprintf("%.2f", stk.High)
-			sstk.Low = fmt.Sprintf("%.2f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.3f", stk.Volume)
-		case "bty_ETCUSDT":
-			sstk.Last = fmt.Sprintf("%.2f", stk.Last)
-			sstk.High = fmt.Sprintf("%.2f", stk.High)
-			sstk.Low = fmt.Sprintf("%.2f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
-		case "bty_ZECUSDT":
-			sstk.Last = fmt.Sprintf("%.2f", stk.Last)
-			sstk.High = fmt.Sprintf("%.2f", stk.High)
-			sstk.Low = fmt.Sprintf("%.2f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.3f", stk.Volume)
-		case "bty_LTCUSDT":
-			sstk.Last = fmt.Sprintf("%.2f", stk.Last)
-			sstk.High = fmt.Sprintf("%.2f", stk.High)
-			sstk.Low = fmt.Sprintf("%.2f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
-		case "bty_YCCUSDT":
-			fallthrough
-		case "bty_BTYUSDT":
-			sstk.Last = fmt.Sprintf("%.4f", stk.Last)
-			sstk.High = fmt.Sprintf("%.4f", stk.High)
-			sstk.Low = fmt.Sprintf("%.4f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.1f", stk.Volume)
-		case "bty_BTCSUSDT":
-			sstk.Last = fmt.Sprintf("%.2f", stk.Last)
-			sstk.High = fmt.Sprintf("%.2f", stk.High)
-			sstk.Low = fmt.Sprintf("%.2f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
-		case "bty_SCUSDT":
-			sstk.Last = fmt.Sprintf("%.6f", stk.Last)
-			sstk.High = fmt.Sprintf("%.6f", stk.High)
-			sstk.Low = fmt.Sprintf("%.6f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.0f", stk.Volume)
-		case "bty_BTSUSDT":
-			sstk.Last = fmt.Sprintf("%.4f", stk.Last)
-			sstk.High = fmt.Sprintf("%.4f", stk.High)
-			sstk.Low = fmt.Sprintf("%.4f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
-		case "bty_DCRUSDT":
-			sstk.Last = fmt.Sprintf("%.2f", stk.Last)
-			sstk.High = fmt.Sprintf("%.2f", stk.High)
-			sstk.Low = fmt.Sprintf("%.2f", stk.Low)
-			sstk.Volume = fmt.Sprintf("%.2f", stk.Volume)
-		default:
-		}
-		b, err := json.Marshal(sstk)
+		sstk := getStringSTK(stk, insId)
+		b, err := json.Marshal(&sstk)
 		if err != nil {
 			http.Error(w, "json encoding error", http.StatusInternalServerError)
 			return

+ 2 - 2
server/cmd/webproxys/main.go

@@ -753,7 +753,7 @@ func main() {
 	}
 	http.HandleFunc("/kdata", makeGzipHandler(kdataHandler))
 	http.HandleFunc("/tdata", makeGzipHandler(tdataHandler))
-	log.Fatal(s.ListenAndServeTLS("214341259320977.pem", "214341259320977.key"))
-	//log.Fatal(s.ListenAndServe())
+	//log.Fatal(s.ListenAndServeTLS("214341259320977.pem", "214341259320977.key"))
+	log.Fatal(s.ListenAndServe())
 	//log.Fatal(s.ListenAndServeTLS("licai20170620.pem", "licai20170620.key"))
 }

+ 3 - 1
server/tick/ds_bty.go

@@ -17,6 +17,7 @@ import (
 
 	"tickserver/markinfo"
 	"tickserver/server/market"
+
 	_ "github.com/go-sql-driver/mysql"
 )
 
@@ -146,7 +147,8 @@ func (bds *BtyDS) getData(instrumentId, offset int64) {
 
 func GetEthTickbyPage(instrumentId, offset int64, cb func(*Market)) (int64, error) {
 	symbol, _ := markinfo.SymbolName(int(instrumentId))
-	url := "http://47.74.9.155:45656/tender/default/kline?symbol=" + symbol + "&offset=" + fmt.Sprintf("%d", offset) + "&limit=100"
+	url := "http://47.75.62.253:46658/tender/default/kline?symbol=" + symbol + "&offset=" + fmt.Sprintf("%d", offset) + "&limit=100"
+	//url := "http://47.74.9.155:45656/tender/default/kline?symbol=" + symbol + "&offset=" + fmt.Sprintf("%d", offset) + "&limit=100"
 	//url := "http://121.196.205.182:45656/tender/default/kline?symbol=" + symbol + "&offset=" + fmt.Sprintf("%d", offset) + "&limit=100"
 	response, err := http.Get(url)
 	if err != nil {