Sub Class_Globals
Dim name As String
Private API_Key As String
Private API_Secret As String
Dim BidOld As Double
Dim AskOld As Double
Dim LastOld As Double
Dim TimeOld As Long
Dim BidNow As Double
Dim AskNow As Double
Dim LastNow As Double
Dim status As String
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(money As String, Key As String, Secret As String)
name = money
API_Key = Key
API_Secret = Secret
End Sub
private Sub HashHmac(data As String, secret As String) As Byte()
Try
Dim m As Mac 'm As Message Authentication Code
Dim kg As KeyGenerator 'kg As KeyGenerator
kg.Initialize("HmacSHA512") 'initialize kg using HmacSHA512 algorithm
kg.KeyFromBytes(secret.GetBytes("UTF8")) 'encode string "secret" to an array of Bytes using UTF8
m.Initialise("HmacSHA512", kg.Key) 'initialize m using HmacSHA512 algorithm and the secret key
m.Update(data.GetBytes("UTF8")) 'encodes post data to an array of Bytes and loads it to be signed
Return m.Sign 'sign the loaded data using the secret key, return the calc signature data
Catch
Log(LastException)
End Try
End Sub
private Sub SendCommand(work As String, uri As String)
Try
Dim nonce As Long
nonce = DateTime.now
uri = uri & "&nonce=" & nonce
Dim sign() As Byte
sign = HashHmac(uri, API_Secret)
Dim API_Signed As String
Dim Byte_Conv As ByteConverter
API_Signed = Byte_Conv.HexFromBytes(sign) 'convert to HEX
API_Signed = API_Signed.ToLowerCase
Dim j As HttpJob
j.Initialize(work, "money")
j.PostString(uri, "")
j.GetRequest.SetHeader("apisign", API_Signed)
Wait For (j) jobDone(j As HttpJob)
If j.Success Then
If (j.JobName == "CmdGetTicker") Then
Dim parser As JSONParser
parser.Initialize(j.GetString)
Dim root As Map = parser.NextObject
Dim result As Map = root.Get("result")
Dim Last As Double = result.Get("Last")
LastOld = LastNow
LastNow = Last
Dim Ask As Double = result.Get("Ask")
AskOld = AskNow
AskNow = Ask
Dim Bid As Double = result.Get("Bid")
BidOld = BidNow
BidNow = Bid
Dim success As String = root.Get("success")
status = success 'Guardamos el estatus
Dim message As String = root.Get("message")
End If
End If
Catch
Log(LastException)
End Try
End Sub
private Sub jobDone (job As HttpJob)
Try
Log(job.Success)
Log(job.GetString)
If (job.JobName == "CmdGetTicker") Then
Dim parser As JSONParser
parser.Initialize(job.GetString)
Dim root As Map = parser.NextObject
Dim result As Map = root.Get("result")
Dim Last As Double = result.Get("Last")
LastOld = LastNow
LastNow = Last
Dim Ask As Double = result.Get("Ask")
AskOld = AskNow
AskNow = Ask
Dim Bid As Double = result.Get("Bid")
BidOld = BidNow
BidNow = Bid
Dim success As String = root.Get("success")
status = success 'Set estatus
Dim message As String = root.Get("message")
End If
'Save Time
TimeOld = DateTime.Now
Catch
Log(LastException)
End Try
End Sub
public Sub Update
Try
If (TimeOld + 1000 < DateTime.Now) Then
Dim uri As String
uri = "https://bittrex.com/api/v1.1/public/getticker?apikey=" & API_Key & "&market=BTC-ETH"
SendCommand("CmdGetTicker", uri)
End If
Catch
Log(LastException)
End Try
End Sub