Пример #1
0
def Main():

    exchange = Binance()
    symbols = exchange.GetTradingSymbols(quoteAssets=["ETH"])

    strategy_evaluators = [
        StrategyEvaluator(strategy_function=Strategies.bollStrategy),
        StrategyEvaluator(strategy_function=Strategies.maStrategy),
        StrategyEvaluator(strategy_function=Strategies.ichimokuBullish)
    ]

    print(opening_text)

    answer = input()
    while answer not in ['b', 'e', 'q']:
        print(opening_text)
        answer = input()

    if answer == 'e':
        EvaluateStrategies(symbols=symbols,
                           interval='5m',
                           strategy_evaluators=strategy_evaluators)
    if answer == 'b':
        BacktestStrategies(symbols=symbols,
                           interval='5m',
                           plot=True,
                           strategy_evaluators=strategy_evaluators)
    if answer == 'q':
        print("\nBYE!\n")
Пример #2
0
def Main():
    exchange = Binance()
    symbols = exchange.GetTradingSymbols(quoteAssets=["ETH"])

    strategy_evaluators = [
        StrategyEvaluator(strategy_function=Strategies.bollStrategy),
        StrategyEvaluator(strategy_function=Strategies.maStrategy),
        StrategyEvaluator(strategy_function=Strategies.ichimokuBullish)
    ]
    opening_text = "\nWelcome to Tudor's Crypto Trading Bot. \n \
	Press 'b' (ENTER) to backtest all strategies \n \
	Press 'e' (ENTER) to execute the strategies on all coins \n \
	Press 'q' (ENTER) to quit. "

    print(opening_text)
    '''
    answer = input()
	while answer not in ['b', 'e', 'q']:
		print(opening_text)
		answer = input()

	if answer == 'e':
		EvaluateStrategies(symbols=symbols, interval='5m', strategy_evaluators=strategy_evaluators)
	if answer == 'b':
		BacktestStrategies(symbols=symbols, interval='5m', plot=True, strategy_evaluators=strategy_evaluators)
	if answer == 'q':
		print("\nBYE!\n")
    '''
    answer = input()
    symbol = 'ETCBTC'
    interval = '1h'

    model = TradingModel(symbol=symbol, timeframe=interval)

    if answer == 'buy':
        order_result = model.exchange.PlaceOrder(model.symbol,
                                                 "BUY",
                                                 "MARKET",
                                                 quantity=0.02,
                                                 test=False)
    elif answer == 'sell':
        order_result = model.exchange.PlaceOrder(model.symbol,
                                                 "SELL",
                                                 "MARKET",
                                                 quantity=0.01,
                                                 test=False)

        if "code" in order_result:
            print("\nERROR.")
            print(order_result)
        else:
            print("\nSUCCESS.")
            print(order_result)
Пример #3
0
def Main():

	exchange = Binance()
	# symbols = exchange.GetTradingSymbols(quoteAssets=["BTC", "USDT", "ETH"])
	symbols = exchange.GetTradingSymbols(quoteAssets=["BTC"])

	strategy_evaluators = [
		StrategyEvaluator(strategy_function=strategies_dict['bollinger_simple']),
		# StrategyEvaluator(strategy_function=Strategies.maStrategy),
		# StrategyEvaluator(strategy_function=strategies_dict['ichimoku_bullish']),
		# StrategyEvaluator(strategy_function=strategies_dict['ma_crossover'])
	]

	print(opening_text)
	
	answer = input()
	while answer not in ['b', 'e', 'q']:
		print(opening_text)
		answer = input()

	if answer == 'e':
		EvaluateStrategies(symbols=symbols, interval='1h', strategy_evaluators=strategy_evaluators)
	if answer == 'b':
		BacktestStrategies(symbols=symbols, interval='1h', plot=False, strategy_evaluators=strategy_evaluators)
	if answer == 'q':
		print("\nBYE!\n")
Пример #4
0
def BacktestStrategies(symbols=[], interval='4h', plot=False):

    trade_value = Decimal(100)

    strategy_evaluators = [
        StrategyEvaluator(strategy_function=Strategies.bollStrategy,
                          strategy_settings={'indicators': ['low_boll']}),
        StrategyEvaluator(strategy_function=Strategies.maStrategy,
                          strategy_settings={'indicators': ['slow_sma']})
    ]

    coins_tested = 0

    for symbol in symbols:

        print(symbol)

        model = TradingModel(symbol=symbol, timeframe=interval)

        for evaluator in strategy_evaluators:
            resulting_balance = evaluator.backtest(
                model, starting_balance=trade_value)

            if resulting_balance != trade_value:
                print(evaluator.strategy.__name__ + ": starting balance: " +
                      str(trade_value) + ": resulting balance: " +
                      str(round(resulting_balance, 2)))

                if plot:
                    model.plotData(buy_signals=evaluator.results[
                        model.symbol]['buy_times'],
                                   sell_signals=evaluator.results[
                                       model.symbol]['sell_times'],
                                   plot_title=evaluator.strategy.__name__ +
                                   " on " + model.symbol,
                                   indicators=evaluator.settings['indicators'])

                evaluator.profits_list.append(resulting_balance - trade_value)
                evaluator.updateResult(trade_value, resulting_balance)

            coins_tested = coins_tested + 1

    for evaluator in strategy_evaluators:
        print("")
        evaluator.printResults()
Пример #5
0
def Main():
    #log file.. when bot is running in paper mode log trades
    lf = open('tradelog.txt', 'w')
    lf.write("welcoem to trade bot's log file")
    print(opening_text)
    answer = input()
    if answer == 'e':
        exchange = Binance()
        symbols = [
            "BNBETH"
        ]  #, "BTCUSDT", "BNBBTC", "LTCBTC", "BANDBTC", "ETHBTC"]    #exchange.GetTradingSymbols(quoteAssets=["ETH"])

        strategy_evaluators = [
            #StrategyEvaluator(strategy_function=Strategies.bollStrategy),
            #StrategyEvaluator(strategy_function=Strategies.maStrategy),
            StrategyEvaluator(strategy_function=Strategies.ichimokuBullish)
        ]
        #loop 20 times a second
        while True:
            try:
                t1 = time.monotonic()
                print(str(t1), flush=True)
                #BacktestStrategies(symbols=symbols, interval='5m', plot=True, strategy_evaluators=strategy_evaluators)
                EvaluateStrategies(symbols=symbols,
                                   interval='5m',
                                   strategy_evaluators=strategy_evaluators)
                t2 = time.monotonic()
                if (t2 - t1) < 0.05:
                    time.sleep(0.05)
            except KeyboardInterrupt:
                print("key board interrupt by user")
                return
    elif answer == 'q':
        sys.exit("user quit program")

    lf.close()