Beispiel #1
0
    def __init__(self):
	self.accountNumber = ''
	self.optionExpiry = '20121221'   # This needs manual updating!
	self.maxAskBidRatio = 1.25
	self.maxAskLastPriceRatio = 1.02
	self.maxOrderQueueLength = 3
	# Create a file for TWS logging
        self.twslog_fh = open('/home/mchan/git/Artemis/twslog.txt', 'a', 0)
	self.twslog_fh.write("Session Started " + str(datetime.datetime.now()) + "\n")
	self.callback = ArtemisIBWrapperSilent.ArtemisIBWrapper() 
	self.tws = EPosixClientSocket(self.callback)
	self.orderIdCount = 1 # This will be updated automatically
	self.requestIdCount = 1
	self.invested = False
	self.maxLimitPriceFactor = 1.02  # No limit orders above 2% of current ask price
	# Connect the socket
	self.socketnum = 30
	self.tws.eConnect("", 7496, self.socketnum, poll_interval=1)
	# Strategy Generic object, has methods for interpreting consensus out/under performance
	self.Strat = strategy.Strategy()
	# Queue for orders
	self.orderQueue = []
	# Setup DB connector
	self.db = dbutil.db(h='127.0.0.1', schema='mchan')
	
	# Query Cash Account Balance
	self.updateBuyingPowerNextId()
Beispiel #2
0
    def __init__(self):
        self.accountNumber = ''
        self.optionExpiry = '20121221'  # This needs manual updating!
        self.maxAskBidRatio = 1.25
        self.maxAskLastPriceRatio = 1.02
        self.maxOrderQueueLength = 3
        # Create a file for TWS logging
        self.twslog_fh = open('/home/mchan/git/Artemis/twslog.txt', 'a', 0)
        self.twslog_fh.write("Session Started " +
                             str(datetime.datetime.now()) + "\n")
        self.callback = ArtemisIBWrapperSilent.ArtemisIBWrapper()
        self.tws = EPosixClientSocket(self.callback)
        self.orderIdCount = 1  # This will be updated automatically
        self.requestIdCount = 1
        self.invested = False
        self.maxLimitPriceFactor = 1.02  # No limit orders above 2% of current ask price
        # Connect the socket
        self.socketnum = 30
        self.tws.eConnect("", 7496, self.socketnum, poll_interval=1)
        # Strategy Generic object, has methods for interpreting consensus out/under performance
        self.Strat = strategy.Strategy()
        # Queue for orders
        self.orderQueue = []
        # Setup DB connector
        self.db = dbutil.db(h='127.0.0.1', schema='mchan')

        # Query Cash Account Balance
        self.updateBuyingPowerNextId()
###

tickTypeHash = {0:"bid size", 1:"bid price", 2:"ask price", 3:"ask size", 4:"last price", \
	5:"last size", 6:"high", 7:"low", 8:"volume", 9:"close price", 10:"bid option computation", \
	11:"ask option computation",  12:"last option computation", 13:"model option computation", \
	14:"open tick", 15:"low 13 week", 16:"high 13 week", 17:"low 26 week", 18:"high 26 week", \
	19:"low 52 week", 20:"high 52 week", 21:"avg volume", 22:"open interest", \
	23:"option historical vol", 24:"option implied vol", 25:"option bid exch", \
	26:"option ask exch", 27:"option call open interest", 28:"option put open interest", \
	29:"option call volume", 30:"option put volume", 31:"index future premium", \
	32:"bid exch", 33:"ask exch", 37:"mark price", 45:"last timestamp", \
	46:"shortable", 47:"fundamental ratios", 48:"rt volume", 49:"halted", \
	53:"cust option computation", 54:"trade count", 55:"trade rate", \
	56:"volume rate"}

wrapper_db = dbutil.db(h='127.0.0.1', schema='mchan')
class ArtemisIBWrapper(EWrapper):
    '''Callback object passed to TWS, these functions will be called directly
    by TWS.

    '''
    def deltaNeutralValidation(self, reqId, underComp):
	pass

    def marketDataType(self, reqid, marketDataType):
	print "Market Data Type: ", reqId, " ", marketDataType

    def winError(self, mesg, errorCode):
	print "Win error message: ", mesg, " ", errorCode

    def error(self, orderId, errorCode, errorString):
Beispiel #4
0
import sys
from datetime import datetime, date

theurl = "http://www.theflyonthewall.com/beta/news.php"
theurl2 = "http://www.theflyonthewall.com/beta/paraDesarrollar/getNews.php"
loginurl = "http://www.theflyonthewall.com/login.php"
loginurl2 = "http://www.theflyonthewall.com/beta/paraDesarrollar/login.php"

