Beispiel #1
0
    def order_placed(self, ord):
        "Handles creation of orders. "

        assert (not ord.is_processed())

        acc = ord.account
        order_ev_pos = ord.group_by_event()

        # get the cost for completing the order
        cost = sum([self.eval_cost(ev, ps) for (ev,ps) in order_ev_pos])
        logger.debug("Order '%s' total sum: %f" % (ord, cost))

        # see if the order can be completed
        ord.is_successful = (acc.funds >= cost)
        if ord.is_successful:

            # update the market maker amounts
            MarketBalance.accept_order(ord)

            # update the account amounts
            AccountBalance.accept_order(ord)

            # deduct the total transaction cost from the account
            acc.funds -= cost
                    
            # update buy/sell prices
            for (ev, ps) in order_ev_pos:
                self.update_prices(ev)

        ord.set_processed()
        acc.save()
        ord.save()
        logger.debug("Order '%s' processed!" % (ord,))
Beispiel #2
0
    def reset_event(self, ev):
        """
        Resets the market and account balances (amount of shares held) for each of this event's outcomes. 

        Calls self.update_prices with the given event 
        """
        AccountBalance.reset(ev)
        MarketBalance.reset(ev)
        self.update_prices(ev)
Beispiel #3
0
    def reset_event(self, ev):
        """
        Resets the market and account balances (amount of shares held) for each of this event's outcomes. 

        Calls self.update_prices with the given event 
        """
        AccountBalance.reset(ev)
        MarketBalance.reset(ev)
        self.update_prices(ev)
Beispiel #4
0
 def __init__(self, acc, out):
     self.outcome = out
     self.account = acc
     if acc:
         self.amount = AccountBalance.get(acc, out).amount
Beispiel #5
0
 def __init__(self, acc, out):
     self.outcome = out
     self.account = acc
     if acc:
         self.amount = AccountBalance.get(acc, out).amount