SHARE
TWEET

C++/CLI Library for BTC-E.com Trade API




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- // ------------------------------------------------
- //
- // C++/CLI Library for BTC-E.com Trade API
- // https://btc-e.com/api/documentation
- //
- // Version : 1.0
- // Compiler: VS2012 RC
- // Author : PoorGirl
- //
- // Donation BTC: 1PuH16ozFyTxs5zHCfJciL24BU2ihYZ1s5
- // Donation LTC: LRhVLjKBmyyK88XRbrq1jv3Y5Wc5fghT3K
- //
- // Credits: DmT
- //
- // ------------------------------------------------
- using namespace System;
- using namespace System::Text;
- using namespace System::Net;
- using namespace System::Security::Cryptography;
- using namespace System::IO;
- namespace BTCEBOT
- {
- static ref class btc_e_api
- {
- private: static String^ key;
- private: static String^ secret;
- public: static void Init(String^ api_key, String^ api_secret)
- {
- key = api_key;
- secret = api_secret;
- }
- private: static String^ GetInfo()
- {
- return "method=getInfo";
- }
- private: static String^ GetNonce()
- {
- TimeSpan t1 = (DateTime::UtcNow - DateTime(1970, 1, 1, 0, 0, 0));
- Int64^ UnixTimeNow = safe_cast<System::Int64>(t1.TotalSeconds);
- return "nonce=" + UnixTimeNow;
- }
- public: static String^ Check()
- {
- String^ dataStr = GetInfo() + "&" + GetNonce();
- array<Byte>^ data = Encoding::ASCII->GetBytes(dataStr);
- WebRequest^ request = WebRequest::Create("https://btc-e.com/tapi");
- try
- {
- request->Method = "POST";
- request->Timeout = 10000;
- request->ContentType = "application/x-www-form-urlencoded";
- request->ContentLength = dataStr->Length;
- request->Headers->Add("Key", key);
- // MAKE SIGN
- System::Text::ASCIIEncoding^ encoding = gcnew System::Text::ASCIIEncoding();
- array<Byte>^ keyByte = encoding->GetBytes(secret);
- HMACSHA512^ hmacsha512 = gcnew HMACSHA512(keyByte);
- array<Byte>^ messageBytes = encoding->GetBytes(dataStr);
- array<Byte>^ hashmessage = hmacsha512->ComputeHash(messageBytes);
- String^ s2 = BitConverter::ToString(hashmessage);
- s2 = s2->Replace("-", "");
- s2 = s2->ToLower();
- request->Headers->Add("Sign", s2);
- // PREPARE POST
- Stream^ reqStream = request->GetRequestStream();
- reqStream->Write(data, 0, data->Length);
- reqStream->Close();
- // SEND POST
- WebResponse^ response = request->GetResponse();
- Stream^ resStream = response->GetResponseStream();
- StreamReader^ resStreamReader = gcnew StreamReader(resStream);
- String^ result = resStreamReader->ReadToEnd();
- return result;
- }
- catch(Exception^ e)
- {
- delete e; // POST FAILED
- }
- }
- };
- }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.