On May 19, 2024, the article Hive Cuba's P2P opens to everyone - Open Source was published in the Hive Cuba Community. The HiveCubaP2P project code was released on Github under the MIT license. This release allowed developers to contribute to the development, maintenance and factorization of the project code.
El 19 de mayo de 2024 se publicó en la Comunidad de Hive Cuba el artículo El P2P de Hive Cuba se abre a todos - OpenSource. El código del proyecto HiveCubaP2P fue liberado en Github bajo la licencia MIT. Esta liberación permitió a los desarrolladores contribuir al desarrollo, mantenimiento y factorización del código del proyecto.
HiveCubaP2P is a Telegram bot for P2P peer-to-peer exchange of HIVE or HBD with FIAT or other values. It is based on a mechanism of escrow guaranteed by the @hivecuba.p2p account trusted and supported by the HIVE Cuba community. It has zero commissions for users who have a subscription delegation.
HiveCubaP2P es un bot de Telegram para el intercambio P2P peer-to-peer de HIVE o HBD con FIAT u otros valores. Se basa en un mecanismo de depósito en garantía garantizado por la cuenta @hivecuba.p2p, de confianza y con el respaldo de la comunidad HIVE Cuba. Tiene cero comisiones para los usuarios que tengan una delegación de suscripción.
Reading your roadmap, I understand that, although it is a project that is consolidating and is used and accepted by the Cuban Hive community, it still needs developers to evolve and make the access curve much simpler.
Leyendo su roadmap comprendo que, aunque es un proyecto que se consolida y es utilizado y aceptado por la comunidad cubana de Hive aún necesita de desarrolladores para evolucionar y que la curva de acceso sea mucho más sencilla.
Roadmap
- Collaborate with other communities.
- Add support for Sats via @v4vapp
- Add new functionalities and information elements to users.
- Implement buttons to improve usability.
- Implement a way to keep the exchange inside the bot always.
- Create a webapp that frees us from depending on Telegram.
- Add new languages if necessary.
- Add other collateral services and promote community services in favor of the adoption of HIVE/HBD/SAT.
Roadmap
- Colaborar con otras comunidades.
- Añadir soporte para Sats vía @v4vapp
- Añadir nuevas funcionalidades y elementos de información a los usuarios.
- Implementar botones para mejorar la usabilidad.
- Implementar una forma de mantener el intercambio dentro del bot siempre.
- Crear una webapp que nos libere de depender de Telegram.
- Añadir nuevos idiomas si es necesario.
- Añadir otros servicios colaterales y promover servicios comunitarios a favor de la adopción de HIVE/HBD/SAT.
One of the functionalities that are recurrent in P2P exchange bots is to integrate a currency converter that allows you to see updated prices or calculate the estimated conversion from one currency to another without leaving Telegram.
I got to work by making a fork of the project on Github. To do this, I followed the collaboration guide in the README.md
Guideline
- Cloning the Bot project
git clone https://github.com/Ertytux/Hive_P2P_Bot.git
- Create an exclusive virtual environment
cd Hive_P2P_Bot python3 -m venv env
- Activate the virtual environment
Windows env\Scripts\activatemacOS or Linux
env/bin/activate
- Install the packages from the requirements.txt file
pip install -r requeriment.txt
- Have an account in HIVESQL
- Run and setup into operations the bot with the command:
Linux or macOS ./run.shWindows
call .env_sample.bat
Una de las funcionalidades que son recurrentes en los bots de intercambio P2P es la de integrar un conversor de divisas que permite ver precios actualizados o calcular la conversión estimada de una moneda a otra sin salir de Telegram. Me puse manos a la obra haciendo un fork del proyecto en Github. Para ello, seguí la guía de colaboración en el archivo README.md
Guía
- Clonar el proyecto Bot
git clone https://github.com/Ertytux/Hive_P2P_Bot.git
- Crear un entorno virtual exclusivo
cd Hive_P2P_Bot python3 -m venv env
- Activar el entorno virtual
Windows env\Scripts\activatemacOS o Linux
env/bin/activate
- Instalar los paquetes desde el archivo requirements.txt
pip install -r requeriment.txt
- Tener una cuenta en HIVESQL
- Ejecutar y configurar el bot en operaciones con el comando:
Linux o macOS ./run.shWindows
call .env_sample.bat
A new feature in the project consists of modifying the files: rates.py, botengine.py, hcp2pb.py, messages.py
Una nueva característica del proyecto consiste en modificar los archivos: rates.py, botengine.py, hcp2pb.py, messages.pyHiveCubaP2P project structure
In the rates.py file, the function that is responsible for receiving the amount to be exchanged and the source and destination currencies is added. The currencies available for conversion through APIs (Yadio and Coingecko) are: CUP, USD, MLC, HBD and Hive.
En el archivo rates.py se agrega la función que se encarga de recibir el monto a cambiar y las monedas de origen y destino. Las monedas disponibles para conversión a través de APIs (Yadio y Coingecko) son: CUP, USD, MLC, HBD y Hive.
def getExchange(amount:str, coinFrom:str, coinTo:str)->str:
"""
Convert an amount from one currency to another\n
Currency: USD, CUP, MLC, HIVE, HBD
"""
try:
# response = requests.get(yadio_url)
urlYadio = 'https://api.yadio.io/convert/'
urlYadioRate = 'https://api.yadio.io/exrates/USD'
divisorSlash = '/'
if (coinFrom.upper() in tkY and coinTo.upper() in tkY):
"""Exchange Yadio CUP MLC USD from Yadio"""
convertUrlYadio = f"{urlYadio}{amount}{divisorSlash}{coinFrom.upper()}{divisorSlash}{coinTo.upper()}"
response = requests.get(convertUrlYadio)
result = response.json().get('result')
rate = response.json().get('rate')
msg = f"Amount {coinTo.upper()}: {result:.8f} {coinTo.upper()}\nRate: {rate:.8f} USD"
# return exchange_result
elif (coinFrom.upper() in tkG and coinTo.upper() in tkG and coinFrom.upper() != coinTo.upper()):
"""Exchange HBD/Hive from Coingecko"""
idxFrom = tkG.get(coinFrom.upper())
idxTo = tkG.get(coinTo.upper())
if idxFrom == 'hive':
"""Exchange Hive to HBD from Coingecko"""
pHive=float(cg.get_price(ids=idxFrom, vs_currencies='usd')[idxFrom]['usd'])
vHive=float(amount)*pHive
pHBD=float(cg.get_price(ids=idxTo, vs_currencies='usd')[idxTo]['usd'])
result=vHive/pHBD
msg = f"Amount {coinTo.upper()}: {result:.8f} {coinTo.upper()}\nRate: {pHBD:.8f} USD"
#return exchange_result
else:
"""Exchange HBD to Hive from Coingecko"""
pHBD=float(cg.get_price(ids=idxFrom, vs_currencies='usd')[idxFrom]['usd'])
vHBD=float(amount)*pHBD
pHive=float(cg.get_price(ids=idxTo, vs_currencies='usd')[idxTo]['usd'])
result=vHBD/pHive
msg = f"Amount {coinTo.upper()}: {result:.8f} {coinTo.upper()}\nRate: {pHive:.8f} USD"
# return exchange_result
elif (coinFrom.upper() in tkY and coinTo.upper() in tkG):
"""Exchange from Yadio to Coingecko"""
response = requests.get(urlYadioRate)
pcoin=float(response.json().get('USD').get(coinFrom.upper()))
vcoin=float(amount)/pcoin
idxTo = tkG.get(coinTo.upper())
pcoinGecko=float(cg.get_price(ids=idxTo, vs_currencies='usd')[idxTo]['usd'])
result=vcoin/pcoinGecko
msg = f"Amount {coinTo.upper()}: {result:.8f} {coinTo.upper()}\nRate: {pcoinGecko:.8f} USD"
elif (coinFrom.upper() in tkG and coinTo.upper() in tkY):
"""Exchange from Coingecko to Yadio"""
response = requests.get(urlYadioRate)
idxFrom = tkG.get(coinFrom.upper())
pcoinGecko=float(cg.get_price(ids=idxFrom, vs_currencies='usd')[idxFrom]['usd'])
vcoin=float(amount)*pcoinGecko
pcoin=float(response.json().get('USD').get(coinTo.upper()))
result=vcoin*pcoin
msg = f"Amount {coinTo.upper()}: {result:.8f} {coinTo.upper()}\nRate: {pcoin:.8f} USD"
else:
msg=f"No es posible realizar esa conversión\nIt is not available this exchange!!!"
except:
msg=f"No esta disponible\nIt is not available!!!"
return msg
In the botengine.py file, the convert() function is created that captures the amount of the source currency and the currency to be obtained from the bot front-end using the structure
Structure
/convert 1 HBD CUPEn el archivo botengine.py, se crea la función convert() que captura la cantidad de la moneda de origen y la moneda a obtener desde el front-end del bot utilizando la estructuraEstructura
/convert 1 HBD CUP
async def convert(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: """Convert an amount from one currency to another command /convert\n Command: /convert 1 HBD CUP """ user = update.effective_user scode = getlang(user.language_code) if user.username == '' or user.username == None: await update.message.reply_markdown(messages_statU.get(scode)) return None stext = update.message.text.split() if len(stext) < 4: msg = {'es': 'Comando incorrecto, debe ser por ejemplo: /convert 1 HBD CUP ', 'en': 'Incorrect command, it must be for example: /convert 1 HBD CUP '} await update.message.reply_text(msg.get(scode)) return None await update.message.reply_text(rt.getExchange(stext[1],stext[2],stext[3]))
In the hcp2pb.py file, the handler in charge of displaying the new command /convert application.add_handler(CommandHandler("convert", convert)) in the telegram bot is added.
En el archivo hcp2pb.py, se agrega el controlador encargado de mostrar el nuevo comando /convert application.add_handler(CommandHandler("convert", convert)) en el bot de Telegram.
application.add_handler(CommandHandler("convert", convert))
Finally, the new functionality is described in the messages.py file
Finalmente, la nueva funcionalidad se describe en el archivo messages.py
/convert - Convert an amount from one currency to another 🧮
Telegram bot /convert feature
HiveCubaP2P /convert Yadio api Coingecko apiWell, that's all for this post. I hope this feature has been useful to you. Let me know if you want to see any other new features added.
Bueno, y hasta aquí el post, espero que esta funcionalidad te haya sido útil. Cuéntame si deseas que se agregue alguna otra nueva funcionalidad.
It has been great to have the incorporation of new contributors to the development. Only in this way can we make a continuous improvement and achieve a quality service that brings HIVE and HBD closer to everyday life and an interconnected circular economy. Grateful for your contribution and I look forward to your future contributions.
Grateful for his words, the creation of the HiveCubaP2P bot is a reality and its impact for Cubans was immediate. Contributing whatever is needed to the Hive Cuba Community
Congratulations @codebydoble! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)
Your next target is to reach 50 comments.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Check out our last posts:
El p2p es un servicio cada vez más completo, muchas gracias por dedicarle tanto esfuerzo 🚀
Comprendo que simplifica la vida de muchas personas. Trataré de contribuir con más funcionalidades. Agradecido de tus palabras.
Congratulations @codebydoble! You received a personal badge!
Wait until the end of Power Up Day to find out the size of your Power-Bee.
May the Hive Power be with you!
You can view your badges on your board and compare yourself to others in the Ranking
Check out our last posts:
Congratulations @codebydoble! You received a personal badge!
Participate in the next Power Up Day and try to power-up more HIVE to get a bigger Power-Bee.
May the Hive Power be with you!
You can view your badges on your board and compare yourself to others in the Ranking
Check out our last posts: