algo2t / alphatrade

Python APIs for SAS Online Alpha Trade Web platform for creating algo trading using python
https://algo2t.github.io/alphatrade
MIT License
44 stars 23 forks source link

Help to code Nifty Shortstrangle using Nifty spot price #14

Closed alistair7682 closed 2 years ago

alistair7682 commented 2 years ago

Can anyone help assit to code nifty short strangle (current week expiry) using nifty spot at particular time (say 9:30). also 2 exit criterior place a SL-Limit order for both legs at 30% of premium sold Exit at loss of 3000

algo2t commented 2 years ago

You might get some help on telegram channel Algo Trade Analysis (Python) , Also I recommend you to check the source for 5Paisa API on github, implement similar stuff for yourself.

ronaldpaul commented 2 years ago

Hi @algo2t, I have one query related to intraday strategies. Say, I have placed two SL-M orders in pending status. I would like to modify the SM-M price of one leg when the other leg gets triggered. So what I have done is I just opened a web socket stream and fetching the order status of the pending SL-M orders so that if any one gets moved to 'Complete' status, I can modify the price of the another leg. However, the web socket stream doesn't appear to be running for 9:15 to 3:30. Sometimes the server says too many requests even after hitting it one every 2 minutes. Sometimes it says 'Request unauthorized - error'. So do you think there are any restrictions to fetch the real-time price? Or won't the web socket stream work properly? In-fact I am just fetching only one scrip details though you had mentioned we can do it update 250 scrips. Only thing is I run it from 9:15 to 3:30 so that I can actively monitor the order status in loop and modify the price accordingly. Any help on this will be greatly appreciated. Thanks.

raja-vignesh commented 2 years ago

Hi @ronaldpaul, just a question, are you facing this WebSocket issue in cloud server or local machine?

ronaldpaul commented 2 years ago

I face this issue from Cloud server. Digital Ocean cloud. I haven't tried running it for whole day from my local machine so far. Maybe I can give it a try. However, from the cloud, I have been facing this issue.

image

In the above image if you see, the SL-M orders were placed and then I am checking every 2 mins. once whether any one of 2 SL-M orders status has changed from pending to complete. But when I do it by getting the status, you can see the error being thrown. Initially when I was running the stream every second it threw 'too many requests' error. Now when I hit the server via stream only every 2 minutes once after a rest through sleep() method, still I see 'Request Unauthorized' error.

raja-vignesh commented 2 years ago

Ok. I have deployed similar logic in AWS EC2 for the past two weeks, I haven't faced this issue. But it's still in the testing phase. I will keep you posted. BTW, it doesn't seem like a WebSocket issue because the session is getting closed here I think. In one other closed issue, the author has mentioned don't poll frequently as SAS is not supporting that. I am listening to the ltp in WebSocket and then modifying the order if required.

ronaldpaul commented 2 years ago

That's a good idea Vignesh. I will also built the condition based on ltp instead of checking the status every time. Hopefully it should resolve the issue. Thanks.

ronaldpaul commented 2 years ago

Hi, @raja-vignesh . Do you have any idea how I can exit based on MTM without polling frequently? Because by getting LTP alone will not help in closing based on MTM right? For that we can to keep on querying MTM right?

raja-vignesh commented 2 years ago

Hi @ronaldpaul, Are you working on Combined SL or individual leg SL? If Individual leg, Assuming short straddle

  1. After the sell order is completed and SL-M is placed, subscribe to the prices
  2. compare SL price and the LTP at every specific interval(say 15 or 30 secs)
  3. If the LTP > SL price, check the order status of the SL leg. If the status is 'complete' then modify the other leg SL price. Hope this helps!
    BTW, use SL-L considering the current slippages.
algo2t commented 2 years ago

You might get some help on telegram channel Algo Trade Analysis (Python) , Also I recommend you to check the source for 5Paisa API on github, implement similar stuff for yourself.

Hi @algo2t, the Web socket is not working anymore and the framework is of no use. Please check and rectify. Thanks for your effort.

Can you specify why framework is of no use just because websocket is not working?

algo2t commented 2 years ago

It is working perfectly with the given examples in the repository. So closing the issue. Whoever is facing issue is either not aware how to use it or there might be a technical glitch at SAS Online end. I checked this today on NATURALGAS OCT FUT and streaming is working great.

Just a request before opening issue read the documentation completely and properly and also please learn python to at least intermediate level.

Please create separate issue if you really want good help from my end. Don't hijack others queries.

ronaldpaul commented 2 years ago

Hi @algo2t , I did not hijack others' queries. If you check it, I just posted the query related to short straddle execution as @alistair7682 posted the issue which is related to same strategy. So I didn't wanted to open new issue unnecessarily. Moreover, I posted the web socket issue recently as it was not working for the past couple of weeks and I couldn't use the framework anymore for trades. That is the reason for specifying that the framework rendered of no use as I couldn't use it anymore for execution of traders and web socket for monitoring the pricing and executing conditional trades. Just generically placing trades was possible. Otherwise you have done a great job which has really helped many people like us to automate the trades in a discounted brokerage service to save costs. Thanks for your hard work and effort.