File size: 2,573 Bytes
8c68ede
6468ff1
8c68ede
6468ff1
 
 
 
 
 
 
 
 
 
 
6795bc5
6468ff1
 
 
 
 
 
8c68ede
6468ff1
8c68ede
6468ff1
 
 
 
 
8c68ede
6468ff1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d4710b
6468ff1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import streamlit as st
import requests
import pandas as pd
from bs4 import BeautifulSoup
import urllib3

# Configuraci贸n de p谩gina
st.set_page_config(page_title="Monitor Cambiario", page_icon="馃搱", layout="centered")

# Deshabilitar advertencias de SSL (equivalente a ssl_verifypeer = FALSE en R)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def get_data():
    # --- API BINANCE (v铆a CriptoYa) ---
    try:
        url_crypto = "https://criptoya.com/api/USDT/VES/0.1"
        res_crypto = requests.get(url_crypto)
        data_crypto = res_crypto.json()
        usdt_price = data_crypto['binancep2p']['totalAsk']
    except:
        usdt_price = 0

    # --- SCRAPING BCV ---
    try:
        url_bcv = "https://www.bcv.org.ve"
        # User-agent para evitar bloqueos
        headers = {'User-Agent': 'Mozilla/5.0'}
        res_bcv = requests.get(url_bcv, headers=headers, verify=False)
        soup = BeautifulSoup(res_bcv.text, 'html.parser')
        
        # Extracci贸n siguiendo tu l贸gica de IDs
        dolar = float(soup.find(id="dolar").find("strong").text.strip().replace(',', '.'))
        euro = float(soup.find(id="euro").find("strong").text.strip().replace(',', '.'))
    except:
        dolar, euro = 0, 0

    return usdt_price, dolar, euro

# --- INTERFAZ STREAMLIT ---
st.title("馃搳 Monitor de Divisas")
st.markdown(f"**脷ltima actualizaci贸n:** {pd.Timestamp.now().strftime('%d/%m/%Y %H:%M:%S')}")

usdt, usd_bcv, eur_bcv = get_data()

# M茅tricas principales en columnas est茅ticas
col1, col2, col3 = st.columns(3)

with col1:
    st.metric(label="USDT (Binance)", value=f"{usdt:.2f} VES")

with col2:
    st.metric(label="D贸lar BCV", value=f"{usd_bcv:.2f} VES")

with col3:
    st.metric(label="Euro BCV", value=f"{eur_bcv:.2f} VES")

st.divider()

# --- SECCI脫N DE C脕LCULOS ---
st.subheader("馃挕 An谩lisis de Compra")

# Tu l贸gica: Comprar d贸lar con 10% de descuento sobre el USDT
compra_sugerida = usdt - (usdt * 0.10)

c1, c2 = st.columns(2)
with c1:
    st.info(f"**Precio USDT:** {usdt:.2f}")
    st.success(f"**Sugerencia de compra (-10%):** {compra_sugerida:.2f} VES")

with c2:
    # Brecha entre paralelo (USDT) y oficial
    brecha = ((usdt / usd_bcv) - 1) * 100 if usd_bcv > 0 else 0
    st.warning(f"**Brecha Cambiaria:** {brecha:.2f}%")

# --- TABLA RESUMEN ---
st.subheader("馃摑 Resumen de Datos")
df_mostrar = pd.DataFrame({
    "Moneda": ["USDT", "BCV $", "BCV Euro"],
    "Monto (VES)": [usdt, usd_bcv, eur_bcv]
})
st.table(df_mostrar)

if st.button('馃攧 Actualizar Precios'):
    st.rerun()