Пример #1
0
func sell(price, amount string) string {
	var sellID string
	if Option["enable_trading"] == "1" {
		sellID = gTradeAPI.Sell(price, amount)
	} else {
		sellID = "-1"
	}

	if sellID != "0" {
		timestamp := time.Now()
		magic += 1
		db.SetTx("sell", sellID, timestamp.Unix(), price, amount, magic)
		sellOrders[timestamp] = sellID
		PrevTrade = "sell"
		PrevBuyPirce = 0
	}

	{
		cmd, id, timestamp, amount, price, magic, err := db.GetTx(sellID)
		if err != nil {
			fmt.Println("GetTx", err)
		} else {
			fmt.Println("sell items:", cmd, id, timestamp, amount, price, magic)
		}
	}

	return sellID
}
Пример #2
0
func sell(price, amount string) string {
	Available_coin := GetAvailable_coin()
	if Available_coin < 0.01 {
		warning = "没有足够的币"
		logger.Infoln(warning)
		PrevTrade = "sell"
		PrevBuyPirce = 0
		return "0"
	}

	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)
	}

	var sellID string
	if Option["enable_trading"] == "1" {
		sellID = gTradeAPI.Sell(price, amount)
	} else {
		sellID = "-1"
	}

	if sellID != "0" {
		timestamp := time.Now()
		magic += 1
		if !GetBacktest() {
			err := db.SetTx("sell", sellID, timestamp.Unix(), price, amount, magic)
			if err != nil {
				fmt.Println("SetTx", err)
			}
		}
		sellOrders[timestamp] = sellID
		PrevTrade = "sell"
		PrevBuyPirce = 0
	}

	if !GetBacktest() {
		cmd, id, timestamp, amount, price, magic, err := db.GetTx(sellID)
		if err != nil {
			fmt.Println("GetTx", err)
		} else {
			fmt.Println("sell items:", cmd, id, timestamp, amount, price, magic)
		}
	}

	return sellID
}
Пример #3
0
func buy(price, amount string) string {
	nPrice, err := strconv.ParseFloat(price, 64)
	if err != nil {
		logger.Debugln("price is not float")
		return "0"
	}

	var buyID string
	if Option["enable_trading"] == "1" {
		buyID = gTradeAPI.Buy(price, amount)
	} else {
		buyID = "-1"
	}

	if buyID != "0" {
		timestamp := time.Now()
		magic += 1
		err := db.SetTx("buy", buyID, timestamp.Unix(), amount, price, magic)
		if err != nil {
			fmt.Println("SetTx", err)
		}
		buyOrders[timestamp] = buyID
		PrevTrade = "buy"
		PrevBuyPirce = nPrice
	}

	{
		cmd, id, timestamp, amount, price, magic, err := db.GetTx(buyID)
		if err != nil {
			fmt.Println("GetTx", err)
		} else {
			fmt.Println("buy items:", cmd, id, timestamp, amount, price, magic)
		}
	}

	return buyID
}
Пример #4
0
func buy(price, amount string) string {
	nPrice, err := strconv.ParseFloat(price, 64)
	if err != nil {
		logger.Debugln("price is not float")
		return "0"
	}

	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"
		}
	}

	var buyID string
	if Option["enable_trading"] == "1" {
		buyID = gTradeAPI.Buy(price, amount)
	} else {
		buyID = "-1"
	}

	if buyID != "0" {
		timestamp := time.Now()
		magic += 1
		if !GetBacktest() {
			err := db.SetTx("buy", buyID, timestamp.Unix(), amount, price, magic)
			if err != nil {
				fmt.Println("SetTx", err)
			}
		}
		buyOrders[timestamp] = buyID
		PrevTrade = "buy"
		PrevBuyPirce = nPrice
	}

	if !GetBacktest() {
		cmd, id, timestamp, amount, price, magic, err := db.GetTx(buyID)
		if err != nil {
			fmt.Println("GetTx", err)
		} else {
			fmt.Println("buy items:", cmd, id, timestamp, amount, price, magic)
		}
	}

	return buyID
}