In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use Jupyter NoteBook IB query and transaction and the use of algorithm transactions, the article is very detailed, has a certain reference value, interested friends must read!
Most of Script_engine's operations are for the encapsulation of main_engine, similar logic, other transaction-related apps, can also be called with similar methods, really convenient, compared to the previous debugging. In fact, the algorithm transaction call is also very direct, directly into the algo setting dict can be.
Jupyter NoteBook code is not easy to paste, I rewrite here will be directly python code. After launching the tos login, it can be run directly.
In addition, the return information of IB interface adopts a medium wrapper mechanism, which is a bit similar to Spring's inversion call. It can be understood that the local return method is written by IBapi call.
from vnpy.app.script_trader import init_cli_tradingfrom vnpy.gateway.ib import IbGatewayfrom time import sleep#Connect to server setting = { "TWS address": "127.0.0.1", "TWS port": 7497, "Customer ID": 5 #Each link uses a separate link number, one IBAPI supports 32 links at the same time}engine = init_cli_trading ([IbGateway]) #Returns Script_engine example and registers gatewayengine.connect_gateway for main_engine (setting, "IB") #Link #Search funds-automatic sleep(10)print (engine.get_all_accounts(use_df = True))#Query positions print (engine.get_all_positions(use_df = True))#Subscribe Quotes from vnpy.trader.constant import Exchangefrom vnpy.trader.object import SubscribeRequest#There is a problem with using Script_engine directly from my test. There are too many IB varieties. The get_all_contracts command does not work. You need to specify the specific before you can. Use main_engine here to subscribe req1 = SubscribeRequest ("152791428",Exchange.SEHK) #Create Quotes Subscription, Tencent req2 = SubscribeRequest ("332623976",Exchange.SEHK) #Create Quotes Subscribe, Meituan req3 = SubscribeRequest ("12087792",Exchange.IDEALPRO) #Create Quotes Subscribe, Meituan engine.main_engine.subscribe (req1,"IB")engine.main_engine.subscribe (req2,"IB")engine.main_engine.subscribe (req3,"IB")#Return Quotes sleep(10)print (engine.get_all_contracts(use_df = True)) #Returns all subscribed contactprints (engine.get_contract("152791428.SEHK",use_df = True)) #Returns the contactprint of a single subscription (engine.get_ticks(["152791428.SEHK","332623976.SEHK"],use_df = True)) #return subscribed tick#delegate order, return order number from vnpy.trader.constant import OrderTypevt_orderid = engine.buy (vt_symbol = "12087792.IDEALPRO",price = 1.20, volume = 50000, order_type = OrderType.LIMIT)print(vt_order)#Query the order status according to the order number. Here, you can also use get_orders to query the order number queue sleep(10)print(engine.get_order(vt_order)) #print(engine.get_trades(vt_order, use_df= True))#Query positions again print(engine.get_all_positions(use_df = True))#Use algorithmic trading engine from vnpy.app.algo_trading import AlgoTradingAppengine.main_engine.add_app(AlgoTradingApp) #Add appAlgoInstance = engine.main_engine.get_engine("AlgoTrading")#For convenience, here directly use the returned AlgoInstance#to create the content of the algorithm transaction to be executed. This can copy the content of algo_trading_setting.json. Here, the policy is to place an order every 10 seconds within 100 seconds, and each purchase is 10000 AlgotradingDict1 = { "template_name": "TwapAlgo", "vt_symbol": "12087792.IDEALPRO", "direction": "more", "price": 1.0985, "volume": 10000.0, "time": 100, "interval": 10, "offset": "" }AlgoInstance.start_algo(setting = AlgotradingDict1)#Query positions again print(engine.get_all_positions(use_df = True)) The above is "How to use Jupyter NoteBook for IB query and trading and using algorithmic trading" All the contents of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.