func (w Okcoin) GetAccount() (account Account, ret bool) { tradeAPI := NewOkcoinTrade(SecretOption["ok_partner"], SecretOption["ok_secret_key"]) userInfo, ret := tradeAPI.GetAccount() logger.Infoln("account:", userInfo) if !ret { logger.Traceln("okcoin GetAccount failed") return } else { logger.Traceln(userInfo) account.Available_cny = userInfo.Info.Funds.Free.CNY account.Available_btc = userInfo.Info.Funds.Free.BTC account.Available_ltc = userInfo.Info.Funds.Free.LTC account.Frozen_cny = userInfo.Info.Funds.Freezed.CNY account.Frozen_btc = userInfo.Info.Funds.Freezed.BTC account.Frozen_ltc = userInfo.Info.Funds.Freezed.LTC logger.Infof("okcoin资产: \n 可用cny:%-10s \tbtc:%-10s \tltc:%-10s \n 冻结cny:%-10s \tbtc:%-10s \tltc:%-10s\n", account.Available_cny, account.Available_btc, account.Available_ltc, account.Frozen_cny, account.Frozen_btc, account.Frozen_ltc) //logger.Infoln(Account) return } }
func (w *BitvcTrade) Cancel_order(id string) bool { pParams := make(map[string]string) body, err := w.httpRequest(pParams) if err != nil { return false } _, ret := w.check_json_result(body) if ret == false { return false } doc := json.NewDecoder(strings.NewReader(body)) type Msg struct { Result string } var m Msg if err := doc.Decode(&m); err == io.EOF { logger.Traceln(err) } else if err != nil { logger.Fatal(err) } logger.Traceln(m) if m.Result == "success" { return true } else { return false } }
func (w *HuobiTrade) Get_orders() (m []Order, ret bool) { pParams := make(map[string]string) pParams["method"] = "get_orders" pParams["access_key"] = w.access_key now := time.Now().Unix() pParams["created"] = strconv.FormatInt(now, 10) pParams["sign"] = w.createSign(pParams) ret = true body, err := w.httpRequest(pParams) if err != nil { ret = false return } _, ret = w.check_json_result(body) if ret == false { return } doc := json.NewDecoder(strings.NewReader(body)) if err := doc.Decode(&m); err == io.EOF { logger.Traceln(err) } else if err != nil { logger.Fatal(err) } logger.Traceln(m) return }
func (w *OkcoinTrade) Get_account_info() (userInfo UserInfo, ret bool) { api_url := "https://www.okcoin.com/api/userinfo.do" pParams := make(map[string]string) pParams["partner"] = w.partner ret = true body, err := w.httpRequest(api_url, pParams) if err != nil { ret = false return } _, ret = w.check_json_result(body) if ret == false { return } logger.Traceln(body) doc := json.NewDecoder(strings.NewReader(body)) if err := doc.Decode(&userInfo); err == io.EOF { ret = false logger.Traceln(err) } else if err != nil { ret = false logger.Fatal(err) } logger.Traceln(userInfo) return }
func parse_topsell(topsells map[string]interface{}, topsells_data *[5]Top_buy_sell) { index := 4 for k, v := range topsells { switch vt := v.(type) { case map[string]interface{}: logger.Traceln(k, " is a map:") logger.Tracef("topsells[%s]\n", k) for ik, iv := range vt { logger.Traceln(ik, iv) switch ik { case "price": topsells_data[index].Price = InterfaceToFloat64(iv) case "amount": topsells_data[index].amount = InterfaceToFloat64(iv) case "level": topsells_data[index].level = InterfaceToFloat64(iv) case "accu": topsells_data[index].accu = InterfaceToFloat64(iv) } } index-- default: logger.Errorln(k, v) logger.Fatalln("don't know the type, crash!") } } }
func (w *OkcoinTrade) Get_order(symbol, order_id string) (m OrderTable, ret bool) { api_url := "https://www.okcoin.com/api/getorder.do" pParams := make(map[string]string) pParams["partner"] = w.partner pParams["symbol"] = symbol pParams["order_id"] = order_id ret = true body, err := w.httpRequest(api_url, pParams) if err != nil { ret = false return } _, ret = w.check_json_result(body) if ret == false { return } doc := json.NewDecoder(strings.NewReader(body)) if err := doc.Decode(&m); err == io.EOF { logger.Traceln(err) } else if err != nil { logger.Fatal(err) } logger.Traceln(m) return }
func (w *Huobi) getOrderBook(symbol string) (ret bool, hbOrderBook OrderBook) { // init to false ret = false var huobisymbol string if symbol == "btc_cny" { huobisymbol = "huobibtccny" } else { huobisymbol = "huobiltccny" logger.Fatal("huobi does not support LTC by now, wait for huobi provide it.", huobisymbol) return } rnd := util.RandomString(20) now := time.Now().UnixNano() / 1000000 req, err := http.NewRequest("GET", fmt.Sprintf(Config["hb_trade_detail"], rnd, now, now), nil) if err != nil { logger.Fatal(err) return } req.Header.Set("Referer", Config["base_url"]) req.Header.Add("Connection", "keep-alive") req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36") req.Header.Add("Accept-Encoding", "identity") resp, err := http.DefaultClient.Do(req) if err != nil { logger.Traceln(err) logger.Traceln(req) logger.Traceln(resp) return } defer resp.Body.Close() if resp.StatusCode != 200 { logger.Errorf("HTTP returned status %v", resp) return } var body string contentEncoding := resp.Header.Get("Content-Encoding") logger.Tracef("HTTP returned Content-Encoding %s", contentEncoding) switch contentEncoding { case "gzip": body = util.DumpGZIP(resp.Body) default: bodyByte, err := ioutil.ReadAll(resp.Body) if err != nil { logger.Errorln("read the http stream failed") return } else { body = string(bodyByte) ioutil.WriteFile("cache/OrderBook.json", bodyByte, 0644) } } return w.analyzeOrderBook(body) }
func (w *BitvcTrade) Get_orders() (ret bool, m []HBOrderItem) { pParams := make(map[string]string) ret = true body, err := w.httpRequest(pParams) if err != nil { ret = false return } _, ret = w.check_json_result(body) if ret == false { return } doc := json.NewDecoder(strings.NewReader(body)) if err := doc.Decode(&m); err == io.EOF { logger.Traceln(err) } else if err != nil { logger.Fatal(err) } logger.Traceln(m) return }
func (w Okcoin) Get_account_info() (userMoney common.UserMoney, ret bool) { tradeAPI := NewOkcoinTrade(SecretOption["ok_partner"], SecretOption["ok_secret_key"]) userInfo, ret := tradeAPI.Get_account_info() if !ret { logger.Traceln("okcoin Get_account_info failed") return } else { logger.Traceln(userInfo) userMoney.Available_cny = userInfo.Info.Funds.Free.CNY userMoney.Available_btc = userInfo.Info.Funds.Free.BTC userMoney.Available_ltc = userInfo.Info.Funds.Free.LTC userMoney.Frozen_cny = userInfo.Info.Funds.Freezed.CNY userMoney.Frozen_btc = userInfo.Info.Funds.Freezed.BTC userMoney.Frozen_ltc = userInfo.Info.Funds.Freezed.LTC logger.Infof("okcoin资产: \n 可用cny:%-10s \tbtc:%-10s \tltc:%-10s \n 冻结cny:%-10s \tbtc:%-10s \tltc:%-10s\n", userMoney.Available_cny, userMoney.Available_btc, userMoney.Available_ltc, userMoney.Frozen_cny, userMoney.Frozen_btc, userMoney.Frozen_ltc) //logger.Infoln(userMoney) return } }
func (w Okcoin) GetAccount() (account Account, ret bool) { tradeAPI := w.tradeAPI userInfo, ret := tradeAPI.GetAccount() if !ret { logger.Traceln("okcoin GetAccount failed") return } else { logger.Traceln(userInfo) account.Available_cny = userInfo.Info.Funds.Free.CNY account.Available_btc = userInfo.Info.Funds.Free.BTC account.Available_ltc = userInfo.Info.Funds.Free.LTC account.Frozen_cny = userInfo.Info.Funds.Freezed.CNY account.Frozen_btc = userInfo.Info.Funds.Freezed.BTC account.Frozen_ltc = userInfo.Info.Funds.Freezed.LTC logger.Infof("okcoin资产: \n 可用cny:%-10s \tbtc:%-10s \tltc:%-10s \n 冻结cny:%-10s \tbtc:%-10s \tltc:%-10s\n", account.Available_cny, account.Available_btc, account.Available_ltc, account.Frozen_cny, account.Frozen_btc, account.Frozen_ltc) return } }
func (w *OkcoinTrade) GetAccount() (userInfo UserInfo, ret bool) { pParams := make(map[string]string) pParams["partner"] = w.partner ret = true body, err := w.httpRequest(Config["ok_api_userinfo"], pParams) if err != nil { ret = false return } _, ret = w.check_json_result(body) if ret == false { return } logger.Traceln(body) doc := json.NewDecoder(strings.NewReader(body)) if err := doc.Decode(&userInfo); err == io.EOF { ret = false logger.Traceln(err) } else if err != nil { ret = false logger.Fatal(err) } logger.Traceln(userInfo) return }
func (w *Huobi) TradeKLinePeroid(peroid int) (ret bool) { req, err := http.NewRequest("GET", fmt.Sprintf(Config["trade_kline_url"], peroid, rand.Float64()), nil) if err != nil { logger.Fatal(err) return false } req.Header.Set("Referer", Config["trade_flash_url"]) req.Header.Add("Connection", "keep-alive") req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36") logger.Traceln(req) if w.client == nil { w.client = &http.Client{nil, nil, nil} } resp, err := w.client.Do(req) if err != nil { logger.Errorln(err) return false } defer resp.Body.Close() if resp.StatusCode == 200 { var body string contentEncoding := resp.Header.Get("Content-Encoding") logger.Tracef("HTTP returned Content-Encoding %s", contentEncoding) switch contentEncoding { case "gzip": body = DumpGZIP(resp.Body) default: bodyByte, err := ioutil.ReadAll(resp.Body) if err != nil { logger.Errorln("read the http stream failed") return false } else { body = string(bodyByte) ioutil.WriteFile(fmt.Sprintf("cache/TradeKLine_%03d.data", peroid), bodyByte, os.ModeAppend) } } logger.Traceln(resp.Header.Get("Content-Type")) ret := strings.Contains(body, "您需要登录才能继续") if ret { logger.Traceln("您需要登录才能继续") return false } else { return w.AnalyzePeroidLine(fmt.Sprintf("cache/TradeKLine_%03d.data", peroid), body) } } else { logger.Tracef("HTTP returned status %v", resp) } return false }
func (w *Huobi) AnalyzeKLinePeroid(symbol string, peroid int) (ret bool, records []Record) { ret = false var huobisymbol string if symbol == "btc_cny" { huobisymbol = "huobibtccny" } else { huobisymbol = "huobiltccny" logger.Fatal("huobi does not support LTC by now, wait for huobi provide it.", huobisymbol) return } req, err := http.NewRequest("GET", fmt.Sprintf(Config["hb_kline_url"], peroid), nil) if err != nil { logger.Fatal(err) return } req.Header.Set("Referer", Config["hb_base_url"]) req.Header.Add("Connection", "keep-alive") req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36") logger.Traceln(req) c := util.NewTimeoutClient() logger.Tracef("HTTP req begin AnalyzeKLinePeroid") resp, err := c.Do(req) logger.Tracef("HTTP req end AnalyzeKLinePeroid") if err != nil { logger.Traceln(err) return } defer resp.Body.Close() if resp.StatusCode != 200 { logger.Tracef("HTTP returned status %v", resp) return } var body string contentEncoding := resp.Header.Get("Content-Encoding") logger.Tracef("HTTP returned Content-Encoding %s", contentEncoding) logger.Traceln(resp.Header.Get("Content-Type")) switch contentEncoding { case "gzip": body = util.DumpGZIP(resp.Body) default: bodyByte, err := ioutil.ReadAll(resp.Body) if err != nil { logger.Errorln("read the http stream failed") return } else { body = string(bodyByte) } } ioutil.WriteFile(fmt.Sprintf("cache/hbKLine_%03d.data", peroid), []byte(body), 0644) return analyzePeroidLine(fmt.Sprintf("cache/hbKLine_%03d.data", peroid)) }
func (w *HuobiTrade) httpRequest(pParams map[string]string) (string, error) { v := url.Values{} for key, val := range pParams { v.Add(key, val) } req, err := http.NewRequest("POST", Config["api_url"], strings.NewReader(v.Encode())) if err != nil { logger.Fatal(err) return "", err } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") req.Header.Set("Referer", "https://www.huobi.com/") req.Header.Add("Connection", "keep-alive") req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36") logger.Traceln(req) c := util.NewTimeoutClient() logger.Tracef("HTTP req begin HuobiTrade") resp, err := c.Do(req) logger.Tracef("HTTP req end HuobiTrade") if err != nil { logger.Fatal(err) return "", err } defer resp.Body.Close() logger.Tracef("api_url resp StatusCode=%v", resp.StatusCode) logger.Tracef("api_url resp=%v", resp) if resp.StatusCode == 200 { var body string contentEncoding := resp.Header.Get("Content-Encoding") logger.Tracef("HTTP returned Content-Encoding %s", contentEncoding) logger.Traceln(resp.Header.Get("Content-Type")) switch contentEncoding { case "gzip": body = DumpGZIP(resp.Body) default: bodyByte, _ := ioutil.ReadAll(resp.Body) body = string(bodyByte) ioutil.WriteFile("cache/api_url.json", bodyByte, 0644) } logger.Traceln(body) return body, nil } else { logger.Tracef("resp %v", resp) } return "", nil }
func (w *Okcoin) getOrderBook(symbol string) (ret bool, orderBook OrderBook) { //init to false ret = false req, err := http.NewRequest("GET", fmt.Sprintf(Config["ok_depth_url"], symbol), nil) if err != nil { logger.Fatal(err) return } req.Header.Set("Referer", Config["ok_base_url"]) req.Header.Add("Connection", "keep-alive") req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36") logger.Traceln(req) c := util.NewTimeoutClient() logger.Tracef("HTTP req begin getOrderBook") resp, err := c.Do(req) logger.Tracef("HTTP req end getOrderBook") if err != nil { logger.Traceln(err) return } defer resp.Body.Close() if resp.StatusCode != 200 { logger.Errorf("HTTP returned status %v", resp) return } var body string contentEncoding := resp.Header.Get("Content-Encoding") logger.Tracef("HTTP returned Content-Encoding %s", contentEncoding) switch contentEncoding { case "gzip": body = util.DumpGZIP(resp.Body) default: bodyByte, err := ioutil.ReadAll(resp.Body) if err != nil { logger.Errorln("read the http stream failed") return } else { body = string(bodyByte) ioutil.WriteFile("cache/okdepth.json", bodyByte, 0644) } } return w.analyzeOrderBook(body) }
// 社区帖子列表页 // uri: /topics{view:(|/popular|/no_reply|/last)} func TopicsHandler(rw http.ResponseWriter, req *http.Request, ismobile bool) { logger.Traceln("User-Agent") logger.Traceln(req.Header["User-Agent"][0]) nodes := genNodes() // 设置内容模板 page, _ := strconv.Atoi(req.FormValue("p")) if page == 0 { page = 1 } vars := mux.Vars(req) order := "" where := "" switch vars["view"] { case "/popular": where = "like>0" case "/last": order = "ctime DESC" } var PAGE_NUM int if ismobile { PAGE_NUM = 30 } else { PAGE_NUM = 10 } topics, total := service.FindTopics(page, PAGE_NUM, where, order) logger.Traceln(total) logger.Traceln(len(topics)) logger.Traceln(PAGE_NUM) pageHtml := service.GetPageHtml(page, total, PAGE_NUM) if ismobile { req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/list_mobile.html") } else { req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/list.html") } // 设置模板数据 switch vars["view"] { case "/popular": filter.SetData(req, map[string]interface{}{"popular": 1, "topics": topics, "page": template.HTML(pageHtml), "nodes": nodes}) case "/last": filter.SetData(req, map[string]interface{}{"last": 1, "topics": topics, "page": template.HTML(pageHtml), "nodes": nodes}) default: filter.SetData(req, map[string]interface{}{"active": 1, "topics": topics, "page": template.HTML(pageHtml), "nodes": nodes}) } }
func parse_trade(trades []interface{}, trades_data *[15]Trade) { for k, v := range trades { switch vt := v.(type) { case map[string]interface{}: logger.Traceln(k, " is a map:") logger.Tracef("trades[%d]\n", k) for ik, iv := range vt { switch ik { case "time": trades_data[k].time = iv.(string) case "price": trades_data[k].price = InterfaceToFloat64(iv) case "amount": trades_data[k].amount = InterfaceToFloat64(iv) case "type": trades_data[k].type_ = iv.(string) } } default: logger.Errorln(k, v) logger.Fatalln("don't know the type, crash!") } } }
func (w *BitvcTrade) doTrade(method, price, amount string) int { pParams := make(map[string]string) body, err := w.httpRequest(pParams) if err != nil { return 0 } _, ret := w.check_json_result(body) if ret == false { return 0 } doc := json.NewDecoder(strings.NewReader(body)) type Msg struct { Result string Id int } var m Msg if err := doc.Decode(&m); err == io.EOF { logger.Traceln(err) } else if err != nil { logger.Fatal(err) } logger.Infoln(m) if m.Result == "success" { return m.Id } else { return 0 } }
/* {"code":0,"msg":"","ext":{"cny_balance":{"CNY":{"total":340062540230000,"available":340062540230000,"frozen":0},"BTC":{"total":177247000000,"available":177247000000,"frozen":0},"LTC":{"total":0,"available":0,"frozen":0},"now_btc_price":"38380100000000","now_ltc_price":"471500000000","LOAN_CNY":0,"LOAN_BTC":177247000000,"LOAN_LTC":0,"net_asset":340062540230000,"total":1020338298700000},"coin_saving_balance":{"btc_total":"0","ltc_total":"0"}}} */ func (w *BitvcTrade) GetAccount() (account_info Account_info, ret bool) { w.Login() pParams := make(map[string]string) ret = true body, err := w.httpRequest("https://www.bitvc.com/ajax/user_balance", pParams) if err != nil { ret = false return } fmt.Println(body) _, ret = w.check_json_result(body) if ret == false { return } doc := json.NewDecoder(strings.NewReader(body)) if err := doc.Decode(&account_info); err == io.EOF { logger.Fatal(err) } else if err != nil { logger.Fatal(err) } logger.Traceln(account_info) return }
func TopicsBriefHandler(rw http.ResponseWriter, req *http.Request) { ismobile := isMobile(req) logger.Traceln("ismobile is", ismobile) TopicsHandler(rw, req, ismobile) //ismobile = !ismobile //nodes["ismobile"] = ismobile }
func (w *BitvcTrade) GetAccount() (account_info Account_info, ret bool) { pParams := make(map[string]string) ret = true body, err := w.httpRequest(pParams) if err != nil { ret = false return } _, ret = w.check_json_result(body) if ret == false { return } doc := json.NewDecoder(strings.NewReader(body)) if err := doc.Decode(&account_info); err == io.EOF { logger.Fatal(err) } else if err != nil { logger.Fatal(err) } logger.Traceln(account_info) return }
// Find 查找单条数据 // colFieldMap 数据库表中列对应go中对象的字段 func (this *Dao) Find(colFieldMap map[string]interface{}, selectCol ...string) error { colNum := len(selectCol) if colNum == 0 || (colNum == 1 && selectCol[0] == "*") { selectCol = util.MapKeys(colFieldMap) } sort.Sort(sort.StringSlice(selectCol)) this.selectCols = "`" + strings.Join(selectCol, "`,`") + "`" strSql := util.SelectSql(this) logger.Traceln("Find sql:", strSql) err := this.Open() if err != nil { return err } defer this.Close() row := this.QueryRow(strSql, this.whereVal...) scanInterface := make([]interface{}, 0, colNum) for _, column := range selectCol { scanInterface = append(scanInterface, colFieldMap[column]) } err = row.Scan(scanInterface...) if err == sql.ErrNoRows { logger.Infoln("Find", strSql, ":no result ret") return nil } return err }
// Increment 增加/减少 某个字段的值 func (this *Dao) Increment(field string, num int) error { if num == 0 { return errors.New("dao Increment(`num`不能为0)") } where := this.where if where != "" { where = "WHERE " + where } setClause := fmt.Sprintf("`%s`=`%s`", field, field) if num > 0 { setClause += fmt.Sprintf("+%d", num) } else { setClause += fmt.Sprintf("-%d", num) } strSql := fmt.Sprintf("UPDATE `%s` SET %s %s", this.tablename, setClause, where) logger.Traceln("Increment sql:", strSql) err := this.Open() if err != nil { return err } defer this.Close() result, err := this.Exec(strSql, this.whereVal...) if err != nil { return err } affected, err := result.RowsAffected() if err != nil { return err } if affected == 0 { return errors.New("dao Increment 没有更新任何数据!") } logger.Debugf("成功 increment `%s`表 %d 条记录", this.tablename, affected) return nil }
func (w Peatio) GetAccount() (account Account, ret bool) { tradeAPI, _ := newPeatio(SecretOption["peatio_access_key"], SecretOption["peatio_secret_key"], "btc", 0) userInfo, err := tradeAPI.GetAccount() if err != nil { logger.Traceln("Peatio GetAccount failed") ret = false return } else { ret = true account.Available_cny = float2str(userInfo.Balance) account.Available_btc = float2str(userInfo.Stocks) account.Available_ltc = "N/A" account.Frozen_cny = float2str(userInfo.FrozenBalance) account.Frozen_btc = float2str(userInfo.FrozenStocks) account.Frozen_ltc = "N/A" logger.Infof("Peatio资产: \n 可用cny:%-10s \tbtc:%-10s \tltc:%-10s \n 冻结cny:%-10s \tbtc:%-10s \tltc:%-10s\n", account.Available_cny, account.Available_btc, account.Available_ltc, account.Frozen_cny, account.Frozen_btc, account.Frozen_ltc) return } }
func (w Huobi) Get_account_info() (userMoney common.UserMoney, ret bool) { tradeAPI := NewHuobiTrade(SecretOption["huobi_access_key"], SecretOption["huobi_secret_key"]) userInfo, ret := tradeAPI.Get_account_info() if !ret { logger.Traceln("Huobi Get_account_info failed") return } else { userMoney.Available_cny = userInfo.Available_cny_display userMoney.Available_btc = userInfo.Available_btc_display userMoney.Available_ltc = "N/A" userMoney.Frozen_cny = userInfo.Frozen_cny_display userMoney.Frozen_btc = userInfo.Frozen_btc_display userMoney.Frozen_ltc = "N/A" logger.Infof("Huobi资产: \n 可用cny:%-10s \tbtc:%-10s \tltc:%-10s \n 冻结cny:%-10s \tbtc:%-10s \tltc:%-10s\n", userMoney.Available_cny, userMoney.Available_btc, userMoney.Available_ltc, userMoney.Frozen_cny, userMoney.Frozen_btc, userMoney.Frozen_ltc) return } }
func (w *OkcoinTrade) check_json_result(body string) (errorMsg ErrorMsg, ret bool) { if strings.Contains(body, "result") != true { ret = false return } doc := json.NewDecoder(strings.NewReader(body)) if err := doc.Decode(&errorMsg); err == io.EOF { logger.Traceln(err) } else if err != nil { logger.Fatal(err) logger.Fatalln(body) } if errorMsg.Result != true { logger.Errorln(errorMsg) SetLastError(errorMsg.ErrorCode) ret = false return } ret = true return }
func (w Bitvc) GetAccount() (account Account, ret bool) { tradeAPI := NewBitvcTrade(SecretOption["huobi_access_key"], SecretOption["huobi_secret_key"]) userInfo, ret := tradeAPI.GetAccount() if !ret { logger.Traceln("Bitvc GetAccount failed") return } else { account.Available_cny = userInfo.Available_cny_display account.Available_btc = userInfo.Available_btc_display account.Available_ltc = "N/A" account.Frozen_cny = userInfo.Frozen_cny_display account.Frozen_btc = userInfo.Frozen_btc_display account.Frozen_ltc = "N/A" logger.Infof("Bitvc资产: \n 可用cny:%-10s \tbtc:%-10s \tltc:%-10s \n 冻结cny:%-10s \tbtc:%-10s \tltc:%-10s\n", account.Available_cny, account.Available_btc, account.Available_ltc, account.Frozen_cny, account.Frozen_btc, account.Frozen_ltc) return } }
func (w *OkcoinTrade) Get_order(symbol, order_id string) (ret bool, m OKOrderTable) { pParams := make(map[string]string) pParams["partner"] = w.partner pParams["symbol"] = symbol pParams["order_id"] = order_id ret = true body, err := w.httpRequest(Config["ok_api_getorder"], pParams) if err != nil { ret = false return } _, ret = w.check_json_result(body) if ret == false { return } doc := json.NewDecoder(strings.NewReader(body)) if err := doc.Decode(&m); err == io.EOF { logger.Traceln(err) } else if err != nil { logger.Errorln(err) logger.Errorln(body) logger.Errorln(m) } return }
// 社区帖子详细页 // uri: /topics/{tid:[0-9]+} func TopicDetailHandler(rw http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) uid := 0 user, ok := filter.CurrentUser(req) if ok { uid = user["uid"].(int) } // TODO:刷屏暂时不处理 topic, replies, err := service.FindTopicByTid(vars["tid"]) if err != nil || topic == nil || topic["tid"] == nil { logger.Traceln("------") logger.Traceln(vars["tid"]) i, _ := strconv.Atoi(vars["tid"]) total := service.TopicsTotal() if i >= total { i = 0 } if i <= 0 { i = total - 1 } for ; i <= total; i++ { logger.Traceln(i) topic, replies, err = service.FindTopicByTid(strconv.Itoa(i)) if err == nil && topic != nil && topic["tid"] != nil { break } } } logger.Traceln("------end..........") if err != nil || topic == nil || topic["tid"] == nil { NotFoundHandler(rw, req) return } // 增加浏览量 service.IncrTopicView(vars["tid"], uid) topic["prev_tid"] = topic["tid"].(int) - 1 topic["next_tid"] = topic["tid"].(int) + 1 // 设置内容模板 req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/detail.html") // 设置模板数据 filter.SetData(req, map[string]interface{}{"activeTopics": "active", "topic": topic, "replies": replies}) }
func stringt2float64(in string) float64 { out, err := strconv.ParseFloat(in, 64) if err != nil { logger.Fatalln("don't know the type, crash!") logger.Traceln("config item amount is not number, get from buy price") } return out }