[ENG/ITA] Rebuilding My HIVE/SWAP.HIVE Python Script

avatar


La versione italiana si trova sotto quella inglese

The italian version is under the english one


Rebuilding My HIVE/SWAP.HIVE Python Script

Losing BeeSwap means losing one of the two best ways to convert HIVE into SWAP.HIVE, and vice versa.

Besides BeeSwap, in fact, uSwap also offers a simple and very low-cost service, with fees that, in some cases, can even be positive.

Several months ago, I had created a script that monitored these two bridges and executed transfers whenever it detected potential profit opportunities.

Now that BeeSwap no longer provides this service, I had to take action by disabling the script—which would otherwise have risked sending funds to the @hiveswap account—and then modifying it so that it would work only with uSwap, and in some cases with dCrops.

Since I was already working on it, I decided to go a step further, not just removing the functions that interacted with BeeSwap, but also reviewing and expanding those related to uSwap, in order to improve the way I interact with this platform and increase the chances of making a profit.


Clearer and more precise functions

One of the most important parts of this update certainly involved the functions responsible for collecting data from the platforms (uSwap and dCrops) and providing the data needed to perform a swap.


def uswap_swap(account, uswap, user_id, threshold, token, session: requests.Session):
    if token == "HIVE":
        my_balance = get_my_balance(account, session, token)
        transfer = transfer_hive
        calculate = calculate_hive_swap

    elif token == "SWAP.HIVE":
        my_balance = get_my_balance(account, session, token)
        transfer = transfer_swap_hive
        calculate = calculate_shive_swap

    if not my_balance:
        return False

    us_hive = get_liquid_hive(uswap, session)
    us_swap_hive = get_swap_hive(uswap, session)
    exp_result, _, fee_percent = calculate(my_balance, us_hive, us_swap_hive)
    if fee_percent < threshold:
        return False
    memo = f"{exp_result}"
    transfer(account, uswap, str(my_balance), memo)
    notification(f"Swapped {my_balance} {token} on uSwap", user_id)
    print(f"Swapped {my_balance} {token} on uSwap")

    return True

The uswap_swap function now handles both HIVE and SWAP.HIVE transfers, whereas before I had two separate and partially duplicated functions.

The same applies to dCrops, which now has a single, more readable function that handles both types of transfers.

This makes the script much easier to maintain, since in case of issues I can intervene on a single function instead of constantly having to remember to apply changes to two different ones.


Testing phase

Now, before I can reactivate the script—and see how much my ability to generate profits has changed now that BeeSwap is gone—I’ll need to carry out a testing phase as thorough as possible.

This script, in fact, handles fund transfers, and an error could result in the complete loss of the funds sent.

It is therefore essential that I’m confident the script works correctly, and for this reason the next phase will consist of running tests with a much smaller budget, so that, in case of errors, the loss is limited to just a few HIVE/SWAP.HIVE—and not thousands.

Once this phase is successfully completed, I’ll be able to officially reactivate the script at full capacity and go back to focusing on other arbitrage opportunities.


cover made with Grok AI and edited with GIMP

to support the #OliodiBalena community, @balaenoptera is 3% beneficiary of this post


If you've read this far, thank you! If you want to leave an upvote, a reblog, a follow, a comment... well, any sign of life is really much appreciated!


Versione italiana

Italian version


Risistemando il Mio Script di Python per HIVE/SWAP.HIVE

Perdere BeeSwap significa aver perso uno dei due migliori modi per convertire HIVE in SWAP.HIVE, e viceversa.

Oltre a BeeSwap, infatti, anche uSwap offre un servizio semplice da usare e dal costo molto basso, con commissioni che, in certi casi, possono essere positive.

Io avevo creato, ormai parecchi mesi fa, uno script che si occupava di monitorare questi due bridges ed effettuare trasferimenti quando rilevava potenziali situazioni di guadagno.

Ora che BeeSwap non fornisce più questo servizio ho dovuto perciò correre ai ripari, disabilitando lo script - che altrimenti avrebbe rischiato di inviare fondi all'account @hiveswap - e procedendo a modificarlo in modo da farlo funzionare solo con uSwap - ed in certi casi con dCrops.

Già che c'ero ho deciso di fare un lavoro più profondo, non limitandomi a togliere le funzioni che interagivano con BeeSwap, ma approfondendo ed espandendo quelle relative a uSwap, in modo da migliore il modo in cui interagisco con questa piattaforma ed aumentare le possibilità di realizzare un guadagno.


Funzioni più chiare e precise

Una delle parti più importanti della mia opera di aggiornamento ha sicuramente riguardato le funzioni che si occupano di raccogliere i dati dalle piattaforme (uSwap e dCrops) e fornire i dati per effettuare uno swap.


def uswap_swap(account, uswap, user_id, threshold, token, session: requests.Session):
    if token == "HIVE":
        my_balance = get_my_balance(account, session, token)
        transfer = transfer_hive
        calculate = calculate_hive_swap

    elif token == "SWAP.HIVE":
        my_balance = get_my_balance(account, session, token)
        transfer = transfer_swap_hive
        calculate = calculate_shive_swap

    if not my_balance:
        return False

    us_hive = get_liquid_hive(uswap, session)
    us_swap_hive = get_swap_hive(uswap, session)
    exp_result, _, fee_percent = calculate(my_balance, us_hive, us_swap_hive)
    if fee_percent < threshold:
        return False
    memo = f"{exp_result}"
    transfer(account, uswap, str(my_balance), memo)
    notification(f"Swapped {my_balance} {token} on uSwap", user_id)
    print(f"Swapped {my_balance} {token} on uSwap")

    return True

La funzione uswap_swap adesso infatti gestisce sia i trasferimenti in HIVE che in SWAP.HIVE, mentre prima avevo due funzioni distinte e parzialmente duplicate.

Lo stesso vale per dCrops, che adesso ha una funzione unica e più leggibile che si occupa di entrambi i tipi di trasferimento.

Questo rende lo script sicuramente più facile da mantenere, dato che in caso di problemi posso intervenire su una sola funzione invece che dovermi costantemente ricordare di apportare le modifiche su due funzioni diverse.


Fase di testing

Adesso, prima di poter nuovamente riattivare lo script - e scoprire quanto sarà variata la mia capacità di generare un guadagno, ora che non c'è più BeeSwap - dovrò effettuare una fase di test il più approfondita possibile.

Questo script, infatti, si occupa di trasferire fondi ed un errore potrebbe portare alla completa perdita dei fondi inviati.

E' quindi fondamentale che sia sicuro del corretto funzionamento dello script e, per questo, la prossima fase consisterà nell'eseguire delle prove con un budget molto più ridotto, così che, in caso di errori, la perdita sia solo di pochi HIVE/SWAP.HIVE - e non migliaia.

Terminata - con successo - questa fase potrò ufficialmente riattivare a pieno regime lo script e tornare a concentrarmi su altre possibilità di arbitraggio.


cover realizzata con Grok AI ed editata con GIMP

a supporto della community #OliodiBalena, il 3% delle ricompense di questo post va a @balaenoptera

Se sei arrivato a leggere fin qui, grazie! Se hai voglia di lasciare un upvote, un reblog, un follow, un commento... be', un qualsiasi segnale di vita, in realtà, è molto apprezzato!

Posted Using INLEO



0
0
0.000
0 comments