예제 #1
0
파일: trade.py 프로젝트: 42cc/ripple_api
def create_offer(taker_pays, taker_gets, account, secret, timeout, fee=10000, flags=0, servers=None):
    """
    Create trading offer.

    takes:
        taker_pays -  {
            'value':    - float - amount to buy
            'currency': - str   - currency
            'issuer':   - str   - issuer
        }
        taker_gets -  {
            'value':    - float - amount to sell
            'currency': - str   - currency
            'issuer':   - str   - issuer
        }
        account    - ripple account
        secret     - ripple secret
        timeout    - trade timeout
        fee        - ripple fee (default: 10000)
        flags      - trade flags (default: 0)
        servers    - ripple servers (default: none)

    returns:
        offer

    taker - user, that accepts your offer

    """

    taker_pays = taker_pays.copy()
    taker_gets = taker_gets.copy()
    taker_pays["value"] = "%.12f" % taker_pays["value"]
    taker_gets["value"] = "%.12f" % taker_gets["value"]
    offer = {
        "method": "submit",
        "params": [
            {
                "secret": secret,
                "tx_json": {
                    "TransactionType": "OfferCreate",
                    "Fee": str(fee),
                    "Flags": flags,
                    "Account": account,
                    "TakerPays": taker_pays,
                    "TakerGets": taker_gets,
                },
            }
        ],
    }

    # make offer copy and remove secret
    log_offer = copy.deepcopy(offer)
    log_offer["params"][0].pop("secret", None)
    logger.info("Trade offer: %s" % log_offer)
    return call_api(offer, timeout=timeout, servers=servers)
예제 #2
0
def create_offer(taker_pays,
                 taker_gets,
                 account,
                 secret,
                 timeout,
                 fee=10000,
                 flags=0,
                 servers=None):
    """
    Create trading offer.

    takes:
        taker_pays -  {
            'value':    - float - amount to buy
            'currency': - str   - currency
            'issuer':   - str   - issuer
        }
        taker_gets -  {
            'value':    - float - amount to sell
            'currency': - str   - currency
            'issuer':   - str   - issuer
        }
        account    - ripple account
        secret     - ripple secret
        timeout    - trade timeout
        fee        - ripple fee (default: 10000)
        flags      - trade flags (default: 0)
        servers    - ripple servers (default: none)

    returns:
        offer

    taker - user, that accepts your offer

    """

    taker_pays = taker_pays.copy()
    taker_gets = taker_gets.copy()
    taker_pays['value'] = "%.12f" % taker_pays['value']
    taker_gets['value'] = "%.12f" % taker_gets['value']
    offer = {
        "method":
        "submit",
        "params": [{
            "secret": secret,
            "tx_json": {
                "TransactionType": "OfferCreate",
                "Fee": str(fee),
                "Flags": flags,
                "Account": account,
                "TakerPays": taker_pays,
                "TakerGets": taker_gets,
            },
        }]
    }

    # make offer copy and remove secret
    log_offer = copy.deepcopy(offer)
    log_offer['params'][0].pop('secret', None)
    logger.info('Trade offer: %s' % log_offer)
    return call_api(offer, timeout=timeout, servers=servers)
예제 #3
0
파일: tests.py 프로젝트: akhavr/ripple_api
    def test_timeout(self, post_mock):
        post_mock.side_effect = ssl.SSLError

        with self.assertRaises(RippleApiError):
            call_api({})
예제 #4
0
파일: tests.py 프로젝트: akhavr/ripple_api
 def custom_call_api(error):
     try:
         call_api({})
     except error:
         self.assertEqual(post_mock.call_count,
                          len(settings.RIPPLE_API_DATA))
예제 #5
0
파일: test_api.py 프로젝트: 42cc/ripple_api
    def test_timeout(self, post_mock):
        post_mock.side_effect = ssl.SSLError

        with self.assertRaises(RippleApiError):
            call_api({})
예제 #6
0
파일: test_api.py 프로젝트: 42cc/ripple_api
 def custom_call_api(error):
     try:
         call_api({})
     except error:
         self.assertEqual(post_mock.call_count,
                          len(settings.RIPPLE_API_DATA))