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


Golang email.TriggerTrender函數代碼示例

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


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

示例1: Sell

func Sell() string {
	if PrevTrade == "sell" {
		return "0"
	}

	// compute the price
	price, _, warning := getSellPrice()

	// compute the amount
	Available_coin := GetAvailable_coin()
	if Available_coin < 0.01 {
		warning = "沒有足夠的幣"
		logger.Infoln(warning)
		PrevTrade = "sell"
		PrevBuyPirce = 0
		return "0"
	}

	amount := Option["tradeAmount"]
	nAmount, err := strconv.ParseFloat(amount, 64)
	if err != nil {
		logger.Infoln("amount is not float")
		return "0"
	}

	if nAmount > Available_coin {
		nAmount = Available_coin
		amount = fmt.Sprintf("%02f", nAmount)
	}

	sellID := sell(price, amount)
	if sellID == "-1" {
		warning += " [模擬]"
	} else if sellID == "0" {
		warning += "[委托失敗]"
	} else {
		warning += "[委托成功]" + sellID
	}

	logger.Infoln(warning)

	var coin string
	if Option["symbol"] == "btc_cny" {
		coin = "比特幣"
	} else {
		coin = "萊特幣"
	}

	if sellID != "0" {
		if !GetBacktest() {
			logger.Tradef("在%s,根據策略%s周期%s,以價格%s賣出%s個%s\n", Option["tradecenter"], Option["strategy"], Option["tick_interval"], price, amount, coin)
			go email.TriggerTrender(warning)
		} else {
			t := time.Unix(GetBtTime(), 0)
			logger.Backtestf("%s 在simulate,根據策略%s周期%s,以價格%s賣出%s個%s\n", t.Format("2006-01-02 15:04:05"), Option["strategy"], Option["tick_interval"], price, amount, coin)
		}
	}

	return sellID
}
開發者ID:cnspot,項目名稱:btcrobot,代碼行數:60,代碼來源:strategy.go

示例2: Buy

func Buy() string {
	if PrevTrade == "buy" {
		return "0"
	}

	//init
	isStoploss = false

	//compute the price
	price, nPrice, warning := getBuyPrice()

	//compute the amount
	amount := Option["tradeAmount"]
	nAmount, err := strconv.ParseFloat(amount, 64)
	if err != nil {
		logger.Infoln("amount is not float")
		return "0"
	}

	Available_cny := GetAvailable_cny()
	if Available_cny < nPrice*nAmount {
		var nMinTradeAmount float64
		nAmount = Available_cny / nPrice
		symbol := Option["symbol"]
		if symbol == "btc_cny" {
			nMinTradeAmount = 0.1
		} else {
			nMinTradeAmount = 0.01
		}
		if nAmount < nMinTradeAmount {
			warning += "沒有足夠的法幣餘額"
			logger.Infoln(warning)
			PrevTrade = "buy"
			PrevBuyPirce = nPrice
			return "0"
		}

		amount = fmt.Sprintf("%02f", nAmount)
	}

	warning += "---->數量" + amount

	buyID := buy(price, amount)
	if buyID == "-1" {
		warning += " [模擬]"
	} else if buyID == "0" {
		warning += "[委托失敗]"
	} else {
		warning += "[委托成功]" + buyID
	}

	logger.Infoln(warning)
	go email.TriggerTrender(warning)

	return buyID
}
開發者ID:9cat,項目名稱:btcrobot,代碼行數:56,代碼來源:strategy.go

示例3: Sell

func Sell() string {
	if PrevTrade == "sell" {
		return "0"
	}

	//compute the price
	price, _, warning := getSellPrice()

	//compute the amount
	Available_coin := GetAvailable_coin()
	if Available_coin < 0.01 {
		warning = "沒有足夠的幣"
		logger.Infoln(warning)
		PrevTrade = "sell"
		PrevBuyPirce = 0
		return "0"
	}

	amount := Option["tradeAmount"]
	nAmount, err := strconv.ParseFloat(amount, 64)
	if err != nil {
		logger.Infoln("amount is not float")
		return "0"
	}

	if nAmount > Available_coin {
		nAmount = Available_coin
		amount = fmt.Sprintf("%02f", nAmount)
	}

	sellID := sell(price, amount)
	if sellID == "-1" {
		warning += " [模擬]"
	} else if sellID == "0" {
		warning += "[委托失敗]"
	} else {
		warning += "[委托成功]" + sellID
	}

	logger.Infoln(warning)
	go email.TriggerTrender(warning)

	return sellID
}
開發者ID:9cat,項目名稱:btcrobot,代碼行數:44,代碼來源:strategy.go

