Example #1
0
 def test_sign_withdrawal(self):
     withdrawal = SignableWithdrawal(**WITHDRAWAL_PARAMS)
     signature = withdrawal.sign(MOCK_PRIVATE_KEY)
     assert signature == MOCK_SIGNATURE
Example #2
0
    def create_withdrawal(
        self,
        position_id,
        amount,
        asset,
        to_address,
        client_id=None,
        expiration=None,
        expiration_epoch_seconds=None,
        signature=None,
    ):
        '''
        Post a withdrawal

        :param position_id: required
        :type position_id: int or str

        :param amount: required
        :type amount: str

        :param asset: required
        :type asset: str in list [
            "ETH",
            "LINK",
            "BTC",
            "USDC",
            "USDT",
            "USD",
        ]

        :param to_address: required
        :type to_address: str

        :param client_id: optional
        :type client_id: str

        :param expiration: optional
        :type expiration: ISO str

        :param expiration_epoch_seconds: optional
        :type expiration_epoch_seconds: int

        :param signature: optional
        :type signature: str

        :returns: Transfer

        :raises: DydxAPIError
        '''
        client_id = client_id or random_client_id()
        if bool(expiration) == bool(expiration_epoch_seconds):
            raise ValueError(
                'Exactly one of expiration and expiration_epoch_seconds must '
                'be specified', )
        expiration = expiration or epoch_seconds_to_iso(
            expiration_epoch_seconds, )
        expiration_epoch_seconds = (expiration_epoch_seconds
                                    or iso_to_epoch_seconds(expiration))

        if not signature:
            if not self.stark_private_key:
                raise Exception('No signature provided and client was not' +
                                'initialized with stark_private_key')
            withdrawal_to_sign = SignableWithdrawal(
                network_id=self.network_id,
                position_id=position_id,
                client_id=client_id,
                human_amount=amount,
                expiration_epoch_seconds=expiration_epoch_seconds,
            )
            signature = withdrawal_to_sign.sign(self.stark_private_key)

        params = {
            'amount': amount,
            'asset': asset,
            # TODO: Signature verification should work regardless of case.
            'toAddress': to_address.lower(),
            'expiration': expiration,
            'clientId': client_id,
            'signature': signature,
        }
        return self._post('withdrawals', params)
Example #3
0
    def create_withdrawal(
        self,
        position_id,
        amount,
        asset,
        to_address,
        expiration,
        client_id=None,
        signature=None,
    ):
        '''
        Post a withdrawal

        :param position_id: required
        :type position_id: int or str

        :param amount: required
        :type amount: str

        :param asset: required
        :type asset: str in list [
            "ETH",
            "LINK",
            "BTC",
            "USDC",
            "USDT",
            "USD",
        ]

        :param to_address: required
        :type to_address: str

        :param expiration: required
        :type expiration: ISO string

        :param client_id: optional
        :type client_id: str

        :param signature: optional
        :type signature: str

        :returns: Transfer

        :raises: DydxAPIError
        '''
        client_id = client_id or random_client_id()

        withdrawal_signature = signature
        if not withdrawal_signature:
            if not self.stark_private_key:
                raise Exception(
                    'No signature provided and client was not' +
                    'initialized with stark_private_key'
                )
            withdrawal_to_sign = SignableWithdrawal(
                position_id=position_id,
                client_id=client_id,
                human_amount=amount,
                expiration_epoch_seconds=iso_to_epoch_seconds(expiration),
            )
            withdrawal_signature = withdrawal_to_sign.sign(
                self.stark_private_key,
            )
        withdrawal = {
            'amount': amount,
            'asset': asset,
            # TODO: Signature verification should work regardless of case.
            'toAddress': to_address.lower(),
            'clientId': client_id,
            'signature': withdrawal_signature,
            'expiration': expiration,
        }

        return self._post(
            'withdrawals',
            withdrawal,
        )