Exemple #1
0
func testBitVCAPI() {
	tradeAPI := bitvc.NewBitvc()
	accout_info, _ := tradeAPI.GetAccount()
	fmt.Println(accout_info)
	/*
		fmt.Println(tradeAPI.GetAccount())
		if false {
			buyId := tradeAPI.BuyBTC("1000", "0.001")
			sellId := tradeAPI.SellBTC("10000", "0.001")

			if tradeAPI.Cancel_order(buyId) {
				fmt.Printf("cancel %s success \n", buyId)
			} else {
				fmt.Printf("cancel %s falied \n", buyId)
			}

			if tradeAPI.Cancel_order(sellId) {
				fmt.Printf("cancel %s success \n", sellId)
			} else {
				fmt.Printf("cancel %s falied \n", sellId)
			}
		}

		fmt.Println(tradeAPI.Get_orders())
	*/
}
Exemple #2
0
func tradeAPI() (tradeAPI TradeAPI) {
	if Option["tradecenter"] == "huobi" {
		tradeAPI = huobi.NewHuobi()
	} else if Option["tradecenter"] == "okcoin" {
		tradeAPI = okcoin.NewOkcoin()
	} else if Option["tradecenter"] == "bitvc" {
		tradeAPI = bitvc.NewBitvc()
	} else if Option["tradecenter"] == "peatio" {
		tradeAPI = peatio.NewPeatio()
	} else {
		logger.Fatalln("Please config the exchange center...")
	}
	return
}
Exemple #3
0
func tradeAPI() (tradeAPI TradeAPI) {
	if Option["tradecenter"] == "huobi" {
		tradeAPI = huobi.NewHuobi()
	} else if Option["tradecenter"] == "okcoin" {
		tradeAPI = okcoin.NewOkcoin()
	} else if Option["tradecenter"] == "bitvc" {
		tradeAPI = bitvc.NewBitvc()
	} else if Option["tradecenter"] == "peatio" {
		tradeAPI = peatio.NewPeatio()
	} else if Option["tradecenter"] == "bittrex" {
		tradeAPI = Bittrex.Manager()
	} else if Option["tradecenter"] == "simulate" {
		tradeAPI = simulate.NewSimulate()
	} else {
		logger.Fatalln("Please config the exchange center...")
		panic(0)
	}
	return
}
Exemple #4
0
func RobotWorker() {
	fmt.Println("env", Config["env"])
	if DebugEnv || Config["env"] == "dev" {
		fmt.Println("test working...")
		mintpal.Manager().GetMarketSummary("")
		mintpal.Manager().GetMarketStats("BC", "BTC")
		mintpal.Manager().GetMarketTrades("BC", "BTC")
		mintpal.Manager().GetMarketOrders("BC", "BTC", "BUY")
		mintpal.Manager().GetMarketOrders("BC", "BTC", "SELL")
		mintpal.Manager().GetMarketChartData("BC", "BTC", "MAX")

		return

		var tradeAPI TradeAPI
		tradeAPI = bitvc.NewBitvc()
		tradeAPI.GetAccount()
		//tradeAPI.GetOrderBook()
		return

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