コード例 #1
0
#!/usr/bin/python2.7
import sys
print 'python', sys.version
import utility_3 as ut
from binance.client import Client
import time
# INDICATOR BOT #
ut.pickle_write(
    '/home/ec2-user/environment/botfarming/Development/variables/indicator_trades_12h',
    [])
indicator_bot = 1
file_number = 0
total_files = 1
length = '12h'
ut.pickle_write(
    '/home/ec2-user/environment/botfarming/Development/variables/stop_trading_until_'
    + length,
    int(time.time()) + 12 * 60 * 2 * 60)
api_key = '41EwcPBxLxrwAw4a4W2cMRpXiQwaJ9Vibxt31pOWmWq8Hm3ZX2CBnJ80sIRJtbsI'
api_secret = 'pnHoASmoe36q54DZOKsUujQqo4n5Ju25t5G0kBaioZZgGDOQPEHqgDDPA6s5dUiB'
client = Client(api_key, api_secret)

ut.run_bot_parallel(file_number, length, total_files, client, indicator_bot)
コード例 #2
0
ファイル: utility.py プロジェクト: nelsonriley/botfarming
def run_optimizer_multi(lengths):
    while True:
        
        for length in lengths:
            
            symbols = ut.pickle_read('/home/ec2-user/environment/botfarming/Development/3_binance_btc_symbols.pklz')
            symbols_trimmed = {}
            total_btc_coins = 0
            for s in symbols:
                symbol = symbols[s]
                if float(symbol['24hourVolume']) > 300:
                    total_btc_coins += 1
                    symbols_trimmed[s] = symbol
            print('total symbols', total_btc_coins)
    
            if length == '1m':
                data_length_multiplier = 360 # 6 hours      # 3x as long, but 12 sections
                minutes = 1
                minutes_until_sale = 12
            if length == '5m':
                data_length_multiplier = 60*24*2/5 # 2 days
                minutes = 5
                minutes_until_sale = 12
            if length == '15m':
                data_length_multiplier = 60*24*7/15 # 1 wk
                minutes = 15
                minutes_until_sale = 12
            if length == '30m':
                data_length_multiplier = 60*24*14/30 # 2 wks
                minutes = 30
                minutes_until_sale = 12
            if length == '1h':
                data_length_multiplier = 60*24*14/60 # 2 wks
                minutes = 60
                minutes_until_sale = 12
            if length == '2h':
                data_length_multiplier = 60*24*30/120 # 1 month
                minutes = 60 * 2
                minutes_until_sale = 8
            if length == '6h':
                data_length_multiplier = 60*24*45/360 # 1.5 months
                minutes = 60 * 6
                minutes_until_sale = 4
            if length == '12h':
                data_length_multiplier = 60*24*90/720 # 3 months
                minutes = 60 * 12
                minutes_until_sale = 3
            if length == '1d':
                data_length_multiplier = 60*24*120/1440 # 4 months
                minutes = 60 * 24
                minutes_until_sale = 2
            hours_per_period = round(float(data_length_multiplier*minutes/60.0), 3)
            
            symbols_started = 0
            for s in symbols_trimmed:
                symbols_started += 1
                print('########## symbols_started', symbols_started, 'for', length, ut.get_time())
                
                #get data in right format for save function (could fix this)
                symbol = symbols_trimmed[s]
                symbols_trimmed_one = {}
                for s_one in symbols:
                    symbol_one = symbols[s_one]
                    if symbol_one['symbol'] == symbol['symbol']:
                        symbols_trimmed_one[s] = symbol_one
                
                # 777
                optimizing_array = [1,3,5,7,9,11,13,15]
                results_by_look_back = {}
                for lb in optimizing_array:
                    results_by_look_back[str(lb)] = []
            
                step_back_periods = 12
                for step_back in range(0, step_back_periods):
                    end_time = int(time.time()) - data_length_multiplier * step_back * minutes * 60
                    results = get_optimization_factors(optimizing_array, data_length_multiplier, end_time, symbol, symbols_trimmed_one, length, minutes, minutes_until_sale)
                    for r in results:
                        results_by_look_back[str(r['look_back'])].append(r)
                    # results = [r, r, r...]
                        # r['lowest_buy_factor'] = lowest_buy_factor
                        # r['highest_sale_factor'] = highest_sale_factor
                        # r['look_back'] = optimizing
                        # r['optimal_buy_factor'] = lowest_buy_factor
                        # r['optimal_sell_factor'] = highest_sale_factor
                
                for lb in results_by_look_back:
                    lowest_buy_factors = []
                    highest_sale_factors = []
                    results = results_by_look_back[lb]
                    for r in results:
                        lowest_buy_factors.append(r['optimal_buy_factor'])
                        highest_sale_factors.append(r['optimal_sell_factor'])
                    lowest_buy_factor_stats = fn.std_dev(lowest_buy_factors)
                    highest_sale_factor_stats = fn.std_dev(highest_sale_factors)
                    # print('#####################################################')
                    # print('LOWEST BUY FACTORS ######## LOOK_BACK', lb, s, step_back_periods, '*', hours_per_period, 'hrs')
                    # pprint(lowest_buy_factor_stats)
                    # print(lowest_buy_factors)
                    # print('HIGHEST SALE FACTORS ######## LOOK_BACK', lb, s, step_back_periods, '*', hours_per_period, 'hrs')
                    # pprint(highest_sale_factor_stats)
                    # print(highest_sale_factors)
                    # print('#####################################################')
            
                    result = {}
                    result['lowest_buy_factor_std_dev'] = lowest_buy_factor_stats['std_dev']
                    result['lowest_buy_factor_min'] = lowest_buy_factor_stats['min']
                    result['highest_sale_factor_std_dev'] = highest_sale_factor_stats['std_dev']
                    result['highest_sale_factor_min'] = highest_sale_factor_stats['min']
                    result['look_back'] = int(lb)
                    result['optimal_buy_factor'] = lowest_buy_factor_stats['mean']
                    result['optimal_sell_factor'] = highest_sale_factor_stats['mean']
            
                    optimization_factors_path = '/home/ec2-user/environment/botfarming/Development/optimization_factors/2_' + length + '_optimal_for_' + symbol['symbol'] + '_' + str(result['look_back']) + '.pklz'
                    ut.pickle_write(optimization_factors_path, result)
