コード例 #1
0
    def test_create_order_success(self):
        def additional_matcher(request):
            body = json.loads(request.body)
            assert body["fillOrKill"] is False
            assert body["order"]["takerMarket"] == "0"
            assert body["order"]["makerMarket"] == "1"
            assert body["order"]["takerAmount"] == "1000"
            assert body["order"]["makerAmount"] == "2000"
            assert body["order"]["makerAccountOwner"] == client.public_address
            assert body["order"]["makerAccountNumber"] == str(
                client.account_number)
            assert body["order"][
                "takerAccountOwner"] == client.TAKER_ACCOUNT_OWNER
            assert body["order"]["takerAccountNumber"] == str(
                client.TAKER_ACCOUNT_NUMBER)
            assert (abs(
                int(body["order"]["expiration"]) - utils.epoch_in_four_weeks())
                    <= 10)
            assert body["order"]["salt"].isnumeric()
            sent_order = body["order"]
            expected_signature = utils.sign_order(
                {
                    "makerMarket": int(sent_order["makerMarket"]),
                    "takerMarket": int(sent_order["takerMarket"]),
                    "makerAmount": int(sent_order["makerAmount"]),
                    "takerAmount": int(sent_order["takerAmount"]),
                    "makerAccountOwner": sent_order["makerAccountOwner"],
                    "makerAccountNumber": int(
                        sent_order["makerAccountNumber"]),
                    "takerAccountOwner": sent_order["takerAccountOwner"],
                    "takerAccountNumber": int(
                        sent_order["takerAccountNumber"]),
                    "expiration": int(sent_order["expiration"]),
                    "salt": int(sent_order["salt"]),
                },
                client.private_key,
            )
            assert body["order"]["typedSignature"] == expected_signature
            return True

        client = Client(PRIVATE_KEY_1)
        with requests_mock.mock() as rm:
            json_obj = tests.test_json.mock_create_order_json
            rm.post(
                "https://api.dydx.exchange/v1/dex/orders",
                additional_matcher=additional_matcher,
                json=json_obj,
            )
            result = client.create_order(makerMarket=1,
                                         takerMarket=0,
                                         makerAmount=2000,
                                         takerAmount=1000)
            assert result == json_obj
コード例 #2
0
    def test_create_order_success(self):

        def additional_matcher(request):
            body = json.loads(request.body)
            assert body['fillOrKill'] is False
            assert body['order']['takerMarket'] == '0'
            assert body['order']['makerMarket'] == '1'
            assert body['order']['takerAmount'] == '1000'
            assert body['order']['makerAmount'] == '2000'
            assert body['order']['makerAccountOwner'] == \
                client.public_address
            assert body['order']['makerAccountNumber'] == \
                str(client.account_number)
            assert body['order']['takerAccountOwner'] == \
                client.TAKER_ACCOUNT_OWNER
            assert body['order']['takerAccountNumber'] == \
                str(client.TAKER_ACCOUNT_NUMBER)
            assert abs(
                int(body['order']['expiration']) -
                utils.epoch_in_four_weeks()) <= 10
            assert body['order']['salt'].isnumeric()
            sent_order = body['order']
            expected_signature = utils.sign_order({
                'makerMarket': int(sent_order['makerMarket']),
                'takerMarket': int(sent_order['takerMarket']),
                'makerAmount': int(sent_order['makerAmount']),
                'takerAmount': int(sent_order['takerAmount']),
                'makerAccountOwner': sent_order['makerAccountOwner'],
                'makerAccountNumber': int(sent_order['makerAccountNumber']),
                'takerAccountOwner': sent_order['takerAccountOwner'],
                'takerAccountNumber': int(sent_order['takerAccountNumber']),
                'expiration': int(sent_order['expiration']),
                'salt': int(sent_order['salt']),
            }, client.private_key)
            assert body['order']['typedSignature'] == expected_signature
            return True

        client = Client(PRIVATE_KEY_1)
        with requests_mock.mock() as rm:
            json_obj = tests.test_json.mock_create_order_json
            rm.post(
                'https://api.dydx.exchange/v1/dex/orders',
                additional_matcher=additional_matcher,
                json=json_obj
            )
            result = client.create_order(
                makerMarket=1,
                takerMarket=0,
                makerAmount=2000,
                takerAmount=1000
            )
            assert result == json_obj
コード例 #3
0
 def test_create_order_success(self):
     client = Client(PRIVATE_KEY_1)
     with requests_mock.mock() as rm:
         json_obj = tests.test_json.mock_create_order_json
         rm.post(
             'https://api.dydx.exchange/v1/dex/orders',
             additional_matcher=_create_additional_matcher(client),
             json=json_obj
         )
         result = client.create_order(
             makerMarket=1,
             takerMarket=0,
             makerAmount=2000,
             takerAmount=1000
         )
         assert result == json_obj