コード例 #1
0
 def __buildAcceptedLimitOrder(self, action, limitPrice, quantity):
     ret = broker.LimitOrder(action, "orcl", limitPrice, quantity,
                             DefaultTraits())
     self.assertEqual(ret.getSubmitDateTime(), None)
     ret.switchState(broker.Order.State.SUBMITTED)
     ret.setSubmitted(1, datetime.datetime.now())
     self.assertNotEqual(ret.getSubmitDateTime(), None)
     ret.switchState(broker.Order.State.ACCEPTED)
     return ret
コード例 #2
0
def build_order_from_open_order(openOrder, instrumentTraits):
    if openOrder.isBuy():
        action = broker.Order.Action.BUY
    elif openOrder.isSell():
        action = broker.Order.Action.SELL
    else:
        raise Exception("Invalid order type")

    ret = broker.LimitOrder(action, common.btc_symbol, openOrder.getPrice(),
                            openOrder.getAmount(), instrumentTraits)
    ret.setSubmitted(openOrder.getId(), openOrder.getDateTime())
    ret.setState(broker.Order.State.ACCEPTED)
    return ret
コード例 #3
0
    def createLimitOrder(self, action, instrument, limitPrice, quantity):
        if instrument != common.btc_symbol:
            raise Exception("Only BTC instrument is supported")

        if action == broker.Order.Action.BUY_TO_COVER:
            action = broker.Order.Action.BUY
        elif action == broker.Order.Action.SELL_SHORT:
            action = broker.Order.Action.SELL

        if action not in [broker.Order.Action.BUY, broker.Order.Action.SELL]:
            raise Exception("Only BUY/SELL orders are supported")

        instrumentTraits = self.getInstrumentTraits(instrument)
        limitPrice = round(limitPrice, 2)
        quantity = instrumentTraits.roundQuantity(quantity)
        return broker.LimitOrder(action, instrument, limitPrice, quantity,
                                 instrumentTraits)