def process_socket_pushes_tickers(msg):
    # close and restart the socket, if socket can't reconnect itself
    if 'e' in msg and msg['e'] == 'error':
        print('restarting socket in process_socket_pushes_tickers()')
        bm.close()
        conn_key = bm.start_multiplex_socket(socket_list, process_socket_pushes_tickers)
        bm.start()
    else:
        if 'stream' in msg and 'data' in msg:
            s = msg['stream'].split('@')[0].upper()
            ticker_path = '/home/ec2-user/environment/botfarming/Development/recent_tickers/'+s+'.pklz'
            current_price = float(msg['data']['c'])
            # ut.pickle_write(ticker_path, msg['data'])
            ut.pickle_write(ticker_path, current_price)

            if s == 'ETHBTC' and time.localtime().tm_sec == 0:
                current_price = float(msg['data']['c'])
                print('STILL ALIVE process_socket_pushes_tickers()', s, current_price, ut.get_time())
        else:
            print('ERROR: unexpected socket response in process_socket_pushes_tickers(), printing msg so we know what is going on')
            pprint(msg)
if save_24hr_drop_data:
    print('start save to disk max 1min drop for all symbols', ut.get_time())
    for s in symbols_filtered:
        symbol = symbols_filtered[s]

        if do_print:
            print('------------------------------', s,
                  '-----------------------------')

        symbol_candles_path = '/home/ec2-user/environment/botfarming/Development/binance_training_data/' + day_folder + '/' + s + '_data_' + str(
            minutes) + 'm.pklz'
        candles = ut.pickle_read(symbol_candles_path)

        if candles == False:
            print('ERROR', s, 'symbol_candles not found @',
                  symbol_candles_path)
        else:
            outlier_drops = ut2.get_outlier_drops(candles, symbol,
                                                  future_candles_length,
                                                  drops_to_collect)
            drop_to_save = {
                'biggest_drop_percent': outlier_drops[-1]['drop_percent'],
                'best_gain_percent': outlier_drops[-1]['best_gain_percent']
            }

            symbol_24hr_drop_path = '/home/ec2-user/environment/botfarming/Development/binance_24hr_1min_drop/24hr_1min_drops_by_symbol/' + s + '.pklz'
            ut.pickle_write(
                symbol_24hr_drop_path, drop_to_save,
                'ERROR could not save 24hr 1min drop data for ' + s)

print('done @', ut.get_time())
 )
 print('results for', optimizing,
       'optimal buy, optimal sell, optimal band,',
       optimal_buy_factor, optimal_sell_factor, optimal_band_factor)
 print('optimal minutes, optimal minutes 2',
       optimal_minutes_until_sale, optimal_minutes_until_sale_2)
 print('optimal sell 2, optimal sell 3', optimal_sell_factor_2,
       optimal_sell_factor_3)
 optimization_factors = [
     optimizing, optimal_buy_factor, optimal_sell_factor,
     optimal_sell_factor_2, optimal_sell_factor_3,
     optimal_minutes_until_sale, optimal_minutes_until_sale_2,
     optimal_band_factor, True, best_gain, best_wins, best_losses
 ]
 ut.pickle_write(
     '/home/ec2-user/environment/botfarming/Development/optimization_factors/optimal_for_'
     + symbol['symbol'] + '_' + str(optimizing) + '.pklz',
     optimization_factors)
 print(
     '###################################################################'
 )
 print(
     '###################################################################'
 )
 print(
     '###################################################################'
 )
 print(
     '###################################################################'
 )
 print(
     '###################################################################'
Ejemplo n.º 4
0
import requests

# save symbol list daily since API sometimes fail when getting live
symbol_data = requests.get(
    "https://api.binance.com/api/v1/exchangeInfo").json()
ticker_data = requests.get("https://api.binance.com/api/v1/ticker/24hr").json()

symbols_for_save = {}
for symbol in symbol_data['symbols']:
    if symbol['quoteAsset'] == 'BTC':
        symbols_for_save[symbol['symbol']] = symbol
for symbol in ticker_data:
    if 'BTC' in symbol['symbol'] and not 'BTC' in symbol['symbol'][:3]:
        symbols_for_save[
            symbol['symbol']]['24hourVolume'] = symbol['quoteVolume']
        symbols_for_save[symbol['symbol']]['24priceChangePercent'] = symbol[
            'priceChangePercent']

print('---------------ETHBTC')
pprint(symbols_for_save['ETHBTC'])
print('---------------ETHBTC')

print('btc symbols found:', len(symbols_for_save))
ut.pickle_write(
    '/home/ec2-user/environment/botfarming/Development/binance_btc_symbols.pklz',
    symbols_for_save)

symbols_saved = ut.pickle_read(
    '/home/ec2-user/environment/botfarming/Development/binance_btc_symbols.pklz'
)
print('btc symbols saved:', len(symbols_saved))
Ejemplo n.º 5
0
api_key = '41EwcPBxLxrwAw4a4W2cMRpXiQwaJ9Vibxt31pOWmWq8Hm3ZX2CBnJ80sIRJtbsI'
api_secret = 'pnHoASmoe36q54DZOKsUujQqo4n5Ju25t5G0kBaioZZgGDOQPEHqgDDPA6s5dUiB'
client = Client(api_key, api_secret)
global bm
bm = BinanceSocketManager(client)

# limit symbols by 24hr volume
min_volume = 450
ut.update_symbol_list()
symbol_path = '/home/ec2-user/environment/botfarming/Development/binance_btc_symbols.pklz'
symbols = ut.pickle_read(symbol_path)
total_btc_coins = 0
symbols_trimmed = {}
global socket_list
socket_list = []
for s in symbols:
    symbol = symbols[s]
    if float(symbol['24hourVolume']) > min_volume:
        total_btc_coins += 1
        symbols_trimmed[s] = symbol
        socket_list.append(s.lower() + '@depth20')
        ut.pickle_write(
            '/home/ec2-user/environment/botfarming/Development/recent_order_books/'
            + s + '.pklz', False)

print('symbols with volume > ', min_volume, '=', len(socket_list))

# start order_book web socket > call back saves most recent data to disk
conn_key = bm.start_multiplex_socket(socket_list, ut.buy_coin_socket)
bm.start()
Ejemplo n.º 6
0
                                    print('getting one minute data',
                                          symbol['symbol'])
                                    url = 'https://api.binance.com/api/v1/klines?symbol=' + symbol[
                                        'symbol'] + '&interval=1m&startTime=' + str(
                                            start_time_period
                                        ) + '&endTime=' + str(end_time_period)
                                    data_for_sale = requests.get(url).json()

                                    # watch for too many API requests
                                    if isinstance(data_for_sale, dict):
                                        print('ERROR... API Failed')
                                        print(url)
                                        pprint(data_for_sale)
                                        sys.exit()
                                    ut.pickle_write(
                                        sale_data_path, data_for_sale,
                                        'trying to save data for sale')

                                for index_for_sale in range(0, minutes + 1):
                                    if float(data_for_sale[index_for_sale]
                                             [3]) < buy_price:
                                        break

                                if index_for_sale == minutes:
                                    print(
                                        'should have found lower price earlier some wierd error'
                                    )

                                if len(data_for_sale) < 60:
                                    continue