當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Logger.Infof函數代碼示例

本文整理匯總了Golang中Logger.Infof函數的典型用法代碼示例。如果您正苦於以下問題:Golang Infof函數的具體用法?Golang Infof怎麽用?Golang Infof使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Infof函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: checkThreshold

func (emaStrategy *EMAStrategy) checkThreshold(tradeType string, EMAdif float64) bool {
	if tradeType == "buy" {
		buyThreshold := toFloat(Option["buyThreshold"])

		if EMAdif > buyThreshold {
			logger.Infof("EMAdif(%0.04f) > buyThreshold(%0.04f), trigger to buy\n", EMAdif, buyThreshold)
			emaStrategy.LessBuyThreshold = false
			return true
		} else {
			if emaStrategy.LessBuyThreshold == false {
				logger.Infof("cross up, but EMAdif(%0.04f) <= buyThreshold(%0.04f)\n", EMAdif, buyThreshold)
				emaStrategy.LessBuyThreshold = true
			}
		}
	} else {
		sellThreshold := toFloat(Option["sellThreshold"])

		if sellThreshold > 0 {
			sellThreshold = -sellThreshold
		}

		if EMAdif < sellThreshold {
			logger.Infof("EMAdif(%0.04f) <  sellThreshold(%0.04f), trigger to sell\n", EMAdif, sellThreshold)
			emaStrategy.LessSellThreshold = false
			return true
		} else {
			if emaStrategy.LessSellThreshold == false {
				logger.Infof("cross down, but EMAdif(%0.04f) >= sellThreshold(%0.04f)\n", EMAdif, sellThreshold)
				emaStrategy.LessSellThreshold = true
			}
		}
	}

	return false
}
開發者ID:cnspot,項目名稱:btcrobot,代碼行數:35,代碼來源:ema.go

示例2: RobotWorker

func RobotWorker() {
	ticker := time.NewTicker(1 * time.Second) // one second
	defer ticker.Stop()

	totalHour, _ := strconv.ParseInt(Option["totalHour"], 0, 64)
	if totalHour < 1 {
		totalHour = 1
	}

	fmt.Println("trade robot start working...")

	go func() {
		for _ = range ticker.C {
			peroid, _ := strconv.Atoi(Option["tick_interval"])
			strategyName := Option["strategy"]
			ret := true
			var records []Record
			if strategyName != "OPENORDER" {
				ret, records = marketAPI().GetKLine(peroid)
			}

			if ret != false {
				strategy.Tick(tradeAPI(), records)
			}
		}
	}()

	logger.Infof("程序將持續運行%d小時後停止", time.Duration(totalHour))

	time.Sleep(time.Duration(totalHour) * time.Hour)

	logger.Infof("程序到達設定時長%d小時,停止運行。", time.Duration(totalHour))
}
開發者ID:philsong,項目名稱:btcrobot,代碼行數:33,代碼來源:monitor.go

示例3: Login

// 登錄;成功返回用戶登錄信息(user_login)
func Login(username, passwd string) (*model.UserLogin, error) {
	userLogin := model.NewUserLogin()
	err := userLogin.Where("username=" + username + " OR email=" + username).Find()
	if err != nil {
		logger.Errorf("用戶 %s 登錄錯誤:%s", username, err)
		return nil, errors.New("內部錯誤,請稍後再試!")
	}
	// 校驗用戶
	if userLogin.Uid == 0 {
		logger.Infof("用戶名 %s 不存在", username)
		return nil, ErrUsername
	}
	passcode := userLogin.GetPasscode()
	md5Passwd := util.Md5(passwd + passcode)
	logger.Debugf("passwd: %s, passcode: %s, md5passwd: %s, dbpasswd: %s", passwd, passcode, md5Passwd, userLogin.Passwd)
	if md5Passwd != userLogin.Passwd {
		logger.Infof("用戶名 %s 填寫的密碼錯誤", username)
		return nil, ErrPasswd
	}

	// 登錄,活躍度+1
	go IncUserWeight("uid="+strconv.Itoa(userLogin.Uid), 1)

	return userLogin, nil
}
開發者ID:philsong,項目名稱:studygolang,代碼行數:26,代碼來源:user.go

