elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Necesito obtener el precio del BTC y agregarlo a TextBox
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Necesito obtener el precio del BTC y agregarlo a TextBox  (Leído 1,493 veces)
Brayhan

Desconectado Desconectado

Mensajes: 2


Ver Perfil
Necesito obtener el precio del BTC y agregarlo a TextBox
« en: 3 Diciembre 2022, 18:52 pm »

Buenas. Soy nuevo por acá, y estoy intentando hacer un sistema que me saque precios y porcentajes ya que trabajo con minería.

Básicamente necesito saber si hay alguna forma de obtener el precio del Bitcoin (no importa si no es en tiempo real, puede ser cada 5 minutos, etc) y que esa información se muestre dentro de un TextBox. Puedo introducir ese valor manualmente y el programa funciona perfectamente porque ya tengo todo lo demás listo, pero me gustaría saber si se puede automatizar de alguna manera.

Muchas gracias :D


En línea

AlbertoBSD
Programador y
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.696


🏴 Libertad!!!!!


Ver Perfil WWW
Re: Necesito obtener el precio del BTC y agregarlo a TextBox
« Respuesta #1 en: 4 Diciembre 2022, 05:29 am »

Tal vez el sigueinte codigo te ayude.

Código
  1. Dim request As HttpWebRequest
  2. Dim response As HttpWebResponse = Nothing
  3. Dim reader As StreamReader
  4.  
  5. ' Set the URL of the API endpoint
  6. Dim url As String = "https://api.coindesk.com/v1/bpi/currentprice.json"
  7.  
  8. Try
  9.    ' Create a new HTTP to=python
  10. request = HttpWebRequest.Create(url)
  11.  
  12. ' Send the request and get the response
  13. response = request.GetResponse()
  14.  
  15. ' Read the response and store it in a string
  16. Dim data As String = response.GetResponseStream()
  17. Dim content As String = reader.ReadToEnd()
  18.  
  19. ' Close the response
  20. response.Close()
  21.  
  22. ' Parse the JSON response to get the current Bitcoin price
  23. Dim jObject As JObject = JObject.Parse(content)
  24. Dim price As Double = jObject("bpi")("USD")("rate_float")
  25.  
  26. ' Update the text box with the current Bitcoin price
  27. TextBox1.Text = price
  28.  
  29. Catch ex As Exception
  30.    ' Show an error message if the request failed
  31.    MessageBox.Show("Error: " & ex.Message)
  32. End Try
  33.  

Saludos!


En línea

Brayhan

Desconectado Desconectado

Mensajes: 2


Ver Perfil
Re: Necesito obtener el precio del BTC y agregarlo a TextBox
« Respuesta #2 en: 4 Diciembre 2022, 07:25 am »

Muchas gracias por responder!

Lamentablemente no logro hacerlo funcionar :(

Me da el siguiente error:

"Dim data As String = response.GetResponseStream()" El valor de tipo Stream no se puede convertir en String.

"Dim jObject As JObject = jObject.Parse(content)" No está definido el tipo JObject. La variable jObject se usa antes de que se le haya asignado un valor.
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines