예제 #1
0
 def test_Buy_error(self):
     self.interface.handleRequest(2, 'bl4p.buy', {
         'limit_rate': 42,
         'amount': 6
     })
     self.assertEqual(self.output.buffer, b'')
     self.client.handleIncomingMessage.assert_called_once_with(
         messages.BuyCommand(
             commandID=2,
             limitRate=42,
             amount=6,
         ))
     self.interface.handleMessage(
         messages.PluginCommandError(
             commandID=2,
             code=11,
             message='fubar',
         ))
     self.checkJSONOutput({
         'jsonrpc': '2.0',
         'id': 2,
         'error': {
             'code': 11,
             'message': 'fubar'
         },
     })
예제 #2
0
 def wrapper(self, cmd):
     if not self.client.isBL4PConnected():
         self.client.handleOutgoingMessage(
             messages.PluginCommandError(
                 commandID=cmd.commandID,
                 code=1,
                 message=
                 'Cannot perform this action while not connected to a BL4P server'
             ))
         return
     method(self, cmd)
예제 #3
0
    def handleCancelCommand(self, cmd: messages.CancelCommand) -> None:
        try:
            task = self.orderTasks[cmd.orderID]
        except KeyError:
            self.client.handleOutgoingMessage(
                messages.PluginCommandError(
                    commandID=cmd.commandID,
                    code=2,
                    message='There is no active order with ID ' +
                    str(cmd.orderID)))
            return

        task.cancel()

        self.client.handleOutgoingMessage(
            messages.PluginCommandResult(commandID=cmd.commandID, result=None))
예제 #4
0
    def test_handleCancelCommand(self):
        self.backend.orderTasks = {41: Mock()}
        cmd = Mock()
        cmd.commandID = 42
        cmd.orderID = 41
        self.backend.handleCancelCommand(cmd)
        self.backend.orderTasks[41].cancel.assert_called_with()
        self.assertEqual(
            self.outgoingMessages,
            [messages.PluginCommandResult(commandID=42, result=None)])

        self.outgoingMessages = []
        cmd.orderID = 40
        self.backend.handleCancelCommand(cmd)
        self.assertEqual(self.outgoingMessages, [
            messages.PluginCommandError(
                commandID=42,
                code=2,
                message='There is no active order with ID 40')
        ])
예제 #5
0
    def test_handleSellCommand_noBL4P(self):
        self.backend.storage = MockStorage(test=self)
        self.backend.BL4PAddress = 'BL4PAddress'
        self.bl4pIsConnected = False

        cmd = Mock()
        cmd.commandID = 42
        cmd.amount = 123
        cmd.limitRate = 20000
        with patch.object(backend.ordertask, 'OrderTask', MockOrderTask):
            self.backend.handleSellCommand(cmd)

        self.assertEqual(set(self.backend.orderTasks.keys()), set([]))
        self.assertEqual(set(self.backend.storage.sellOrders.keys()), set([]))

        self.assertEqual(self.outgoingMessages, [
            messages.PluginCommandError(
                commandID=42,
                code=1,
                message=
                'Cannot perform this action while not connected to a BL4P server'
            )
        ])