Python 3.6 wrapper for TWSLink

Python 3.6 wrapper for TWSLink available

  • 32-bit .pyd and 64-bit .pyd binaries included.
  • Visual Studion 2015 solution file included (should be usable with Visual Studio 2013,2015 Express)
  • A small python test script to place a MKT order included.

 

The project included (along with binaries) can be used to build custom Python TWSLink wrappers for all future Python versions 2.x and 3.x. It depends just on what library path provided for link settings (to the 2.x lib or 3.x lib) and what include path provided for the c++/general settings. So a few clicks only, when you like to create wrappers for future Python versions on your own.

 

View sample code
# file: sample.py

# -----------------------------------------------------------------------------------------
# This file demonstrates placing MSFT MKT order with TWSLink2 for python3 (tested with 3.5)
# -----------------------------------------------------------------------------------------

import twslink2pt
import time
import sys


# ----- Object creation -----
print ("Creating twslink2")
tws = twslink2pt.TWSLink2Wrap("",1)
# print ("    Created twslink2", tws)

# ----- conntect to TWS at standard port -----
host = "127.0.0.1" ;
print( "Connecting . . . \n")
tws.CONNECT(host,7496,5,100);

# --- get a contract uid for MSFT (do this only once per contract. save uid globally, if you need this contract more than once)
print ("Register MSFT\n")
uidMSFT = tws.REGISTER_CONTRACT("MSFT","STK","USD","SMART","NASDAQ","","",0.0,"",0,0.0) 
print ("uid contract MSFT=",uidMSFT,"\n")

# --- place the market order
if uidMSFT > 0:
    print ("Place buy market 100 MSFT\n")
    uidOrderMSFT = tws.PLACE_ORDER(uidMSFT,0,"BUY","MKT",100,0.0,0.0,"GTC",1,0) 
    print ("uid order MSFT=",uidOrderMSFT,"\n");
    tws.WAIT_FOR_FILLED(uidOrderMSFT,2000)
else:
    print("wrong contract specification");
print ("finished")



[ddownload id=”1196″ style=”link” text=”Download TWSLink Python 3.6 wrapper”]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.