Example #1
0
 def __init__(self):
     event.subscribe(self.inner.on_order_created, _(self).onOrderCreated, self)
     event.subscribe(OnOrderMatched(), _(self)._onOrderMatched, self)
     self.on_traded = event.Event()
     self.orderBook = OfTrader()
     self._balance = 0
     self._position = 0
Example #2
0
def Peg(order):
    """ Peg is a virtual order that ensures that it has the best price in the order book. 
    It is implemented as a limit order which is cancelled 
    once the best price in the order queue has changed 
    and is sent again to the order book 
    with a price one tick better than the best price in the book.
    """
    from marketsim.gen._out.orderbook._oftrader import OfTrader
    from marketsim.gen._out.orderbook._ticksize import TickSize
    from marketsim.gen._out.orderbook.ask._price import Price as AskPrice
    from marketsim.gen._out.orderbook.bid._price import Price as BidPrice
    from marketsim.gen._out.math.Cumulative._maxepsilon import MaxEpsilon
    from marketsim.gen._out.math.Cumulative._minepsilon import MinEpsilon

    side = order.side
    book = OfTrader()
    tickSize = TickSize(book)
    askPrice = AskPrice(book)
    bidPrice = BidPrice(book)

    price = MinEpsilon(askPrice, tickSize)\
                if side == Side.Sell else\
            MaxEpsilon(bidPrice, tickSize)

    return FloatingPrice(order, price)
Example #3
0
 def __init__(self):
     self._balance = 0
     self._position = 0
     from marketsim.gen._out.event._event import Event
     self.on_traded = Event()
     self.orderBook = OfTrader()
     event.subscribe(self.inner.on_order_created,
                     _(self).onOrderCreated, self)
Example #4
0
    def __init__(self):

        # orders created by trader
        from marketsim.gen._out.trader._singleproxy import SingleProxy
        from marketsim.gen._out.orderbook._oftrader import OfTrader
        self._elements = []
        self._eventGen = event.Every(self.cancellationIntervalDistr)
        self._myTrader = SingleProxy()
        self._book = OfTrader(self._myTrader)
        self.on_order_created = event.Event()
Example #5
0
    def __init__(self):
        Strategy.__init__(self)

        # our order book
        self._book = OfTrader()
        # our order queue
        self._orderQueue = Queue(self._book, side = self.side)
        # we are going to track best price changes
        self._source = self._orderQueue.BestPrice
        event.subscribe(self._source, _(self)._wakeUp, self)
        # deque containing issued orders
        self._orders = None
        # how many orders can be issued
        self._size = self.initialSize
        self._suspended = False
Example #6
0
def Peg(order):
    """ Peg is a virtual order that ensures that it has the best price in the order book. 
    It is implemented as a limit order which is cancelled 
    once the best price in the order queue has changed 
    and is sent again to the order book 
    with a price one tick better than the best price in the book.
    """
    from marketsim.gen._out.orderbook._oftrader import OfTrader

    side = order.side
    book = OfTrader()
    tickSize = book.TickSize
    askPrice = book.Asks.BestPrice
    bidPrice = book.Bids.BestPrice

    price = askPrice.Cumulative.MinEpsilon(tickSize)\
                if side == Side.Sell else\
            bidPrice.Cumulative.MaxEpsilon(tickSize)

    return FloatingPrice(order, price)
Example #7
0
 def Orderbook(self):
     from marketsim.gen._out.orderbook._oftrader import OfTrader
     return OfTrader(self)