Beispiel #1
0
 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
Beispiel #2
0
    def _make_order(
        self,
        market,
        side,
        amount,
        price,
        expiration=None,
        limitFee=None,
        postOnly=False,
    ):
        '''
        Make an order object

        :param market: required
        :type market: str in list ["WETH-DAI", "WETH-USDC", "DAI-USDC"]

        :param side: required
        :type side: str in list ["BUY", "SELL"]

        :param amount: required
        :type amount: number

        :param price: required
        :type price: number

        :param expiration: optional, defaults to 28 days from now
        :type expiration: number

        :param limitFee: optional, overrides the default limitFee
        :type limitFee: number

        :param postOnly: optional, defaults to False
        :type postOnly: bool

        :returns: Order

        :raises: DydxAPIError
        '''

        baseMarket, quoteMarket = utils.pair_to_base_quote_markets(market)
        isBuy = utils.get_is_buy(side)
        if limitFee is None:
            limitFee = utils.get_limit_fee(baseMarket, amount, postOnly)

        order = {
            'salt': random.randint(0, 2**256),
            'isBuy': isBuy,
            'baseMarket': baseMarket,
            'quoteMarket': quoteMarket,
            'amount': amount,
            'limitPrice': price,
            'triggerPrice': 0,
            'limitFee': limitFee,
            'makerAccountOwner': self.public_address,
            'makerAccountNumber': self.account_number,
            'expiration': expiration or utils.epoch_in_four_weeks(),
        }
        order['typedSignature'] = utils.sign_order(order, self.private_key)
        return order
Beispiel #3
0
    def _make_order(
        self,
        makerMarket,
        takerMarket,
        makerAmount,
        takerAmount,
        expiration=None,
    ):
        '''
        Make an order object

        :param makerMarket: required
        :type makerMarket: number

        :param takerMarket: required
        :type takerMarket: number

        :param makerAmount: required
        :type makerAmount: number

        :param takerAmount: required
        :type takerAmount: number

        :param expiration: optional, defaults to 28 days from now
        :type expiration: number

        :returns: Order

        :raises: DydxAPIError
        '''

        order = {
            'makerMarket': makerMarket,
            'takerMarket': takerMarket,
            'makerAmount': makerAmount,
            'takerAmount': takerAmount,
            'makerAccountOwner': self.public_address,
            'makerAccountNumber': self.account_number,
            'takerAccountOwner': self.TAKER_ACCOUNT_OWNER,
            'takerAccountNumber': self.TAKER_ACCOUNT_NUMBER,
            'expiration': expiration or utils.epoch_in_four_weeks(),
            'salt': random.randint(0, 2**256)
        }
        order['typedSignature'] = utils.sign_order(order, self.private_key)
        return order
    def _additional_matcher(request):
        body = json.loads(request.body)
        assert not body['fillOrKill']
        assert not body['postOnly']
        assert 'cancelAmountOnRevert' not in body
        assert 'cancelId' not in body
        assert 'clientId' not in body

        order = body['order']
        assert order['isBuy'] is True
        assert order['isDecreaseOnly'] is False
        assert order['baseMarket'] == '0'
        assert order['quoteMarket'] == '3'
        assert order['amount'] == '10000'
        assert order['limitPrice'] == '250.01'
        assert order['triggerPrice'] == '0'
        assert order['limitFee'] == '0.005'
        assert order['makerAccountOwner'] == \
            client.public_address
        assert order['makerAccountNumber'] == \
            str(client.account_number)
        assert abs(int(order['expiration']) -
                   utils.epoch_in_four_weeks()) <= 10
        assert order['salt'].isnumeric()

        expected_signature = utils.sign_order(
            {
                'isBuy': order['isBuy'],
                'baseMarket': int(order['baseMarket']),
                'quoteMarket': int(order['quoteMarket']),
                'amount': int(order['amount']),
                'limitPrice': float(order['limitPrice']),
                'triggerPrice': float(order['triggerPrice']),
                'limitFee': float(order['limitFee']),
                'makerAccountOwner': order['makerAccountOwner'],
                'makerAccountNumber': int(order['makerAccountNumber']),
                'expiration': int(order['expiration']),
                'salt': int(order['salt'])
            }, client.private_key)
        assert body['order']['typedSignature'] == expected_signature
        return True
Beispiel #5
0
 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
Beispiel #6
0
 def test_sign_order(self):
     signature = utils.sign_order(order=ORDER, private_key=PRIVATE_KEY_1)
     assert signature == ORDER_SIGNATURE
Beispiel #7
0
    def create_order(
        self,
        makerMarket,
        takerMarket,
        makerAmount,
        takerAmount,
        expiration=None,
        fillOrKill=False,
        clientId=None,
    ):
        '''
        Create an order

        :param makerMarket: required
        :type makerMarket: number

        :param takerMarket: required
        :type takerMarket: number

        :param makerAmount: required
        :type makerAmount: number

        :param takerAmount: required
        :type takerAmount: number

        :param expiration: optional, defaults to 28 days from now
        :type expiration: number

        :param fillOrKill: optional, defaults to False
        :type fillOrKill: bool

        :param clientId: optional, defaults to None
        :type clientId: string

        :returns: Order

        :raises: DydxAPIError
        '''

        order = {
            'makerMarket': makerMarket,
            'takerMarket': takerMarket,
            'makerAmount': makerAmount,
            'takerAmount': takerAmount,
            'makerAccountOwner': self.public_address,
            'makerAccountNumber': self.account_number,
            'takerAccountOwner': self.TAKER_ACCOUNT_OWNER,
            'takerAccountNumber': self.TAKER_ACCOUNT_NUMBER,
            'expiration': expiration or utils.epoch_in_four_weeks(),
            'salt': random.randint(0, 2**256)
        }
        order['typedSignature'] = utils.sign_order(order, self.private_key)

        return self._post('dex/orders',
                          data=json.dumps(
                              utils.remove_nones({
                                  'fillOrKill': fillOrKill,
                                  'clientId': clientId,
                                  'order':
                                  {k: str(v)
                                   for k, v in order.items()}
                              })))
Beispiel #8
0
    def create_order(
        self,
        makerMarket,
        takerMarket,
        makerAmount,
        takerAmount,
        expiration=None,
        fillOrKill=False,
        clientId=None,
    ):
        """
        Create an order

        :param makerMarket: required
        :type makerMarket: number

        :param takerMarket: required
        :type takerMarket: number

        :param makerAmount: required
        :type makerAmount: number

        :param takerAmount: required
        :type takerAmount: number

        :param expiration: optional, defaults to 28 days from now
        :type expiration: number

        :param fillOrKill: optional, defaults to False
        :type fillOrKill: bool

        :param clientId: optional, defaults to None
        :type clientId: string

        :returns: Order

        :raises: DydxAPIError
        """

        order = {
            "makerMarket": makerMarket,
            "takerMarket": takerMarket,
            "makerAmount": makerAmount,
            "takerAmount": takerAmount,
            "makerAccountOwner": self.public_address,
            "makerAccountNumber": self.account_number,
            "takerAccountOwner": self.TAKER_ACCOUNT_OWNER,
            "takerAccountNumber": self.TAKER_ACCOUNT_NUMBER,
            "expiration": expiration or utils.epoch_in_four_weeks(),
            "salt": random.randint(0, 2 ** 256),
        }
        order["typedSignature"] = utils.sign_order(order, self.private_key)

        return self._post(
            "dex/orders",
            data=json.dumps(
                utils.remove_nones(
                    {
                        "fillOrKill": fillOrKill,
                        "clientId": clientId,
                        "order": {k: str(v) for k, v in order.items()},
                    }
                )
            ),
        )