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:

# -----------------------------------------------------------------------------------------
# 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 = "" ;
print( "Connecting . . . \n")

# --- 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");
    print("wrong contract specification");
print ("finished")

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

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.