Skip to content

Instantly share code, notes, and snippets.

@itsff
Created September 7, 2019 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsff/bd7021deffeb01a85eb1b97c5135a1f5 to your computer and use it in GitHub Desktop.
Save itsff/bd7021deffeb01a85eb1b97c5135a1f5 to your computer and use it in GitHub Desktop.
from __future__ import print_function
import re
def create_leg(osi_symbol, ratio):
regex = re.compile("(?<symbol>\w+)\s*(?<year>\d{2})(?<month>\d{2})(?<day>\d{2})(?<call_put>[CP])(?<dollars>\d+)(?<cents>\d{2})")
m = regex.match(osi_symbol)
if not m:
raise ValueError("Huh? Is this right OSI symbol: " + osi_symbol)
symbol = m.group('symbol')
year = m.group('year')
month = m.group('month')
day = m.group('day')
call_put = m.group('call_put')
dollars = m.group('dollars')
cents = m.group('cents')
leg = Msg()
leg.LegID = leg.gen_id()
leg.LegSymbol = symbol
leg.LegStrikePrice = float(dollars + '.' + cents)
leg.CFICode = call_put + "O" # hard-coding O
leg.LegMaturityMonthYear = "20" + year + month
leg.LegMaturityDate = day
leg.LegRatioQty = abs(ratio)
if ratio < 0:
leg.LegSide = '2' # sell
else:
leg.LegSide = '1' # buy
return leg
def make_limit(side, symbol, qty, price):
order = Order()
order.Side = side
order.Symbol = symbol
order.OrderQty = qty
order.Price = price
order.OrdType = fix.OrdType.LIMIT
return order
def make_market(side, symbol, qty):
order = Order()
order.Side = side
order.Symbol = symbol
order.OrderQty = qty
order.Price = None
order.OrdType = fix.OrdType.MARKET
return order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment