tqsdk-python Tianqin Quantitative Python Development Kit | Foreign Exchange EA Download- MT4/MT5 Resources
Open source Python quantitative trading framework. Quantitative trading programs can be implemented with a small amount of code, and it also supports functions such as historical data, real-time data, strategy backtesting, real trading, and graphical interface display. However, the free version only provides all futures, commodities/financial options and real-time quotes of SSE 50, CSI 300 and CSI 500. The paid version supports more types and more stable services. python from tqsdk import TqApi, TqAuth, TqAccount, TargetPosTask api = TqApi(TqAccount("Hhaitong Futures", "4003242", "123456"), auth=TqAuth("Xinyi Account", "Account Password")) # Create a TqApi instance and specify the trading account q_1910 = api.get_quote("SHFE.rb1910") # Subscribe to recent month contract quotes t_1910 = TargetPosTask(api, "SHFE.rb1910") # Create a near-month contract position adjustment tool q_2001 = api.get_quote("SHFE.rb2001") # Subscribe to far-month contract quotes t_2001 = TargetPosTask(api, "SHFE.rb2001") # Create a far-month contract position adjustment tool while True: api.wait_update() # Wait for data update spread = q_1910.last_price - q_2001.last_price # Calculate the price difference between the near-month contract and the far-month contract print("Current price difference:", spread) if spread > 250: print("The price difference is too high: short the near month, how far the month is") t_1910.set_target_volume(-1) # Request to adjust the 1910 contract to short 1 lot t_2001.set_target_volume(1) # It is required to adjust the 2001 contract to long 1 lot elif spread < 200: print("Spread reply: clear the position") # It is required to adjust both the 1910 and 2001 contracts to no positions t_1910.set_target_volume(0) t_2001.set_target_volume(0) ``` https://github.com/shinnytech/tqsdk-python 
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- No related recommendations