示例4: SecretHandler

func SecretHandler(rw http.ResponseWriter, req *http.Request) {
	if !Basic(rw, req) {
		return
	}
	vars := mux.Vars(req)
	msgtype := vars["msgtype"]
	if req.Method != "POST" && msgtype == "" {
		// 獲取用戶信息
		err := config.LoadSecretOption()
		if err != nil {
			fmt.Fprint(rw, `{"errno": 1, "error":"`, "讀取秘鑰配置數據失敗", `"}`)
			return
		}
		// 設置模板數據
		filter.SetData(req, map[string]interface{}{"config": config.SecretOption})
		req.Form.Set(filter.CONTENT_TPL_KEY, "/template/trade/secret.html")
		return
	} else {
		config.SecretOption["username"] = req.FormValue("username")
		config.SecretOption["password"] = req.FormValue("password")

		config.SecretOption["huobi_access_key"] = req.FormValue("huobi_access_key")
		config.SecretOption["huobi_secret_key"] = req.FormValue("huobi_secret_key")

		config.SecretOption["ok_partner"] = req.FormValue("ok_partner")
		config.SecretOption["ok_secret_key"] = req.FormValue("ok_secret_key")

		config.SecretOption["smtp_username"] = req.FormValue("smtp_username")
		config.SecretOption["smtp_password"] = req.FormValue("smtp_password")
		config.SecretOption["smtp_host"] = req.FormValue("smtp_host")
		config.SecretOption["smtp_addr"] = req.FormValue("smtp_addr")

		// 更新個人信息
		err := config.SaveSecretOption()
		if err != nil {
			fmt.Fprint(rw, `{"errno": 1, "error":"`, "寫入秘鑰配置數據失敗", `"}`)
			return
		}

		fmt.Fprint(rw, `{"errno": 0, "msg":"更新秘鑰配置成功!"}`)

		go email.TriggerTrender("btcrobot測試郵件,您能收到這封郵件說明您的SMTP配置成功,來自星星的機器人")
	}
}
開發者ID:kewinwang,項目名稱:btcrobot,代碼行數:44,代碼來源:handler.go

示例5: webui

