Protobuf installation for linux system

Hello ketan sir,

@Ketan

I am switching from windows to linux based distro. So for that I have to install protobuf and compile files. Please provide me steps regarding the installation. No instructions are given on github page for linux users.

@Daljit_singh

If you use streamer functions you would not need to install protobuf and complie files
For more information about the streamer functions and usage, refer to the SDK documentation:

Upstox Market Stream Feed WebSocket Setup on Linux

If you are switching from Windows to a Linux-based distribution, here are the steps to install Protocol Buffers (Protobuf) and set up the Upstox Market Stream Feed WebSocket client.


1. Install Python 3.8+ (if not already installed)

Check your Python version:

python3 --version

If Python is not installed, you can install it using your package manager:

  • Ubuntu/Debian:
    sudo apt update && sudo apt install python3 python3-pip

  • Fedora:
    sudo dnf install python3 python3-pip


2. Install required Python packages

Install the dependencies using pip:

pip3 install websockets asyncio protobuf requests


3. Install Protocol Buffers Compiler (protoc)

  1. Go to the Google Protocol Buffers GitHub releases page and download the latest Linux protoc-<version>-linux-x86_64.zip.
  2. Extract the ZIP file:

unzip protoc-<version>-linux-x86_64.zip -d protoc

  1. Add the bin directory to your system PATH:

export PATH=$PATH:/path/to/protoc/bin

  1. Verify the installation:

protoc --version
It should print the installed protoc version.


4. Generate Python classes from .proto files

  1. Navigate to the folder containing your .proto files.
  2. Run the following command to generate Python classes:

protoc --python_out=. *.proto

This will generate .py files for each .proto file.

  1. In your Python code, import the generated classes:

import MarketDataFeedV3_pb2 as pb
(Assuming you have MarketDataFeedV3.proto which generates MarketDataFeedV3_pb2.py.)


5. Configure your Upstox API access token

Open your Python script and replace the placeholder with your actual access token:

access_token = 'ACCESS_TOKEN'


6. Run the WebSocket client

Navigate to the script directory and run:

python3 websocket_client.py

Replace websocket_client.py with your actual script filename.


Following these steps on Linux will set up your environment to connect to the Upstox Market Stream Feed, fetch live market data, and decode protobuf messages to JSON format.

Thanks!

Thank you ketan sir…