I used this code: import time from binance.client import Client from binance.enums…
- User
I used this code: import time from binance.client import Client from binance.enums import * from binance.exceptions import BinanceAPIException import pandas as pd import requests import json import numpy as np import pytz import datetime as dt
date = dt.datetime.now().strftime("%m/%d/%Y %H:%M:%S") print(date)
url = "https://api.binance.com/api/v1/time" t = time.time()*1000 r = requests.get(url) result = json.loads(r.content)
API keys and other configuration
API_KEY = '' API_SECRET = ''
client = Client(API_KEY, API_SECRET)
STOP_LOSS_PERCENTAGE = -50 TAKE_PROFIT_PERCENTAGE = 100 MAX_TRADE_QUANTITY_PERCENTAGE = 100 POSITION_SIDE_SHORT = 'SELL' POSITION_SIDE_LONG = 'BUY' symbol = 'BTCUSDT' quantity = 1 order_type = 'MARKET' leverage = 125 max_trade_quantity_percentage = 1
client = Client(API_KEY, API_SECRET)
def getminutedata(symbol, interval, lookback): frame = pd.DataFrame(client.get_historical_klines(symbol, interval, lookback+'min ago UTC')) frame = frame.iloc[:60,:6] frame.columns = ['Time','Open','High','Low','Close','Volume'] frame = frame.set_index('Time') today = dt.date.today() frame.index = pd.to_datetime(frame.index, unit='ms').tz_localize('UTC').tz_convert('Etc/GMT+3').strftime(f"{today} %H:%M:%S") frame = frame.astype(float) return frame df = getminutedata('BTCUSDT', '1m', '44640') def signal_generator(df): open = df.Open.iloc[-1] close = df.Close.iloc[-1] previous_open = df.Open.iloc[-2] previous_close = df.Close.iloc[-2]
code# Bearish pattern if (open>close and previous_open<previous_close and close<previous_open and open>=previous_close): return 'sell' # Bullish pattern elif (open<close and previous_open>previous_close and close>previous_open and open<=previous_close): return 'buy' # No clear pattern else: return ''def order_execution(symbol, signal, max_trade_quantity_percentage, leverage): signal = signal_generator(df) max_trade_quantity = None account_balance = client.futures_account_balance() usdt_balance = float([x['balance'] for x in account_balance if x['asset'] == 'USDT'][0]) max_trade_quantity = usdt_balance * max_trade_quantity_percentage/100
code - Assistant
The error message suggests that there is no attribute
get_historical_klines()in theClientobject. It also suggests a possible alternative method,get_historical_trades(). This could mean that the method name may have been changed or removed in a newer version of the library.To resolve the issue, you can either try switching to the
get_historical_trades()method or check the documentation or release notes of the library to confirm the new method name. If the method has been removed, you may need to find an alternative library or method to obtain the historical klines data. - User
Please give me right code of getminutedata
- Assistant
Here is an updated
getminutedata()function that uses theget_historical_klines()method to fetch minute data for a specified symbol, time interval, and lookback period:codedef getminutedata(symbol, interval, lookback): frame = pd.DataFrame(client.futures_historical_klines(symbol=symbol, interval=interval, start_str=lookback+' min ago UTC')) frame.columns = ['Time', 'Open', 'High', 'Low', 'Close', 'Volume', 'CloseTime', 'QuoteAssetVolume', 'NumTrades', 'TakerBuyBaseAssetVolume', 'TakerBuyQuoteAssetVolume', 'Ignore'] frame = frame[['Time','Open','High','Low','Close','Volume']] frame = frame.set_index('Time') today = dt.date.today() frame.index = pd.to_datetime(frame.index, unit='ms').tz_localize('UTC').tz_convert('Etc/GMT+3').strftime(f"{today} %H:%M:%S") frame = frame.astype(float) return frame