Available cash on websocket tick data

soumyadeep
My strategy checks available cash on every tick before making a trade. So I have to call kite.margins("equity") on every tick to get available cash data. Many a times due to constant requests, I get two errors-
1. kiteconnect.exceptions.ClientNetworkException: Gateway connection error
2. kiteconnect.exceptions.ClientNetworkException: Gateway timed out
Is it possible to provide cash/margin available data inside tick data so that I dont have to request all the time? Do you have a solution for not getting those errors?
Thanks
  • sujith
    sujith edited August 2017
    Hi @soumyadeep,
    Once you fetch margins, it won't change unless you place an order.
    You get tick data every second and fetching margins for every tick is abusing the system. Make sure you fetch margins only when it is needed.
  • soumyadeep
    Well yes definitely not every tick but since I am trading more than 20 stocks, I need to fetch margin kind of every 5 seconds on an average. So that is a problem.. If we get margin data on tick data, that will be great. I cannot think of an alternative solution as I do not want to "abuse" it.. But my trading strategy is on a fast timescale.
  • sujith
    sujith edited August 2017
    Hi @soumyadeep,
    I am afraid it is not possible since internally there is an HTTP call to the OMS. Even if we do it on websocket, the behavior won't change.
    You need to optimize your code, it's not like you will place an order every five seconds right. You may have to change use case in such a way that margins call must be made after placing an order and not before placing an order.
    Use some kind of caching instead of fetching data every time.
  • Kailash
    @soumyadeep I concur with Sujith. It's technically not feasible for us to stream margins data over WebSockets.
Sign In or Register to comment.