Is there a way to get LTP from marketfeed into a synchronous function

Is there a way to get LTP into a synchronous function - with or without marketfeed.
Have tried several codes, none work.
Only the print message printing the LTP inside the on_message function works.
Print message trying to print global LTP variable in a synchronous function fails.

Can you help me crack this.

from dhanhq import marketfeed
from dhanhq import dhanhq
from json import loads
import pandas as pd
import pandas.core.series as Series
import time

client_id = “12345678”
access_token = “Access _Code”
dhan = dhanhq(client_id,access_token)

ltp_value = None # Initialize a variable to store the LTP

instruments = [(5, “428946”)]
subscription_code = marketfeed.Ticker

async def on_connect(instance):
print(“Connected to websocket”)

async def on_message(instance, message):
global ltp_value
if ‘LTP’ in message:
ltp_value = float(message[‘LTP’])
print(“Current price (on_message):”, ltp_value)

def get_ltp(): # Synchronous function to retrieve LTP
return ltp_value # Return the stored LTP value in the global variable

ltp = get_ltp()
if ltp is not None:
print(“Current price (synchronous):”, ltp)
else:
print(“LTP not yet received”)

print(“Subscription code :”,subscription_code)

feed = marketfeed.DhanFeed(client_id,
access_token,
instruments,
subscription_code,
on_connect=on_connect,
on_message=on_message)

feed.run_forever()

output:
Current price (on_message): 62.9
Current price (on_message): 62.9
Current price (on_message): 63.1
Current price (on_message): 63.0
Current price (on_message): 63.0

i am getting the error
if “LTP” in message:
^^^^^^^^^^^^^^^^
TypeError: argument of type ‘NoneType’ is not iterable

I have solved this.
You can use LTP in the synchronous function PrintingLTP()