コード例 #3
0
       optimal_buy_factor, optimal_sell_factor, optimal_band_factor,
       optimal_increase_factor)
 optimization_factors = {}
 optimization_factors['look_back'] = optimizing
 optimization_factors['optimal_buy_factor'] = optimal_buy_factor
 optimization_factors['optimal_sell_factor'] = optimal_sell_factor
 optimization_factors[
     'optimal_increase_factor'] = optimal_increase_factor
 optimization_factors['optimal_band_factor'] = optimal_band_factor
 optimization_factors[
     'optimal_minutes_until_sale'] = optimal_minutes_until_sale
 optimization_factors['gain'] = best_gain
 optimization_factors['wins'] = best_wins
 optimization_factors['losses'] = best_losses
 ut.pickle_write(
     '/home/ec2-user/environment/botfarming/Development/optimization_factors/'
     + length + '_optimal_for_' + symbol['symbol'] + '_' +
     str(optimizing) + '.pklz', optimization_factors)
 print(
     '###################################################################'
 )
 print(
     '###################################################################'
 )
 print(
     '###################################################################'
 )
 print(
     '###################################################################'
 )
 print(
     '###################################################################'
コード例 #4
0
ファイル: utility.py プロジェクト: nelsonriley/botfarming
def run_optimizer(length, minutes, minutes_until_sale):

    if length == '1m':
        data_length_multiplier = 360 # 6 hours      # 3x as long, but 12 sections
    if length == '5m':
        data_length_multiplier = 60*24*2/5 # 2 days
    if length == '15m':
        data_length_multiplier = 60*24*7/15 # 1 wk
    if length == '30m':
        data_length_multiplier = 60*24*14/30 # 2 wks
    if length == '1h':
        data_length_multiplier = 60*24*14/60 # 2 wks
    if length == '2h':
        data_length_multiplier = 60*24*30/120 # 1 month
    if length == '6h':
        data_length_multiplier = 60*24*45/360 # 1.5 months
    if length == '12h':
        data_length_multiplier = 60*24*90/720 # 3 months
    if length == '1d':
        data_length_multiplier = 60*24*120/1440 # 4 months
    
    while True:
    
        print('starting..')
        
        ################################################################################ RUN OPTIMIZER
        
        symbols = ut.pickle_read('/home/ec2-user/environment/botfarming/Development/3_binance_btc_symbols.pklz')
        
        symbols_trimmed = {}
        total_btc_coins = 0
        for s in symbols:
            symbol = symbols[s]
            if float(symbol['24hourVolume']) > 300:
                total_btc_coins += 1
                symbols_trimmed[s] = symbol
        print('total symbols', total_btc_coins)
        
        symbols_started = 0
        for s in symbols_trimmed:
            symbols_started += 1
            print('symbols_started', symbols_started)
            
            #get data in right format for save function (could fix this)
            symbol = symbols_trimmed[s]
            symbols_trimmed_one = {}
            for s_one in symbols:
                symbol_one = symbols[s_one]
                if symbol_one['symbol'] == symbol['symbol']:
                    symbols_trimmed_one[s] = symbol_one
            
            # 777
            optimizing_array= [1,3,5,7,9,11,13,15]
            end_time = int(time.time())
            results = get_optimization_factors(optimizing_array, data_length_multiplier, end_time, symbol, symbols_trimmed_one, length, minutes, minutes_until_sale)
            
            for i, result in enumerate(results):
                optimization_factors_path = '/home/ec2-user/environment/botfarming/Development/optimization_factors/1_' + length + '_optimal_for_' + symbol['symbol'] + '_' + str(result['look_back']) + '.pklz'
              
                if result['lowest_buy_factor'] != 1:
                    ut.pickle_write(optimization_factors_path, result)
                    print('###################################################################')
                    print('###################################################################')
                    print('######### LOOK_BACK', result['look_back'], '###########', symbol['symbol'])
                    print('lowest_buy_factor', result['lowest_buy_factor'])
                    print('highest_sale_factor', result['highest_sale_factor'])
                else:
                    ut.pickle_write(optimization_factors_path, False)

        # end optimization cycle, sleep
        if length == '1d':
            time.sleep(4*60*60)
        if length == '12h':
            time.sleep(3*60*60)
        if length == '6h':
            time.sleep(2*60*60)
        if length == '2h':
            time.sleep(1*60*60)
        if length == '1h':
            time.sleep(30*60)
        if length == '30m':
            time.sleep(20*60)
コード例 #5
0
            max_trades_allowed = 5
            max_std_increase = 1
        elif length == '6h':
            max_trades_allowed = 1
            max_std_increase = 1
        elif length == '12h':
            max_trades_allowed = 1
            max_std_increase = 1
        elif length == '1d':
            max_trades_allowed = 1
            max_std_increase = 1

        indicator_trades = ut.pickle_read(
            '/home/ec2-user/environment/botfarming/Development/variables/indicator_trades_'
            + length)

        std_dev_increase_factor = max(
            0,
            round((float(max_trades_allowed) - float(len(indicator_trades))) *
                  max_std_increase / float(max_trades_allowed), 1))

        #std_dev_increase_factor = 0

        ut.pickle_write(
            '/home/ec2-user/environment/botfarming/Development/variables/std_dev_increase_factor_'
            + length, std_dev_increase_factor)

        print('std_dev_increase_factor_' + length, std_dev_increase_factor,
              ut.get_time())

    time.sleep(30)