ROBERT MECHLER
asked on
Convert Python script to C# including libraries
Access to Rest API in Python working but would prefer a C# translation.
import requests
import json
import base64
import hmac
import hashlib
import datetime, time
url = "https://api.gemini.com/v1/balances"
gemini_api_key = "master-xxxxxxxxxxxxxxxxx"
gemini_api_secret = "xxxxxxxxxxxxxxxxxx".encode()
t = datetime.datetime.now()
payload_nonce = str(int(time.mktime(t.timetuple())*1000))
payload = {"request": "/v1/balances","nonce": payload_nonce,"account": "xxxx-xxxxx-xxxxxx"}
encoded_payload = json.dumps(payload).encode()
b64 = base64.b64encode(encoded_payload)
signature = hmac.new(gemini_api_secret, b64, hashlib.sha384).hexdigest()
request_headers = {
'Content-Type': "text/plain",
'Content-Length': "0",
'X-GEMINI-APIKEY': gemini_api_key,
'X-GEMINI-PAYLOAD': b64,
'X-GEMINI-SIGNATURE': signature,
'Cache-Control': "no-cache"
}
response = requests.post(url, headers=request_headers)
my_balance = response.json()
print(my_balance)
Pyton to C# conversion: https://pythoncsharp.com
Pyton to C# conversion: https://pythoncsharp.com
previously tried this online converter and the generated code didn't work at all.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.