print('Retrieving market data for', pair)
    hist_symbol = pair
    filename = f"hist_{pair}.csv"
    timestampStr = dateTimeObj.strftime("%d-%b-%Y (%H:%M)")
    history_settings = f"Retrieved market data for {hist_symbol} at intervals of {hist_interval} as at {timestampStr}"
    with open(filename, 'w', newline='\n') as myfile:
        wr = csv.writer(myfile)
        wr.writerow(
            [history_settings]
        )  #[] wraps string in a list so it doesn't delimit the string as an array of characters
        wr.writerow(history_header)
    i = 1
    #iterate through history time blocks and append to file
    while hist_end < 1576130400000:
        print(hist_symbol, hist_interval, hist_start, hist_end,
              '1576130400000')
        res = bot.klines(symbol=hist_symbol,
                         interval=hist_interval,
                         startTime=hist_start,
                         endTime=hist_end,
                         limit='1000')
        with open(filename, 'a', newline='\n') as myfile:
            wr = csv.writer(myfile)
            wr.writerows(res)
        hist_start += hist_step
        hist_end += hist_step
        i += 1

#Tell user it is done
print('Market data saved in hist.csv')
Example #2
0
iCountPair = 0
lTicker = []
for lEI in lExchangeInfo['symbols']:
    # print(lEI)
    # print(lEI['status'])
    if (lEI['status'] == 'TRADING') and ((lEI['baseAsset'] == sBase) or
                                         (lEI['quoteAsset'] == sBase)):
        lTicker24h = bot.ticker24hr(symbol=lEI['symbol'])
        if lEI['baseAsset'] == sBase:
            lPairs.append([
                lEI['symbol'], lEI['baseAsset'], lEI['quoteAsset'],
                float(lTicker24h['volume'])
            ])
        else:
            lPairs.append([
                lEI['symbol'], lEI['baseAsset'], lEI['quoteAsset'],
                float(lTicker24h['quoteVolume'])
            ])
lPairs.sort(key=lambda ii: ii[3], reverse=True)

for lPair in lPairs:
    iCountPair += 1
    print(
        f'№ {iCountPair:03d} Пара: {lPair[0]:10s} Оборот за 24h: {lPair[3]: 15.2f}{sBase}'
    )
    #  данные с биржи по свечам
    slKLines = bot.klines(symbol=lPair[0], interval=sInterval, limit=iLimit)
    # вычисляем !!!
    bFunc.estimationPair(slKLines, lPair[0], iLimit, sInterval, iCountPrint,
                         iCountTrade)
Example #3
0
history_header = [
    'Open time (milliseconds)', 'Open', 'High', 'Low', 'Close', 'Volume',
    'Close time (milliseconds)', 'Quote Asset Volume', '# Trades',
    'Taker buy base asset volume', 'Taker buy quote asset volume', 'Ignore'
]
bot = Binance(API_KEY, API_SECRET)
hist_symbol = 'BTCUSDT'
hist_interval = '1m'

#Get the data
#Iterate pairs

#Setup new history file
print('Retrieving market data for', hist_symbol)
filename = f"./logs/hist_{hist_symbol}_today.csv"
history_settings = f"Retrieved market data for {hist_symbol} at intervals of {hist_interval}"
with open(filename, 'w', newline='\n') as myfile:
    wr = csv.writer(myfile)
    wr.writerow(
        [history_settings]
    )  #[] wraps string in a list so it doesn't delimit the string as an array of characters
    wr.writerow(history_header)
    res = bot.klines(symbol=hist_symbol, interval=hist_interval, limit='1000')
    with open(filename, 'a', newline='\n') as myfile:
        wr = csv.writer(myfile)
        wr.writerows(res)

#Tell user it is done
print(f'Market data saved in ./logs/hist_{hist_symbol}_today.csv')