-
Mar 5th, 2020, 01:34 PM
#1
Thread Starter
New Member
How to connect to a REST-API from bitso.com
Hi everyone.
I'm a Freelance IT Enginner and currently have a job opportunity to develop a solution that requieres the connection to a RESP-API from bitso.com, a platform for cryptocurrency and trading.
I honestly have no experience on consuming remote services, so it is a little hard for me to figure out how to deal with this site requirements, furthermore, there is no documentation on how to accomplish this from C#/VB or the .NET Framework
I have read and found what I have to do to connect to the service, but it requires to proceed as follows:
--- copied from the developer site at https://bitso.com/api_info?php#generating-api-keys ---
Creating and Signing Requests
All REST requests should be valid JSON. You must include 3 fields as a payload in the “Authorization” header for all Private API Endpoints in order to perform authentication:
key – The API Key you generated
nonce – An integer that must be unique and increasing for each API call (we recommend using a UNIX timestamp)
signature – See below
Signature
The signature is generated by creating a SHA256 HMAC using the Bitso API Secret on the concatenation of nonce + HTTP method + requestPath + JSON payload (no Â’+Â’ signs in the concatenated string) and hex encode the output. The nonce value should be the same as the nonce field in the Authorization header. The requestPath and JSON payload must, of course, be exactly as the ones used in the request.
Authorization Header
The header should be constructed, using the fields described above, in the following form:
Authorization: Bitso <key>:<nonce>:<signature>
--- aside there is this code fragment in PHP ---
Code:
PHP Code:
<?php
$bitsoKey = "API_KEY";
$bitsoSecret = "API_SECRET"
$nonce = round(microtime(true) * 1000);
$HTTPMethod = "POST";
$RequestPath = "/v3/orders/";
$JSONPayload = json_encode(['book' => 'btc_mxn',
'side' => 'buy',
'major' => '.01',
'price' => '1000',
'type' => 'limit']);
// Create signature
$message = $nonce . $HTTPMethod . $RequestPath . $JSONPayload;
$signature = hash_hmac('sha256', $message, $bitsoSecret);
// Build the auth header
$format = 'Bitso %s:%s:%s';
$authHeader = sprintf($format, $bitsoKey, $nonce, $signature);
// Send request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.bitso.com/v3/orders/');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $JSONPayload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: ' . $authHeader,
'Content-Type: application/json'));
$result = curl_exec($ch);
echo $result;
?>
I know I have to CREATE this string using an especified format, using my bitso credentials and some other data, I know I need to use a JSON Library to create/read JSON Objects, what I don't know is, HOW TO send the HEADER to the remote service to SIGN my requests and start communicating with it?
Furthermore, how do I creathe this SHA256 HMAC within VB.NET ... is it either with HMACSHA256 Class or HMAC.Create Method?
For what I have researched, I have two options: HttpWebRequest Class or WebClient class, I have read that with HttpWebRequest Class I have more control that with WebClient class that is easier to use.
Hopefully you guys and guru's can throw a little light to my darkness, otherwise, there will be a very bumpy road ahead.
Thank you all.
-
Feb 26th, 2021, 03:56 PM
#2
Re: How to connect to a REST-API from bitso.com
VB6 CODE
Code:
Function HMACSHA256(strToSign As String, strKey() As Byte)
Dim lngLoop As Long
Dim oUTF, oEnc
Dim HMAC() As Byte
Dim lastrow As Long
On Error GoTo err_handler
Set oUTF = CreateObject("System.Text.UTF8Encoding")
Set oEnc = CreateObject("System.Security.Cryptography.HMACSHA256")
oEnc.Key = strKey
HMAC = oEnc.ComputeHash_2(oUTF.GetBytes_4(strToSign))
HMACSHA256 = HMAC
Exit Function
err_handler:
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|