Atomic PEK Testing: Why the Exchange Rate Won’t Load

avatar
(Edited)

PeakCoin is a 20% beneficiary on my posts to buyback PeakeCoin"

The Atomic PEK swap interface is finally up and running — in testing mode — at
https://geocities.ws/peakecoin/atomic_pek/

The PeakeCoin branding is Maryland as ever, and you can walk through a real atomic swap for Hive Engine tokens like PIMP, NEOXAG, WAIV, POB, BEE, or LEO. The UI works, the backend is coded, and you can even generate the correct memo for the swap.

But... if you try to swap right now, you’ll probably run into this:

Unable to fetch live SWAP.HIVE rate.

Yeah, that message is getting on my nerves too.


💡 What’s Working

UI:
Clean, simple, and even mobile-friendly. You can select tokens, enter amounts, and preview everything.

Backend:
Flask serves up everything, and the /api/rate endpoint is supposed to fetch the latest rate for you, using code like this:

('/api/rate')
def get_token_rate():
    token = request.args.get('token')
    if not token:
        return jsonify({'error': 'Missing token'}), 400
    # Try buyBook (best ask)
    try:
        res = requests.post('https://api.hive-engine.com/rpc', json={
            'jsonrpc': '2.0',
            'id': 1,
            'method': 'find',
            'params': {
                'contract': 'market',
                'table': 'buyBook',
                'query': {'symbol': token, 'baseSymbol': 'SWAP.HIVE'},
                'limit': 1,
                'indexes': [{'index': 'price', 'descending': True}]
            }
        })
        data = res.json()
        if data and data.get('result') and len(data['result']) > 0 and data['result'][0].get('price'):
            return jsonify({'rate': float(data['result'][0]['price'])})
    except Exception:
        pass
    # Try metrics as fallback
    ...

Swap Logic:
The bot and the atomic swap watcher logic are all coded up. As soon as a token lands with the right memo, the bot should process your swap. (The watcher is basically in an infinite loop polling for qualifying transfers and matching up memos and rates.)


🚫 What’s Not Working (Yet)

The live exchange rate fetch is still fighting me, and the frontend is the main casualty.

My script.js tries this logic:

async function fetchSwapHiveRate(token) {
    // Try buyBook (best ask)
    try {
        const res = await fetch('https://api.hive-engine.com/rpc', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
                jsonrpc: '2.0',
                id: 1,
                method: 'find',
                params: {
                    contract: 'market',
                    table: 'buyBook',
                    query: { symbol: token, baseSymbol: 'SWAP.HIVE' },
                    limit: 1,
                    indexes: [{ index: 'price', descending: true }]
                }
            })
        });
        const data = await res.json();
        if (data && data.result && data.result.length > 0 && data.result[0].price && !isNaN(data.result[0].price)) {
            return parseFloat(data.result[0].price);
        }
    } catch (e) {}
    // Try metrics as fallback...
    ...
    return null;
}

But in reality? Sometimes the Hive Engine node just returns empty data or times out. Other times, CORS blocks the browser call entirely. So for now, you’ll see:

rateDisplay.textContent = 'Unable to fetch live SWAP.HIVE rate.';
pekRateInput.value = '';

Not exactly the smooth experience I wanted.


🛠️ Where We're At (Test Mode)

  • You can test the form, preview your swap, and see exactly what memo to use.

  • You cannot reliably fetch the live exchange rate, so you'll have to look it up manually for now.

  • All the swap logic and backend pieces are ready — just waiting for the frontend rate-fetch to behave.


🔜 Next Steps

  • Try other Hive Engine API nodes (in case it’s a public node issue).

  • Refactor so all rate-fetching is done by my Flask backend, not in the browser (to dodge CORS).

  • Add more error logging, so I can see why things fail, not just that they did.


🗣️ Dev Note / Call for Help

If anyone has conquered this kind of Hive Engine API + CORS weirdness — let me know your secrets! Until then, Atomic PEK swaps are working, but still in testing.


https://geocities.ws/peakecoin/atomic_pek/



0
0
0.000
0 comments