コード例 #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
コード例 #2
0
ファイル: client.py プロジェクト: stinct9/dydx-python
    def _make_perp_order(
        self,
        market,
        side,
        amount,
        price,
        expiration=None,
        limitFee=None,
        postOnly=False,
    ):
        '''
        Make an order object

        :param market: required
        :type market: str in list
            ["PBTC-USDC"]

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

        :param amount: required
        :type amount: number

        :param price: required
        :type price: Decimal

        :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, _ = 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,
            'amount': amount,
            'limitPrice': price,
            'triggerPrice': Decimal(0),
            'limitFee': limitFee,
            'maker': self.public_address,
            'taker': consts.TAKER_ACCOUNT_OWNER,
            'expiration': expiration or utils.epoch_in_four_weeks(),
        }
        order['typedSignature'] = \
            perp_orders.sign_order(order, self.private_key)
        return order
コード例 #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
コード例 #4
0
    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
コード例 #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
コード例 #6
0
ファイル: test_client.py プロジェクト: stinct9/dydx-python
    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
        assert body['market'] == args['market']

        order = body['order']
        assert order['isBuy'] is args['isBuy']
        assert order['isDecreaseOnly'] is False
        assert order['amount'] == str(args['amount'])
        assert order['limitPrice'] == str(args['limitPrice'])
        assert order['triggerPrice'] == '0'
        assert order['limitFee'] == '0.00075'
        assert order['maker'] == client.public_address
        assert order['taker'] == consts.TAKER_ACCOUNT_OWNER
        assert abs(int(order['expiration']) -
                   utils.epoch_in_four_weeks()) <= 10
        assert order['salt'].isnumeric()

        expected_signature = perp_orders.sign_order(
            {
                'isBuy': order['isBuy'],
                'amount': int(order['amount']),
                'limitPrice': Decimal(order['limitPrice']),
                'triggerPrice': Decimal(order['triggerPrice']),
                'limitFee': Decimal(order['limitFee']),
                'maker': order['maker'],
                'taker': order['taker'],
                'expiration': int(order['expiration']),
                'salt': int(order['salt'])
            }, client.private_key)
        assert body['order']['typedSignature'] == expected_signature
        return True
コード例 #7
0
ファイル: client.py プロジェクト: WarrickFitz/dydx-python
    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()}
                              })))
コード例 #8
0
ファイル: client.py プロジェクト: kpyzhyanov/dydx-python
    def _make_solo_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: Decimal

        :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 = consts.DEFAULT_LIMIT_FEE

        order = {
            'salt': random.randint(0, 2**256),
            'isBuy': isBuy,
            'baseMarket': baseMarket,
            'quoteMarket': quoteMarket,
            'amount': int(float(amount)),
            'limitPrice': price,
            'triggerPrice': Decimal(0),
            'limitFee': limitFee,
            'makerAccountOwner': self.public_address,
            'makerAccountNumber': self.account_number,
            'expiration': expiration or utils.epoch_in_four_weeks(),
        }
        order['typedSignature'] = \
            solo_orders.sign_order(order, self.private_key)
        return order
コード例 #9
0
ファイル: client.py プロジェクト: ErikBjare/dydx-python
    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()},
                    }
                )
            ),
        )