Shoonya-Dev / ShoonyaApi-py

144 stars 133 forks source link

Multi Instance of ShoonyaApiPy Class Doesnt Work. #36

Closed vijay-arwapally closed 2 years ago

vijay-arwapally commented 2 years ago

ShoonyaApiPy is not working for multiple instance. I would like to run strategies for multiple accounts of my family, they individually work, when I create individual instance for each user, websockets not working. Only any one users websocket works and other users websocket doesnt work.

Shoonya-Dev commented 2 years ago

Greetings from FINVASIA!

Thanks for your Concern.

Query has been Forwarded to Tech Team.

Shoonya-Dev commented 2 years ago

Greetings from FINVASIA!

Thanks for your Concern.

example test_product_convertion.py shows this

vijay-arwapally commented 2 years ago

@Shoonya-Dev Did you understand the issue in first place? Why are so hurry in closing the issue without proper resolution? Don't just point to something random and close the issue.

The issue is when you create multiple instances to handle multiple user accounts. What you have understood is, multiple instances for single user. Kindly read or ask questions before you close an issue.

TheCodeArtist commented 2 years ago

@vijay-arwapally while it is obvious that the communication from shoonya-dev on this repo can improve quite a lot, the same can be said about the original comment raising this issue.

when I create individual instance for each user, websockets not working.

Can you share a minimal code-snippet (hiding private info like token/keys), that someone can copy, execute, and reproduce the behavior you are observing?

Only any one users websocket works and other users websocket doesnt work.

Again, what do you mean by "works" and "doesn't work" here? Ideally share...

(many a time, what one needs is already supported, just not documented very well.)

Even though this issue is closed, i feel that if we ask descriptive, objective questions, we will get a better response soon. 🙂


@Shoonya-Dev when in doubt, instead of trying to guess what the requester might have meant, feel free to ask follow-up questions.

( Github issues aren't just there to be closed ASAP. They can be used for detailed discussions to connect with the users and improving the project too.)

vijay-arwapally commented 2 years ago

@TheCodeArtist Agreed, will detail more information next time. @Shoonya-Dev Please check the code below to understand the issue.

Below the quick code, that I could end up preparing to create the issue. This needs to be tested in live market, as the sockets wouldn't be sending any data post market.

from NorenRestApiPy.NorenApi import NorenApi,FeedType,ProductType,PriceType,BuyorSell
import time

class ShoonyaApiPy(NorenApi):
    def __init__(self):
        NorenApi.__init__(self, host='https://shoonyatrade.finvasia.com/NorenWClientTP/', websocket='wss://shoonyatrade.finvasia.com/NorenWSTP/', eodhost='https://shoonya.finvasia.com/chartApi/getdata/')

creds_user1 = {
    'user' : 'XXX',
    'pwd' : 'XXX',
    'factor2' : 'XXX',
    'vc' : 'XXX',
    'apikey' : 'XXX',
    'imei' : 'XXX',
}
creds_user2 = {
    'user' : 'XXX',
    'pwd' : 'XXX',
    'factor2' : 'XXX',
    'vc' : 'XXX',
    'apikey' : 'XXX',
    'imei' : 'XXX',
}
#Create two instances to handle multiple accounts.
user1 = ShoonyaApiPy()
user2 = ShoonyaApiPy()

#Login multiple accounts.
user1.login(userid = creds_user1['user'], password = creds_user1['pwd'], 
            twoFA=creds_user1['factor2'], vendor_code=creds_user1['vc'], 
            api_secret=creds_user1['apikey'], imei=creds_user1['imei'])
user2.login(userid = creds_user2['user'], password = creds_user2['pwd'], 
            twoFA=creds_user2['factor2'], vendor_code=creds_user2['vc'], 
            api_secret=creds_user2['apikey'], imei=creds_user2['imei'])

#Individual Websocket callbacks for each account.
def user1_socket_order_update(self,message):
    print("OrderInfo Received for User1:" + message)
def user1_socket_quote_update(self,message):
    print("Quote Received for User1:" + message)
def user1_socket_order_update(self,message):
    print("OrderUpdate Received for User1:" + message)

def user2_socket_order_update(self,message):
    print("OrderInfo Received for User2:" + message)
def user2_socket_quote_update(self,message):
    print("Quote Received for User2:" + message)
def user2_socket_order_update(self,message):
    print("OrderUpdate Received for User1:" + message)
#Start the websocket and subscribe to some live feed.
user1.start_websocket(order_update_callback=user1_socket_order_update, \
                      subscribe_callback=user1_socket_quote_update, \
                      order_update_callback = user1_socket_order_update)
time.sleep(5)
user1.subscribe('NSE|26000')

user2.start_websocket(order_update_callback=user2_socket_order_update, \
                      subscribe_callback=user2_socket_quote_update, \
                      order_update_callback = user1_socket_order_update)
time.sleep(5)
user2.subscribe('NSE|26000')

print("Both accounts are initialized, now the quotes/order updates should come for both users.")
while True:
    time.sleep(10)
vijay-arwapally commented 2 years ago

@TheCodeArtist No clue if you are part of Shoonya team, can you please ask them to respond on this issue?

TheCodeArtist commented 2 years ago

@TheCodeArtist No clue if you are part of Shoonya team

No i am NOT affiliated with Shoonya, nor Finvasia. 🙂

can you please ask them to respond on this issue?

Based on what i have seen so far, i wouldn't hold my breath waiting for @Shoonya-Dev to respond here immediately. As you would have observed over the past few weeks, the typical response-time on this repo is currently about 2days to a week.

If we need faster response, we might have better luck in the Skype Group or with Finvasia Customer-care. We can raise an issue with all the details here and steps to reproduce, and share the link to the issue with Finvasia customer-care and Skype group.

PhillipCapital-India commented 2 years ago

separate test_multiple_sessions.py is added to explain better (earlier it was part of test_product_convertion.py)

TheCodeArtist commented 2 years ago

Also, for future reference, can the repo's README.md be updated with the details of the set_session() API ? https://github.com/Shoonya-Dev/ShoonyaApi-py/blob/457040409e5feeef8373a08a6e495df80c1a8bee/tests/test_multiple_sessions.py#L24.