示例4: RobotWorker

func RobotWorker() {
	fmt.Println("env", Config["env"])
	if Config["env"] == "dev" {
		fmt.Println("test working...")
		var tradeAPI common.TradeAPI
		tradeAPI = huobi.NewHuobi()
		tradeAPI.Get_account_info()
		symbol := "btc_cny"
		tradeAPI.GetOrderBook(symbol)

		//testHuobiAPI()
		//testOkcoinLTCAPI()
		return
	}

	ticker := time.NewTicker(2 * time.Second) //2s
	defer ticker.Stop()

	var tradeAPI common.TradeAPI
	tradeAPI = huobi.NewHuobi()
	tradeAPI.Get_account_info()

	tradeAPI = okcoin.NewOkcoin()
	tradeAPI.Get_account_info()

	if Option["tradecenter"] == "huobi" {
		tradeAPI = huobi.NewHuobi()
	} else if Option["tradecenter"] == "okcoin" {
		tradeAPI = okcoin.NewOkcoin()
	} else {
		logger.Fatalln("Please config the tradecenter firstly...")
		return
	}
	peroid, _ := strconv.Atoi(Option["tick_interval"])
	totalHour, _ := strconv.ParseInt(Option["totalHour"], 0, 64)
	if totalHour < 1 {
		totalHour = 1
	}

	fmt.Println("robot working...")

	go func() {
		for _ = range ticker.C {
			tradeAPI.AnalyzeKLine(peroid)
		}
	}()

	logger.Infof("程序將持續運行%d小時後停止", time.Duration(totalHour))

	time.Sleep(time.Duration(totalHour) * time.Hour)

	logger.Infof("程序到達設定時長%d小時,停止運行。", time.Duration(totalHour))
}
開發者ID:kewinwang,項目名稱:btcrobot,代碼行數:53,代碼來源:entry.go

示例5: RobotWorker

func RobotWorker() {
	fmt.Println("env", Config["env"])
	if DebugEnv || Config["env"] == "dev" {
		fmt.Println("test working...")

		// var tradeAPI TradeAPI
		// tradeAPI = okcoin.NewOkcoin()
		// tradeAPI.GetAccount()
		// tradeAPI.GetOrderBook()

		// tradeAPI = huobi.NewHuobi()
		// accout_info, ret := tradeAPI.GetAccount()
		// fmt.Println(ret, accout_info)

		// ret, orderbook := tradeAPI.GetOrderBook()
		// fmt.Println(ret, orderbook)

		testHuobiAPI()
		//testOkcoinLTCAPI()
		return
	}

	ticker := time.NewTicker(8 * time.Second) //2s
	defer ticker.Stop()

	totalHour, _ := strconv.ParseInt(Option["totalHour"], 0, 64)
	if totalHour < 1 {
		totalHour = 1
	}

	fmt.Println("robot working...")

	go func() {
		for _ = range ticker.C {

			records := []Record{}
			strategy.Tick(tradeAPI(), records)

			// peroid, _ := strconv.Atoi(Option["tick_interval"])
			// ret, records := marketAPI().GetKLine(peroid)
			// if ret != false {
			// 	strategy.Tick(tradeAPI(), records)
			// }
		}
	}()

	logger.Infof("程序將持續運行%d小時後停止", time.Duration(totalHour))

	time.Sleep(time.Duration(totalHour) * time.Hour)

	logger.Infof("程序到達設定時長%d小時,停止運行。", time.Duration(totalHour))
}
開發者ID:jiedo,項目名稱:btcrobot,代碼行數:52,代碼來源:monitor.go

示例6: RobotWorker