func webui() {
	m := martini.Classic()
	m.Get("/secret", func() string {
		// show something
		err := LoadSecretOption()
		if err != nil {
			logger.Errorln(err)
			return `{"errno": 1, "msg":", "讀取秘鑰配置數據失敗"}`
		}
		Option_json, err := json.Marshal(SecretOption)
		if err != nil {
			logger.Errorln(err)
			return `{"errno": 1, "msg":", "解析秘鑰配置數據失敗"}`
		}

		return string(Option_json)
	})

	m.Post("/secret", func(res http.ResponseWriter, req *http.Request) { // res and req are injected by Martini
		SecretOption["username"] = req.FormValue("username")
		SecretOption["password"] = req.FormValue("password")

		SecretOption["bitvc_email"] = req.FormValue("bitvc_email")
		SecretOption["bitvc_password"] = req.FormValue("bitvc_password")

		SecretOption["huobi_access_key"] = req.FormValue("huobi_access_key")
		SecretOption["huobi_secret_key"] = req.FormValue("huobi_secret_key")

		SecretOption["smtp_username"] = req.FormValue("smtp_username")
		SecretOption["smtp_password"] = req.FormValue("smtp_password")
		SecretOption["smtp_host"] = req.FormValue("smtp_host")
		SecretOption["smtp_addr"] = req.FormValue("smtp_addr")

		SecretOption["OKCoinAPIkey"] = req.FormValue("OKCoinAPIkey")

		SecretOption["ok_partner"] = req.FormValue("ok_partner")
		SecretOption["ok_secret_key"] = req.FormValue("ok_secret_key")

		SecretOption["ok_partner1"] = req.FormValue("ok_partner1")
		SecretOption["ok_secret_key1"] = req.FormValue("ok_secret_key1")

		SecretOption["ok_partner2"] = req.FormValue("ok_partner2")
		SecretOption["ok_secret_key2"] = req.FormValue("ok_secret_key2")

		SecretOption["ok_partner3"] = req.FormValue("ok_partner3")
		SecretOption["ok_secret_key3"] = req.FormValue("ok_secret_key3")

		SecretOption["ok_partner4"] = req.FormValue("ok_partner4")
		SecretOption["ok_secret_key4"] = req.FormValue("ok_secret_key4")

		SecretOption["ok_partner5"] = req.FormValue("ok_partner5")
		SecretOption["ok_secret_key5"] = req.FormValue("ok_secret_key5")

		SecretOption["ok_partner6"] = req.FormValue("ok_partner6")
		SecretOption["ok_secret_key6"] = req.FormValue("ok_secret_key6")

		SecretOption["ok_partner7"] = req.FormValue("ok_partner7")
		SecretOption["ok_secret_key7"] = req.FormValue("ok_secret_key7")

		SecretOption["ok_partner8"] = req.FormValue("ok_partner8")
		SecretOption["ok_secret_key8"] = req.FormValue("ok_secret_key8")

		SecretOption["ok_partner9"] = req.FormValue("ok_partner9")
		SecretOption["ok_secret_key9"] = req.FormValue("ok_secret_key9")

		SecretOption["ok_partner10"] = req.FormValue("ok_partner10")
		SecretOption["ok_secret_key10"] = req.FormValue("ok_secret_key10")

		// 更新個人信息
		err := SaveSecretOption()
		if err != nil {
			fmt.Fprint(res, "寫入秘鑰配置數據失敗")
			return
		}

		fmt.Fprint(res, "更新秘鑰配置成功!")

		go email.TriggerTrender("btcrobot測試郵件,您能收到這封郵件說明您的SMTP配置成功,來自星星的機器人")

		return
	})

	m.Get("/engine", func() string {
		// show something
		err := LoadOption()
		if err != nil {
			logger.Errorln(err)
			return `{"errno": 1, "msg":", "讀取引擎配置數據失敗"}`
		}
		Option_json, err := json.Marshal(Option)
		if err != nil {
			logger.Errorln(err)
			return `{"errno": 1, "msg":", "解析引擎配置數據失敗"}`
		}

		return string(Option_json)
	})

	m.Post("/engine", func(res http.ResponseWriter, req *http.Request) {
		if req.FormValue("enable_trading") == "on" {
//.........這裏部分代碼省略.........
開發者ID:RagnarDanneskjold,項目名稱:btcrobot,代碼行數:101,代碼來源:server.go

示例6: Tick

//HLCross strategy
func (HLCross *HLCrossStrategy) Tick(records []Record) bool {
	//read config

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

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

	length := len(Price)

	if HLCross.PrevClosePrice != records[length-1].Close ||
		HLCross.PrevHighPrice != records[length-2].High ||
		HLCross.PrevLowPrice != records[length-2].Low {
		HLCross.PrevClosePrice = records[length-1].Close
		HLCross.PrevHighPrice = records[length-2].High
		HLCross.PrevLowPrice = records[length-2].Low

		logger.Infof("nowClose %0.02f prevHigh %0.02f prevLow %0.02f\n", records[length-1].Close, records[length-2].High, records[length-2].Low)
	}

	//HLCross cross
	if records[length-1].Close > records[length-2].High {
		if Option["enable_trading"] == "1" && HLCross.PrevHLCrossTrade != "buy" {
			warning := "HLCross up, 買入buy In<----市價" + getTradePrice("", Price[length-1]) +
				",委托價" + getTradePrice("buy", Price[length-1])
			logger.Infoln(warning)
			if Buy(getTradePrice("buy", Price[length-1]), tradeAmount) != "0" {
				HLCross.PrevBuyPirce = Price[length-1]
				warning += "[委托成功]"
				HLCross.PrevHLCrossTrade = "buy"
			} else {
				warning += "[委托失敗]"
			}

			go email.TriggerTrender(warning)
		}
	} else if records[length-1].Close < records[length-2].Low {
		if Option["enable_trading"] == "1" && HLCross.PrevHLCrossTrade != "sell" {
			warning := "HLCross down, 賣出Sell Out---->市價" + getTradePrice("", Price[length-1]) +
				",委托價" + getTradePrice("sell", Price[length-1])
			logger.Infoln(warning)
			if Sell(getTradePrice("sell", Price[length-1]), tradeAmount) != "0" {
				warning += "[委托成功]"
				HLCross.PrevHLCrossTrade = "sell"
				HLCross.PrevBuyPirce = 0
			} else {
				warning += "[委托失敗]"
			}

			go email.TriggerTrender(warning)
		}
	}

	//do sell when price is below stoploss point
	if Price[length-1] < HLCross.PrevBuyPirce*(1-stoploss*0.01) {
		if Option["enable_trading"] == "1" && HLCross.PrevHLCrossTrade != "sell" {
			warning := "stop loss, 賣出Sell Out---->市價" + getTradePrice("", Price[length-1]) + ",委托價" + getTradePrice("sell", Price[length-1])
			logger.Infoln(warning)
			if Sell(getTradePrice("sell", Price[length-1]), tradeAmount) != "0" {
				warning += "[委托成功]"
				HLCross.PrevHLCrossTrade = "sell"
				HLCross.PrevBuyPirce = 0
			} else {
				warning += "[委托失敗]"
			}

			go email.TriggerTrender(warning)
		}
	}

	return true
}
開發者ID:jmliu88,項目名稱:btcrobot,代碼行數:84,代碼來源:HLCross.go

示例7: Tick

//xxx strategy
func (kdjStrategy *KDJStrategy) Tick(records []Record) bool {
	//實現自己的策略

	tradeAmount := Option["tradeAmount"]

	var Time []string
	var Price []float64
	var Volumn []float64
	for _, v := range records {
		Time = append(Time, v.TimeStr)
		Price = append(Price, v.Close)
		Volumn = append(Volumn, v.Volumn)
		//Price = append(Price, (v.Close+v.Open+v.High+v.Low)/4.0)
		//Price = append(Price, v.Low)
	}

	length := len(records)

	if kdjStrategy.PrevTime == records[length-1].TimeStr &&
		kdjStrategy.PrevPrice == records[length-1].Close {
		return false
	}

	//K線為白,D線為黃,J線為紅,K in middle
	k, d, j := getKDJ(records)

	if kdjStrategy.PrevTime != records[length-1].TimeStr ||
		kdjStrategy.PrevPrice != records[length-1].Close {
		kdjStrategy.PrevTime = records[length-1].TimeStr
		kdjStrategy.PrevPrice = records[length-1].Close

		logger.Infoln(records[length-1].TimeStr, records[length-1].Close)
		logger.Infof("d(黃線)%0.0f\tk(白線)%0.0f\tj(紅線)%0.0f\n", d[length-2], k[length-2], j[length-2])
		logger.Infof("d(黃線)%0.0f\tk(白線)%0.0f\tj(紅線)%0.0f\n", d[length-1], k[length-1], j[length-1])
	}

	if ((j[length-2] < k[length-2] && k[length-2] < d[length-2]) || kdjStrategy.PrevKDJTrade == "sell") &&
		(j[length-1] > k[length-1] && k[length-1] > d[length-1]) {
		logger.Infoln("KDJ up cross")
		if (kdjStrategy.PrevKDJTrade == "init" && d[length-2] <= 30) || kdjStrategy.PrevKDJTrade == "sell" {
			//do buy
			warning := "KDJ up cross, 買入buy In<----市價" + getTradePrice("", Price[length-1]) +
				",委托價" + getTradePrice("buy", Price[length-1])
			logger.Infoln(warning)
			if Buy(getTradePrice("buy", Price[length-1]), tradeAmount) != "0" {
				warning += "[委托成功]"
			} else {
				warning += "[委托失敗]"
			}

			kdjStrategy.PrevKDJTrade = "buy"

			go email.TriggerTrender(warning)
		}

	}

	if ((j[length-2] > k[length-2] && k[length-2] > d[length-2]) || kdjStrategy.PrevKDJTrade == "buy") &&
		(j[length-1] < k[length-1] && k[length-1] < d[length-1]) {

		logger.Infoln("KDJ down cross")
		if (kdjStrategy.PrevKDJTrade == "init" && d[length-2] >= 70) || kdjStrategy.PrevKDJTrade == "buy" {
			//do sell
			warning := "KDJ down cross, 賣出Sell Out---->市價" + getTradePrice("", Price[length-1]) +
				",委托價" + getTradePrice("sell", Price[length-1])
			logger.Infoln(warning)
			if Sell(getTradePrice("sell", Price[length-1]), tradeAmount) != "0" {
				warning += "[委托成功]"
			} else {
				warning += "[委托失敗]"
			}

			kdjStrategy.PrevKDJTrade = "sell"

			go email.TriggerTrender(warning)
		}

	}

	return true
}
開發者ID:Ryan-zzp,項目名稱:btcrobot,代碼行數:82,代碼來源:kdj.go

示例8: Tick


//.........這裏部分代碼省略.........
		emamacdemaStrategy.PrevEMACross = "down" //reset
		logger.Infoln("down->up(EMA diff < buy threshold)->down ^")

	}
	if emamacdemaStrategy.LessSellThreshold && is_uptrend(EMAdif[length-1]) {
		emamacdemaStrategy.LessSellThreshold = false
		emamacdemaStrategy.PrevEMACross = "up" //reset
		logger.Infoln("up->down(EMA diff > sell threshold)->up V")
	}

	//EMA cross
	if (emamacdemaStrategy.is_upcross(EMAdif[length-2], EMAdif[length-1]) || emamacdemaStrategy.LessBuyThreshold) ||
		(emamacdemaStrategy.is_downcross(EMAdif[length-2], EMAdif[length-1]) || emamacdemaStrategy.LessSellThreshold) { //up cross

		//do buy when cross up
		if emamacdemaStrategy.is_upcross(EMAdif[length-2], EMAdif[length-1]) || emamacdemaStrategy.LessBuyThreshold {
			if Option["enable_trading"] == "1" && emamacdemaStrategy.PrevEMATrade != "buy" {

				emamacdemaStrategy.PrevEMACross = "up"

				if emamacdemaStrategy.checkThreshold("buy", EMAdif[length-1]) {
					emamacdemaStrategy.PrevEMATrade = "buy"
					diff := fmt.Sprintf("%0.03f", EMAdif[length-1])
					warning := "EMA up cross, 買入buy In<----市價" + getTradePrice("", Price[length-1]) +
						",委托價" + getTradePrice("buy", Price[length-1]) + ",diff" + diff
					logger.Infoln(warning)
					if buy(getTradePrice("buy", Price[length-1]), tradeAmount) != "0" {
						emamacdemaStrategy.PrevBuyPirce = Price[length-1]
						warning += "[委托成功]"
					} else {
						warning += "[委托失敗]"
					}

					go email.TriggerTrender(warning)
				}
			}
		}

		//do sell when cross down
		if emamacdemaStrategy.is_downcross(EMAdif[length-2], EMAdif[length-1]) || emamacdemaStrategy.LessSellThreshold {
			emamacdemaStrategy.PrevEMACross = "down"
			if Option["enable_trading"] == "1" && emamacdemaStrategy.PrevEMATrade != "sell" {
				if emamacdemaStrategy.checkThreshold("sell", EMAdif[length-1]) {
					emamacdemaStrategy.PrevEMATrade = "sell"
					diff := fmt.Sprintf("%0.03f", EMAdif[length-1])
					warning := "EMA down cross, 賣出Sell Out---->市價" + getTradePrice("", Price[length-1]) +
						",委托價" + getTradePrice("sell", Price[length-1]) + ",diff" + diff
					logger.Infoln(warning)

					var ematradeAmount string
					if emamacdemaStrategy.PrevMACDTrade == "sell" {
						ematradeAmount = MacdTradeAmount
						emamacdemaStrategy.PrevMACDTrade = "init"
					} else {
						ematradeAmount = tradeAmount
					}

					if sell(getTradePrice("sell", Price[length-1]), ematradeAmount) != "0" {
						warning += "[委托成功]"
					} else {
						warning += "[委托失敗]"
					}

					go email.TriggerTrender(warning)
				}
			}
開發者ID:2yeslater,項目名稱:btcrobot,代碼行數:67,代碼來源:emamacdema.go

示例9: SendEmail

func SendEmail(warning string) {
	if !GetBacktest() {
		go email.TriggerTrender(warning)
	}
}
開發者ID:ifzz,項目名稱:btcrobot,代碼行數:5,代碼來源:kdj_ex.go

示例10: 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
		}
	*/

	tradeAmount := Option["tradeAmount"]
	stoploss, err := strconv.ParseFloat(Option["stoploss"], 64)
	if err != nil {
		logger.Errorln("config item stoploss 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 Time []string
	var Price []float64
	var Volumn []float64
	for _, v := range records {
		Time = append(Time, v.TimeStr)
		Price = append(Price, v.Close)
		Volumn = append(Volumn, v.Volumn)
		//Price = append(Price, (v.Close+v.Open+v.High+v.Low)/4.0)
		//Price = append(Price, v.Low)
	}

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

	length := len(Price)

	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) ||
		(macdStrategy.PrevMACDTrade == "sell" && MACDHistogram[length-2] > 0.000001 && MACDHistogram[length-1] > MACDbuyThreshold) {
		if Option["enable_trading"] == "1" && macdStrategy.PrevMACDTrade != "buy" {
			macdStrategy.PrevMACDTrade = "buy"

			histogram := fmt.Sprintf("%0.03f", MACDHistogram[length-1])
			warning := "MACD up cross, 買入buy In<----市價" + getTradePrice("", Price[length-1]) +
				",委托價" + getTradePrice("buy", Price[length-1]) + ",histogram" + histogram
			logger.Infoln(warning)
			if Buy(getTradePrice("buy", Price[length-1]), tradeAmount) != "0" {
				macdStrategy.PrevBuyPirce = Price[length-1]
				warning += "[委托成功]"
			} else {
				warning += "[委托失敗]"
			}

			go email.TriggerTrender(warning)
		}
	} else if (MACDHistogram[length-2] > 0.000001 && MACDHistogram[length-1] < MACDsellThreshold) ||
		(macdStrategy.PrevMACDTrade == "buy" && MACDHistogram[length-2] < -0.000001 && MACDHistogram[length-1] < MACDsellThreshold) {
		if Option["enable_trading"] == "1" && macdStrategy.PrevMACDTrade != "sell" {
			macdStrategy.PrevMACDTrade = "sell"

			histogram := fmt.Sprintf("%0.03f", MACDHistogram[length-1])
			warning := "MACD down cross, 賣出Sell Out---->市價" + getTradePrice("", Price[length-1]) +
				",委托價" + getTradePrice("sell", Price[length-1]) + ",histogram" + histogram
			logger.Infoln(warning)
			if Sell(getTradePrice("sell", Price[length-1]), tradeAmount) != "0" {
				warning += "[委托成功]"
			} else {
				warning += "[委托失敗]"
			}

			go email.TriggerTrender(warning)
		}
	}

	//do sell when price is below stoploss point
	if Price[length-1] < macdStrategy.PrevBuyPirce*(1-stoploss*0.01) {
		if Option["enable_trading"] == "1" && macdStrategy.PrevMACDTrade != "sell" {
//.........這裏部分代碼省略.........
開發者ID:Ryan-zzp,項目名稱:btcrobot,代碼行數:101,代碼來源:macd.go

示例11: Perform

//MACD strategy
func (macdStrategy *MACDStrategy) Perform(tradeAPI TradeAPI, Time []string, Price []float64, Volumn []float64) 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
		}
	*/

	tradeAmount := Option["tradeAmount"]
	stoploss, err := strconv.ParseFloat(Option["stoploss"], 64)
	if err != nil {
		logger.Errorln("config item stoploss 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
	}

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

	length := len(Price)

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

	//macd cross
	if (MACDHistogram[length-2] < -0.000001 && MACDHistogram[length-1] > MACDbuyThreshold) ||
		(macdStrategy.PrevMACDTrade == "sell" && MACDHistogram[length-2] > 0.000001 && MACDHistogram[length-1] > MACDbuyThreshold) {
		if Option["disable_trading"] != "1" && macdStrategy.PrevMACDTrade != "buy" {
			macdStrategy.PrevMACDTrade = "buy"

			histogram := fmt.Sprintf("%0.03f", MACDHistogram[length-1])
			warning := "MACD up cross, 買入buy In<----市價" + tradeAPI.GetTradePrice("") +
				",委托價" + tradeAPI.GetTradePrice("buy") + ",histogram" + histogram
			logger.Infoln(warning)
			if tradeAPI.Buy(tradeAPI.GetTradePrice("buy"), tradeAmount) {
				macdStrategy.PrevBuyPirce = Price[length-1]
				warning += "[委托成功]"
			} else {
				warning += "[委托失敗]"
			}

			go email.TriggerTrender(warning)
		}
	} else if (MACDHistogram[length-2] > 0.000001 && MACDHistogram[length-1] < MACDsellThreshold) ||
		(macdStrategy.PrevMACDTrade == "buy" && MACDHistogram[length-2] < -0.000001 && MACDHistogram[length-1] < MACDsellThreshold) {
		if Option["disable_trading"] != "1" && macdStrategy.PrevMACDTrade != "sell" {
			macdStrategy.PrevMACDTrade = "sell"

			histogram := fmt.Sprintf("%0.03f", MACDHistogram[length-1])
			warning := "MACD down cross, 賣出Sell Out---->市價" + tradeAPI.GetTradePrice("") +
				",委托價" + tradeAPI.GetTradePrice("sell") + ",histogram" + histogram
			logger.Infoln(warning)
			if tradeAPI.Sell(tradeAPI.GetTradePrice("sell"), tradeAmount) {
				warning += "[委托成功]"
			} else {
				warning += "[委托失敗]"
			}

			go email.TriggerTrender(warning)
		}
	}

	//do sell when price is below stoploss point
	if Price[length-1] < macdStrategy.PrevBuyPirce*(1-stoploss*0.01) {
		if Option["disable_trading"] != "1" && macdStrategy.PrevMACDTrade != "sell" {
			macdStrategy.PrevMACDTrade = "sell"
			macdStrategy.PrevBuyPirce = 0
			warning := "stop loss, 賣出Sell Out---->市價" + tradeAPI.GetTradePrice("") + ",委托價" + tradeAPI.GetTradePrice("sell")
			logger.Infoln(warning)
			if tradeAPI.Sell(tradeAPI.GetTradePrice("sell"), tradeAmount) {
				warning += "[委托成功]"
			} else {
				warning += "[委托失敗]"
			}

			go email.TriggerTrender(warning)
//.........這裏部分代碼省略.........
開發者ID:kewinwang,項目名稱:btcrobot,代碼行數:101,代碼來源:macd.go

示例12: Tick


//.........這裏部分代碼省略.........

			avgLow := (records[length-2].Close + records[length-1].Low) / 2.0
			logger.Infoln("X 兩根K線的最低平均價", avgLow)
			//fmt.Println(ret, orderbook)

			warning := "KDJ up cross, 買入buy In<----限價單"
			for i := 1; i <= ordercount; i++ {
				warning := "KDJ up cross, 買入buy In<----限價單"
				tradePrice := fmt.Sprintf("%f", avgLow+slappage*float64(i))
				buyID := buy(tradePrice, splitTradeAmount)
				if buyID != "0" {
					warning += "[委托成功]"
					kdjex.BuyId = append(kdjex.BuyId, buyID)
				} else {
					warning += "[委托失敗]"
				}

				logger.Infoln(warning)
			}

			kdjex.BuyBegin = time.Now()
			kdjex.PrevKDJTrade = "buy"

			kdjex.PrevBuyPirce = avgLow

			logger.Infoln("------------>>>stoploss price", kdjex.PrevBuyPirce*(1-stoploss*0.01))

			_, ret = GetAccount()

			if !ret {
				logger.Infoln("GetAccount failed")
			}

			go email.TriggerTrender(warning)
		}
	}

	if (j[length-2] > k[length-2] && k[length-2] > d[length-2]) &&
		(j[length-1] < k[length-1] && k[length-1] < d[length-1]) {

		logger.Infoln("<----------------------KDJ down cross", kdjex.PrevKDJTrade, d[length-2])

		if kdjex.PrevKDJTrade != "sell" && j[length-2] >= 80 {
			//do sell

			ret, orderbook := GetOrderBook()
			if !ret {
				logger.Infoln("get orderbook failed 1")
				ret, orderbook = GetOrderBook() //try again
				if !ret {
					logger.Infoln("get orderbook failed 2")
					return false
				}
			}

			logger.Infoln("賣一", (orderbook.Asks[len(orderbook.Asks)-1]))
			logger.Infoln("買一", orderbook.Bids[0])

			logger.Infoln("X 兩根K線最低價", records[length-2].Low, records[length-1].Low)
			logger.Infoln("X 兩根K線最高價", records[length-2].High, records[length-1].High)

			avgHigh := (records[length-2].Close + records[length-1].High) / 2.0
			logger.Infoln("X 兩根K線的最高平均價", avgHigh)
			warning := "KDJ down cross, 賣出Sell Out---->限價單"

			for i := 1; i <= ordercount; i++ {
開發者ID:9cat,項目名稱:btcrobot,代碼行數:67,代碼來源:kdj_ex.go

示例13: Tick

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

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

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

	var Time []string
	var Price []float64
	var Volumn []float64
	for _, v := range records {
		Time = append(Time, v.TimeStr)
		Price = append(Price, v.Close)
		Volumn = append(Volumn, v.Volumn)
		//Price = append(Price, (v.Close+v.Open+v.High+v.Low)/4.0)
		//Price = append(Price, v.Low)
	}

	//compute the indictor
	emaShort := EMA(Price, shortEMA)
	emaLong := EMA(Price, longEMA)
	EMAdif := getMACDdif(emaShort, emaLong)

	length := len(Price)
	if emaStrategy.PrevEMACross == "unknown" {
		if is_uptrend(EMAdif[length-3]) {
			emaStrategy.PrevEMACross = "up"
		} else if is_downtrend(EMAdif[length-3]) {
			emaStrategy.PrevEMACross = "down"
		} else {
			emaStrategy.PrevEMACross = "unknown"
		}
		logger.Infoln("prev cross is", emaStrategy.PrevEMACross)
		if is_uptrend(EMAdif[length-3]) {
			logger.Infoln("上一個趨勢是上漲,等待賣出點觸發")
		} else if is_downtrend(EMAdif[length-3]) {
			logger.Infoln("上一個趨勢是下跌,等待買入點觸發")
		} else {
			logger.Infoln("上一個趨勢是unknown。。。")
		}
	}

	//go TriggerPrice(Price[length-1])
	if EMAdif[length-1] != emaStrategy.PrevEMAdif {
		emaStrategy.PrevEMAdif = EMAdif[length-1]
		logger.Infof("EMA [%0.02f,%0.02f,%0.02f] Diff:%0.03f\t%0.03f\n", Price[length-1], emaShort[length-1], emaLong[length-1], EMAdif[length-2], EMAdif[length-1])
	}

	//reset LessBuyThreshold LessSellThreshold flag when (^ or V) happen
	if emaStrategy.LessBuyThreshold && is_downtrend(EMAdif[length-1]) {
		emaStrategy.LessBuyThreshold = false
		emaStrategy.PrevEMACross = "down" //reset
		logger.Infoln("down->up(EMA diff < buy threshold)->down ^")

	}
	if emaStrategy.LessSellThreshold && is_uptrend(EMAdif[length-1]) {
		emaStrategy.LessSellThreshold = false
		emaStrategy.PrevEMACross = "up" //reset
		logger.Infoln("up->down(EMA diff > sell threshold)->up V")
	}

	//EMA cross
	if (emaStrategy.is_upcross(EMAdif[length-2], EMAdif[length-1]) || emaStrategy.LessBuyThreshold) ||
		(emaStrategy.is_downcross(EMAdif[length-2], EMAdif[length-1]) || emaStrategy.LessSellThreshold) { //up cross

		//do buy when cross up
		if emaStrategy.is_upcross(EMAdif[length-2], EMAdif[length-1]) || emaStrategy.LessBuyThreshold {
			if Option["enable_trading"] == "1" && emaStrategy.PrevEMATrade != "buy" {

				emaStrategy.PrevEMACross = "up"

				if emaStrategy.checkThreshold("buy", EMAdif[length-1]) {

					emaStrategy.PrevEMATrade = "buy"

					diff := fmt.Sprintf("%0.03f", EMAdif[length-1])
					warning := "EMA up cross, 買入buy In<----市價" + getTradePrice("", Price[length-1]) +
						",委托價" + getTradePrice("buy", Price[length-1]) + ",diff" + diff
					logger.Infoln(warning)

					if Buy(getTradePrice("buy", Price[length-1]), tradeAmount) != "0" {
						emaStrategy.PrevBuyPirce = Price[length-1]
						warning += "[委托成功]"
					} else {
						warning += "[委托失敗]"
					}

					go email.TriggerTrender(warning)
//.........這裏部分代碼省略.........
開發者ID:Ryan-zzp,項目名稱:btcrobot,代碼行數:101,代碼來源:ema.go

示例14: Buy

func Buy() string {
	if PrevTrade == "buy" {
		return "0"
	}

	// init
	isStoploss = false

	// compute the price
	price, nPrice, warning := getBuyPrice()

	// compute the amount
	amount := Option["tradeAmount"]
	nAmount, err := strconv.ParseFloat(amount, 64)
	if err != nil {
		logger.Infoln("amount is not float")
		return "0"
	}

	Available_cny := GetAvailable_cny()
	if Available_cny < nPrice*nAmount {
		var nMinTradeAmount float64
		nAmount = Available_cny / nPrice
		symbol := Option["symbol"]
		if symbol == "btc_cny" {
			nMinTradeAmount = 0.1
		} else {
			nMinTradeAmount = 0.01
		}
		if nAmount < nMinTradeAmount {
			warning += "沒有足夠的法幣餘額"
			logger.Infoln(warning)
			PrevTrade = "buy"
			PrevBuyPirce = nPrice
			return "0"
		}

		amount = fmt.Sprintf("%02f", nAmount)
	}

	warning += "---->數量" + amount

	buyID := buy(price, amount)
	if buyID == "-1" {
		warning += " [模擬]"
	} else if buyID == "0" {
		warning += "[委托失敗]"
	} else {
		warning += "[委托成功]" + buyID
	}

	logger.Infoln(warning)

	var coin string
	if Option["symbol"] == "btc_cny" {
		coin = "比特幣"
	} else {
		coin = "萊特幣"
	}

	if buyID != "0" {
		if !GetBacktest() {
			logger.Tradef("在%s,根據策略%s周期%s,以價格%s買入%s個%s\n", Option["tradecenter"], Option["strategy"], Option["tick_interval"], price, amount, coin)
			go email.TriggerTrender(warning)
		} else {
			t := time.Unix(GetBtTime(), 0)
			logger.Backtestf("%s 在simulate,根據策略%s周期%s,以價格%s買入%s個%s\n", t.Format("2006-01-02 15:04:05"), Option["strategy"], Option["tick_interval"], price, amount, coin)
		}
	}

	return buyID
}
開發者ID:cnspot,項目名稱:btcrobot,代碼行數:72,代碼來源:strategy.go


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