username = ""
password = ""
txheader = {'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
data = {'username': username, 'password': password}

import dbutil

__homeserv = dbutil.db(h='127.0.0.1', schema='mchan')
__cursor = __homeserv.cursor

txdata = urllib.urlencode(data)
# Setup Cookie manager
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
resp = opener.open(theurl)
resp = opener.open(loginurl2, txdata)
# Now get the unlocked data
try:
    resp2 = opener.open(theurl)
except urllib2.HTTPError, e:
    print 'The server couldn\'t fulfill the request.'
    print 'Error code: ', e.code
except urllib2.URLError, e:
Beispiel #5
0
import sys
from datetime import datetime, date

theurl = "http://www.theflyonthewall.com/beta/news.php"
theurl2 = "http://www.theflyonthewall.com/beta/paraDesarrollar/getNews.php"
loginurl = "http://www.theflyonthewall.com/login.php"
loginurl2 = "http://www.theflyonthewall.com/beta/paraDesarrollar/login.php"

username = ""
password = ""
txheader =  {'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
data = {'username':username, 'password':password}

import dbutil

__homeserv = dbutil.db(h='127.0.0.1', schema='mchan')
__cursor = __homeserv.cursor


txdata = urllib.urlencode(data)
# Setup Cookie manager
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
resp = opener.open(theurl)
resp = opener.open(loginurl2, txdata)
# Now get the unlocked data
try:
   resp2 = opener.open(theurl)
except urllib2.HTTPError, e:
    print 'The server couldn\'t fulfill the request.'
    print 'Error code: ', e.code
###

tickTypeHash = {0:"bid size", 1:"bid price", 2:"ask price", 3:"ask size", 4:"last price", \
	5:"last size", 6:"high", 7:"low", 8:"volume", 9:"close price", 10:"bid option computation", \
	11:"ask option computation",  12:"last option computation", 13:"model option computation", \
	14:"open tick", 15:"low 13 week", 16:"high 13 week", 17:"low 26 week", 18:"high 26 week", \
	19:"low 52 week", 20:"high 52 week", 21:"avg volume", 22:"open interest", \
	23:"option historical vol", 24:"option implied vol", 25:"option bid exch", \
	26:"option ask exch", 27:"option call open interest", 28:"option put open interest", \
	29:"option call volume", 30:"option put volume", 31:"index future premium", \
	32:"bid exch", 33:"ask exch", 37:"mark price", 45:"last timestamp", \
	46:"shortable", 47:"fundamental ratios", 48:"rt volume", 49:"halted", \
	53:"cust option computation", 54:"trade count", 55:"trade rate", \
	56:"volume rate"}

wrapper_db = dbutil.db(h='127.0.0.1', schema='mchan')
wrapper_db.execute('SET autocommit=0;')
class ArtemisIBWrapper(EWrapper):
    '''Callback object passed to TWS, these functions will be called directly
    by TWS.

    '''
    def deltaNeutralValidation(self, reqId, underComp):
	pass

    def marketDataType(self, reqid, marketDataType):
	print "Market Data Type: ", reqId, " ", marketDataType

    def winError(self, mesg, errorCode):
	print "Win error message: ", mesg, " ", errorCode
    31: "index future premium",
    32: "bid exch",
    33: "ask exch",
    37: "mark price",
    45: "last timestamp",
    46: "shortable",
    47: "fundamental ratios",
    48: "rt volume",
    49: "halted",
    53: "cust option computation",
    54: "trade count",
    55: "trade rate",
    56: "volume rate",
}

wrapper_db = dbutil.db(h="127.0.0.1", schema="mchan")


class ArtemisIBWrapper(EWrapper):
    """Callback object passed to TWS, these functions will be called directly
    by TWS.

    """

    def deltaNeutralValidation(self, reqId, underComp):
        pass

    def marketDataType(self, reqid, marketDataType):
        print "Market Data Type: ", reqId, " ", marketDataType

    def winError(self, mesg, errorCode):
Beispiel #8
0
 def __init__(self):
     self.rank = None
     self.db = dbutil.db(h='127.0.0.1', schema='mchan')
     self.cursor = self.db.cursor
Beispiel #9
0
 def __init__(self, c, master):
     self.local = threading.local()
     self.db = dbutil.db()
     threading.Thread.__init__(self)
     self.c = c
     self.master = master
Beispiel #10
0
    def __init__(self):
	self.rank = None
	self.db = dbutil.db(h='127.0.0.1', schema='mchan')
        self.cursor = self.db.cursor