py5paisa icon indicating copy to clipboard operation
py5paisa copied to clipboard

Server Response Time Issue with Scrip Master Contract Download

Open marketcalls opened this issue 9 months ago • 1 comments

  • 5paisa Python SDK version: Used API
  • Python version: 3.11.7
  • Operating System: Windows OS

Description

I am experiencing a significant delay in server response time when downloading the Master contract CSV file from the 5Paisa API. Below is the Python code I am using to measure the response time and download the file:

What I Did

Python Code Used to Measure the Response Time

import requests
import time
from tqdm import tqdm

# URL of the CSV file
url = "https://openapi.5paisa.com/VendorsAPI/Service1.svc/ScripMaster/segment/all"

# Measure time taken to get server response
start_time = time.time()
response = requests.get(url, stream=True)
response_time = time.time() - start_time

print(f"Time taken for server to respond: {response_time:.2f} seconds")

# Check if the request was successful
if response.status_code == 200:
    # Get the total file size
    total_size = int(response.headers.get('content-length', 0))
    block_size = 1024  # 1 Kilobyte
    t = tqdm(total=total_size, unit='iB', unit_scale=True)

    download_start_time = time.time()
    with open('scrip_master.csv', 'wb') as file:
        for data in response.iter_content(block_size):
            t.update(len(data))
            file.write(data)
    t.close()
    download_time = time.time() - download_start_time

    if total_size != 0 and t.n != total_size:
        print("Error occurred during download.")
    else:
        print(f"CSV file downloaded successfully.")
        print(f"Time taken to download the file: {download_time:.2f} seconds")
else:
    print(f"Failed to download CSV file. Status code: {response.status_code}")

Output

Time taken for server to respond: 47.92 seconds
28.0MiB [00:02, 10.5MiB/s]
CSV file downloaded successfully.
Time taken to download the file: 2.66 seconds

Issue:

The response time from the server is approximately 47.92 seconds, which is considerably high. However, once the response is received, the download speed is acceptable, taking around 2.66 seconds to download the 28.0 MiB file.

Request:

Could you please look into this issue and help improve the server response time for downloading the Master contract CSV file? This delay significantly affects the performance of our applications relying on your API.

marketcalls avatar May 21 '24 06:05 marketcalls