Print(client.exchange + " " + symbol + " : Collected " + str(len(data)) + " initial data from "+ str(ms_to_dt_local(data)) +" to " + str(ms_to_dt_local(data)))įromDate = int(datetime.strptime('', '%Y-%m-%d').timestamp() * 1000) Return datetime.utcfromtimestamp(ms / 1000)ĭf = pd.DataFrame(data, columns=)ĭf = df.apply(lambda x: ms_to_dt_local(x))ĭf = df.dt.strftime("%d/%m/%Y")ĭf = df.dt.strftime("%H:%M:%S")Ĭolumn_names = ĭef GetHistoricalData(client, symbol, start_time, end_time, limit=1500):ĭata = client.get_historical_data(symbol, start_time=start_time, end_time=end_time, limit=limit) Raw_candles = self._make_request(endpoint, params)Ĭandles.append((float(c), float(c), float(c), float(c), float(c), float(c),)) Symbols = for x in data]ĭef get_historical_data(self, symbol: str, interval: Optional = "1m", start_time: Optional = None, end_time: Optional = None, limit: Optional = 1500):Įndpoint = "/fapi/v1/klines" if self.futures else "/api/v3/klines" Print("Error while making request to %s: %s (status code = %s)",Įndpoint, response.json(), response.status_code)Įndpoint = "/fapi/v1/exchangeInfo" if self.futures else "/api/v3/exchangeInfo"ĭata = self._make_request(endpoint, params) Print("Connection error while making request to %s: %s", endpoint, e) Response = requests.get(self._base_url + endpoint, params=query_parameters) (Please note this method is cut out of a class I have, so you may get rid of all of the self-s), and you need to have your client set up before byĭef _make_request(self, endpoint: str, query_parameters: Dict): Self.df.set_index('dateTime', inplace=True) Self.df.dateTime = pd.to_datetime(self.df.dateTime, unit='ms').dt.strftime(Constants.DateTimeFormat) # as timestamp is returned in ms, let us convert this back to proper timestamps. Self.df = pd.DataFrame(self.candle, columns=) # Create a dataframe to label all the columns returned by binance so we work with them later. Self.candle = _historical_klines("BNBBTC", Client.KLINE_INTERVAL_1MINUTE, str(self.sinceThisDate), str(self.untilThisDate)) # Execute the query from binance - timestamps must be converted to strings ! Self.sinceThisDate = self.untilThisDate - datetime.timedelta(days = self.howLong) # Calculate the timestamps for the binance api function I am using this out of the binance documentation : import os 'taker_base_vol', 'taker_quote_vol', 'ignore']ĭf.index = Url = root_url + '?symbol=' + symbol + '&interval=' + intervalĭata = json.loads(requests.get(url).text) So I share with you the code I'm using (copied from the steemit code and modified a little bit)įrequency = input("Please enter the frequency (1m/5m/30m/./1h/6h/1d/ : ")ĭef get_bars(symbol, interval=frequency): 2020, or I want the DAILY PRICES from the first day trading for any crypto. I've been using this script to get the prices from some cryptocurrencies using Binance API and this problem is that with this script I cannot control the date range: for example, I want to choose the period range between Dec.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |