|
@@ -126,6 +126,100 @@ func readConf() (*Conf, error) {
|
|
return conf, nil
|
|
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) {
|
|
func dayHandler(w http.ResponseWriter, r *http.Request) {
|
|
//cb := r.FormValue("callback")
|
|
//cb := r.FormValue("callback")
|
|
typ := r.FormValue("type")
|
|
typ := r.FormValue("type")
|
|
@@ -134,20 +228,29 @@ func dayHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
insId := typ + "_" + symbol
|
|
insId := typ + "_" + symbol
|
|
candles, err := clientDown.GetLastCandles(insId, market.D1, 1)
|
|
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)
|
|
http.Error(w, "server get data failed", http.StatusInternalServerError)
|
|
return
|
|
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) {
|
|
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 {
|
|
if err != nil {
|
|
http.Error(w, "json encoding error", http.StatusInternalServerError)
|
|
http.Error(w, "json encoding error", http.StatusInternalServerError)
|
|
return
|
|
return
|