def test_create_order_message(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            'market': str,
            'side': str,
            'quantity': str,
            'price': str,
            'type': str,
            'time_in_force': str,
            'stop_price': str,
            'trigger_type': str,
            'is_post_only': bool,
            'is_reduce_only': bool,
            'originator': str,
        }

        test_type = types.CreateOrderMessage(market="swth_eth1",
                                             side="swth",
                                             quantity="1",
                                             price="0.1",
                                             type='limit',
                                             time_in_force="gtc",
                                             stop_price="0.2",
                                             trigger_type="stop-limit",
                                             is_post_only=False,
                                             is_reduce_only=False,
                                             originator=WALLET_ADDRESS)
        self.assertDictStructure(expect, jsons.dump(test_type))
    def test_create_order(self):
        txn_message: dict = types.CreateOrderMessage(market='swth_eth',
                                                     side="sell",
                                                     quantity="200",
                                                     type="market")
        result: dict = self.authenticated_client.create_order(
            message=txn_message)

        self.assertDictStructure(expect=self.expect, actual=result)
Ejemplo n.º 3
0
    def stop_limit_sell(self, pair: str, price: str, quantity: str,
                        stop_price: str):
        """
        Function to place a stop limit sell order on Demex.

        Execution of this function is as follows::

            stop_limit_sell(pair='swth_eth1', quantity=1000, price='0.0002', stop_price='0.00015')

        The expected return result for this function is as follows::

            {
                'height': str,
                'txhash': str,
                `'raw_log': str,
                'logs': [{
                    'msg_index': int,
                    'log': str,
                    'events': [{
                        'type': str,
                        'attributes': [{
                            'key': str,
                            'value': str
                        }, {
                            'key': str,
                            'value': str
                        }]
                    }]
                }],
                'gas_wanted': str,
                'gas_used': str
            }

        :return: Dictionary in the form of a JSON message with the stop limit order details.
        """
        current_price = self.tradehub.get_prices(market=pair)["last"]
        if Decimal(stop_price) < Decimal(current_price):
            create_order_msg = types.CreateOrderMessage(
                market=pair,
                side="sell",
                quantity=quantity,
                price=price,
                type="stop-limit",
                stop_price=stop_price,
                trigger_type="last_price")
            return self.tradehub.create_order(message=create_order_msg)
        else:
            raise ValueError(
                "Stop Price target {} is required to be below the current market price {} to trigger a stop order."
                .format(stop_price, current_price))
Ejemplo n.º 4
0
    def limit_sell(self, pair: str, quantity: str, price: str):
        """
        Function to place a limit sell order on Demex.

        Execution of this function is as follows::

            limit_sell(pair='swth_eth1', quantity=1000, price='0.0002')

        The expected return result for this function is as follows::

            {
                'height': str,
                'txhash': str,
                `'raw_log': str,
                'logs': [{
                    'msg_index': int,
                    'log': str,
                    'events': [{
                        'type': str,
                        'attributes': [{
                            'key': str,
                            'value': str
                        }, {
                            'key': str,
                            'value': str
                        }]
                    }]
                }],
                'gas_wanted': str,
                'gas_used': str
            }

        :return: Dictionary in the form of a JSON message with the limit order details.
        """
        create_order_msg = types.CreateOrderMessage(market=pair,
                                                    side="sell",
                                                    quantity=quantity,
                                                    price=price,
                                                    type="limit")
        return self.tradehub.create_order(message=create_order_msg)