get_orderbook

Hello, tell me: how to get data from the order book.
My question is about how to specify the timestamp .
When I use the command :
##########################
url=“https://api.binance.com/api/v3/depth
headers = {‘symbol’: ‘BTCUSDT’, ‘limit’: 5000}
response = requests.get(url, headers)
tickers=response.json()
##########################
i see in tickers[‘lastUpdateId’] timestamp=18985208561 , now, when I translate this timestamp into a standard date I get 1970-08-08 20:40:08.561000 .
could someone tell me how to specify a specific timestamp (current date) in the request :
url=“https://api.binance.com/api/v3/depth
headers = {‘symbol’: ‘BTCUSDT’, ‘limit’: 5000}
response = requests.get(url, headers)

import time
uri = "https://api.binance.com"

def get_timestamp_offset():
    url = "{}/api/v3/time".format(uri)
    payload = {}
    headers = {"Content-Type": "application/json"}
    response = requests.request("GET", url, headers=headers, data=payload)
    result = json.loads(response.text)["serverTime"] - int(time.time() * 1000)

    return result

timestamp = int(time.time() * 1000 + get_timestamp_offset())

@solipsist01.
I must have formulated my question incorrectly.
But the answer that was given to my question is not about that.

Once again , when I make a request to the binance server = give me an order book for eg bitcoin , I want to specify a timestamp ( this timestamp is the current time in milliseconds ) .
I ask you to tell me how to specify a timestamp in the url request or the client

Historical order book data is not available via the API.

@solipsist01 :
why do I need the bid book data for 1970? I want current order book data, I’m sure you wouldn’t want 1970 data either.
Therefore, I ask for an answer on how to form a request to the exchange server in order to get the current order book data

You can request the current order book state from the Market Order Book endpoint
https://binance-docs.github.io/apidocs/spot/en/#order-book

Hi Romul!

To get the current data, i recommend subscribing to websocket stream or better a depth cache. Thats the fastest and cheapest way (used weight).

If you want to get historical data i do it with unicorn-binance-rest-api:


from unicorn_binance_rest_api.manager import BinanceRestApiManager

api_key = "*"

api_secret = "*"

ubra = BinanceRestApiManager(api_key, api_secret)

# Retrieve 1-minute klines for the last day so far

klines_1m = ubra.get_historical_klines("BNBBTC", ubra.KLINE_INTERVAL_1MINUTE, "1 day ago UTC")

print(f"klines_1m:\r\n{klines_1m}")

# Retrieve 30-minute klines for the last month of 2021

klines_30m = ubra.get_historical_klines("BNBBTC", "30m", "1 Dec, 2021", "1 Jan, 2022")

print(f"klines_30m:\r\n{klines_30m}")

# Retrieve weekly klines since they are listed

klines_1w = ubra.get_historical_klines("BNBBTC", "1w", "1 Jan, 2017")

print(f"klines_1w:\r\n{klines_1w}")