func RobotWorker() {
	fmt.Println("env", Config["env"])
	if DebugEnv || Config["env"] == "dev" {
		fmt.Println("test working...")

		var tradeAPI TradeAPI
		tradeAPI = okcoin.NewOkcoin()
		tradeAPI.GetAccount()
		tradeAPI.GetOrderBook()

		tradeAPI = huobi.NewHuobi()
		tradeAPI.GetAccount()
		ret, orderbook := tradeAPI.GetOrderBook()
		fmt.Println(ret, orderbook)

		//testHuobiAPI()
		//testOkcoinLTCAPI()
		return
	}

	ticker := time.NewTicker(1 * time.Second) //2s
	defer ticker.Stop()

	totalHour, _ := strconv.ParseInt(Option["totalHour"], 0, 64)
	if totalHour < 1 {
		totalHour = 1
	}

	fmt.Println("robot working...")

	go func() {
		for _ = range ticker.C {
			peroid, _ := strconv.Atoi(Option["tick_interval"])
			strategyName := Option["strategy"]
			ret := true
			var records []Record
			if strategyName != "OPENORDER" {
				ret, records = marketAPI().GetKLine(peroid)
			}

			if ret != false {
				strategy.Tick(tradeAPI(), records)
			}
		}
	}()

	logger.Infof("程序將持續運行%d小時後停止", time.Duration(totalHour))

	time.Sleep(time.Duration(totalHour) * time.Hour)

	logger.Infof("程序到達設定時長%d小時,停止運行。", time.Duration(totalHour))
}
開發者ID:jmliu88,項目名稱:btcrobot,代碼行數:52,代碼來源:monitor.go

示例7: Tick

// the3crow strategy
func (the3crow *the3crowStrategy) Tick(records []Record) bool {
	if the3crow.PrevClosePrice == lastPrice {
		return false
	}

	the3crow.PrevClosePrice = lastPrice

	logger.Infof("lastPrice %0.02f\n", lastPrice)
	logger.Infof("3 open %0.02f close %0.02f\n", records[length-2].Open, records[length-2].Close)
	logger.Infof("2 open %0.02f close %0.02f\n", records[length-3].Open, records[length-3].Close)
	logger.Infof("1 open %0.02f close %0.02f\n", records[length-4].Open, records[length-4].Close)

	if records[length-2].Close > records[length-2].Open {
		logger.Infof("3陽")
	} else {
		logger.Infof("3陰")
	}

	if records[length-3].Close > records[length-3].Open {
		logger.Infof("2陽")
	} else {
		logger.Infof("2陰")
	}
	if records[length-4].Close > records[length-4].Open {
		logger.Infof("1陽")
	} else {
		logger.Infof("1陰")
	}
	logger.Infoln("---------")

	// the3crow cross
	if records[length-2].Close > records[length-2].Open &&
		records[length-3].Close > records[length-3].Open &&
		records[length-4].Close > records[length-4].Open {
		Buy()
	} else if records[length-2].Close < records[length-2].Open &&
		records[length-3].Close < records[length-3].Open &&
		records[length-4].Close < records[length-4].Open {
		Sell()
	}

	// do sell when price is below stoploss point
	processStoploss(lastPrice)

	processTimeout()

	return true
}
開發者ID:cnspot,項目名稱:btcrobot,代碼行數:49,代碼來源:3crow.go

示例8: GetAccount

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
	}
}
開發者ID:9cat,項目名稱:btcrobot,代碼行數:31,代碼來源:api.go

示例9: GetAccount

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
	}
}
開發者ID:ifzz,項目名稱:btcrobot,代碼行數:29,代碼來源:api.go

示例10: Get_account_info

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
	}
}
開發者ID:kewinwang,項目名稱:btcrobot,代碼行數:30,代碼來源:api.go

示例11: Tick

//circular strategy
func (circular *circularStrategy) Tick(records []Record) bool {
	if circular.PrevClosePrice == lastPrice {
		return false
	}

	basePrice, err := strconv.ParseFloat(Option["basePrice"], 64)
	if err != nil {
		logger.Debugln("config item basePrice is not float")
		return false
	}

	fluctuation, err := strconv.ParseFloat(Option["fluctuation"], 64)
	if err != nil {
		logger.Debugln("config item fluctuation is not float")
		return false
	}

	circular.PrevClosePrice = lastPrice

	logger.Infof("lastPrice %0.02f\n", lastPrice)
	if lastPrice >= basePrice+fluctuation {
		Sell()
	} else if lastPrice <= basePrice-fluctuation {
		Buy()
	}

	//do sell when price is below stoploss point
	processStoploss(lastPrice)

	processTimeout()

	return true
}
開發者ID:2yeslater,項目名稱:btcrobot,代碼行數:34,代碼來源:circular.go

示例12: AnalyzePeroidLine

func (w *Huobi) AnalyzePeroidLine(filename string, content string) bool {
	//logger.Infoln(content)
	//logger.Infoln(filename)
	PeroidRecords := ParsePeroidCSV(filename)

	var xData []string
	var yData []float64
	for _, v := range PeroidRecords {
		xData = append(xData, v.Date+" "+v.Time)
		yData = append(yData, v.Close)
		//yData = append(yData, (v.Close+v.Open+v.High+v.Low)/4.0)
		//yData = append(yData, v.Low)
	}
	w.xData = xData
	w.yData = yData
	//rsi(yData)
	if Config["env"] == "test" {
		w.do2Percent(xData, yData)
		return true

		k, d, j := doKDJ(PeroidRecords)
		length := len(k)
		// Loop through the entire array.
		for i := 0; i < length; i++ {
			logger.Infof("[%s-%s]%d/%d/%d\n", PeroidRecords[i].Date, PeroidRecords[i].Time, int(k[i]), int(d[i]), int(j[i]))
		}
	} else {
		w.doEMA(xData, yData)
		return true
	}

	return true
}
開發者ID:kuainiao,項目名稱:btcrobot,代碼行數:33,代碼來源:huobikline.go

示例13: FindCurrentUser

// 獲取當前登錄用戶信息(常用信息)
func FindCurrentUser(username string) (user map[string]interface{}, err error) {
	userLogin := model.NewUserLogin()
	err = userLogin.Where("username=" + username).Find()
	if err != nil {
		logger.Errorf("獲取用戶 %s 信息失敗:%s", username, err)
		return
	}
	if userLogin.Uid == 0 {
		logger.Infof("用戶 %s 不存在!", username)
		return
	}
	user = map[string]interface{}{
		"uid":      userLogin.Uid,
		"username": userLogin.Username,
		"email":    userLogin.Email,
	}

	// 獲取未讀消息數
	user["msgnum"] = FindNotReadMsgNum(userLogin.Uid)

	// 獲取角色信息
	userRoleList, err := model.NewUserRole().Where("uid=" + strconv.Itoa(userLogin.Uid)).FindAll()
	if err != nil {
		logger.Errorf("獲取用戶 %s 角色 信息失敗:%s", username, err)
		return
	}
	for _, userRole := range userRoleList {
		if userRole.Roleid <= model.AdminMinRoleId {
			// 是管理員
			user["isadmin"] = true
		}
	}
	return
}
開發者ID:philsong,項目名稱:studygolang,代碼行數:35,代碼來源:user.go

示例14: Tick

// MACD strategy
func (macdStrategy *MACDStrategy) Tick(records []Record) bool {
	// read config
	shortEMA, _ := strconv.Atoi(Option["shortEMA"])
	longEMA, _ := strconv.Atoi(Option["longEMA"])

	signalPeriod, _ := strconv.Atoi(Option["signalPeriod"])
	/*
		MACDMinThreshold, err := strconv.ParseFloat(Option["MACDMinThreshold"], 64)
		if err != nil {
			logger.Debugln("config item MACDMinThreshold is not float")
			return false
		}
	*/

	MACDbuyThreshold, err := strconv.ParseFloat(Option["MACDbuyThreshold"], 64)
	if err != nil {
		logger.Errorln("config item MACDbuyThreshold is not float")
		return false
	}

	MACDsellThreshold, err := strconv.ParseFloat(Option["MACDsellThreshold"], 64)
	if err != nil {
		logger.Errorln("config item MACDsellThreshold is not float")
		return false
	}

	var Price []float64
	for _, v := range records {
		Price = append(Price, v.Close)
	}

	// compute the indictor
	emaShort := EMA(Price, shortEMA)
	emaLong := EMA(Price, longEMA)
	MACDdif := getMACDdif(emaShort, emaLong)
	MACDSignal := getMACDSignal(MACDdif, signalPeriod)
	MACDHistogram := getMACDHistogram(MACDdif, MACDSignal)

	if MACDdif[length-1] != macdStrategy.PrevMACDdif {
		macdStrategy.PrevMACDdif = MACDdif[length-1]
		logger.Infof("MACD:d%5.03f\ts%5.03f\tph%5.03f\th%5.03f\tPrice:%5.02f\n", MACDdif[length-1], MACDSignal[length-1], MACDHistogram[length-2], MACDHistogram[length-1], Price[length-1])
	}

	// macd cross
	if (MACDHistogram[length-2] < -0.000001 && MACDHistogram[length-1] > MACDbuyThreshold) ||
		(PrevTrade == "sell" && MACDHistogram[length-2] > 0.000001 && MACDHistogram[length-1] > MACDbuyThreshold) {
		Buy()
	} else if (MACDHistogram[length-2] > 0.000001 && MACDHistogram[length-1] < MACDsellThreshold) ||
		(PrevTrade == "buy" && MACDHistogram[length-2] < -0.000001 && MACDHistogram[length-1] < MACDsellThreshold) {
		Sell()
	}

	// do sell when price is below stoploss point
	processStoploss(lastPrice)
	processTimeout()

	return true
}
開發者ID:cnspot,項目名稱:btcrobot,代碼行數:59,代碼來源:macd.go

示例15: checkThreshold

func (emaStrategy *EMAStrategy) checkThreshold(direction string, EMAdif float64) bool {
	if direction == "buy" {
		buyThreshold, err := strconv.ParseFloat(Option["buyThreshold"], 64)
		if err != nil {
			logger.Errorln("config item buyThreshold is not float")
			return false
		}

		if EMAdif > buyThreshold {
			logger.Infof("EMAdif(%0.04f) > buyThreshold(%0.04f), trigger to buy\n", EMAdif, buyThreshold)
			emaStrategy.LessBuyThreshold = false
			return true
		} else {
			if emaStrategy.LessBuyThreshold == false {
				logger.Infof("cross up, but EMAdif(%0.04f) <= buyThreshold(%0.04f)\n", EMAdif, buyThreshold)
				emaStrategy.LessBuyThreshold = true
			}
		}
	} else {
		sellThreshold, err := strconv.ParseFloat(Option["sellThreshold"], 64)
		if err != nil {
			logger.Errorln("config item sellThreshold is not float")
			return false
		}

		if sellThreshold > 0 {
			sellThreshold = -sellThreshold
		}

		if EMAdif < sellThreshold {
			logger.Infof("EMAdif(%0.04f) <  sellThreshold(%0.04f), trigger to sell\n", EMAdif, sellThreshold)
			emaStrategy.LessSellThreshold = false
			return true
		} else {
			if emaStrategy.LessSellThreshold == false {
				logger.Infof("cross down, but EMAdif(%0.04f) >= sellThreshold(%0.04f)\n", EMAdif, sellThreshold)
				emaStrategy.LessSellThreshold = true
			}
		}
	}

	return false
}
開發者ID:9cat,項目名稱:btcrobot,代碼行數:43,代碼來源:ema.go


注:本文中的Logger.Infof函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。