Po zastosowaniu takiego kodu:
procedure TForm1.Button2Click(Sender: TObject);
var
http : TIdHTTP;
iossl : TIdSSLIOHandlerSocketOpenSSL;
post : TIdMultiPartFormDataStream;
s : string;
const
link = 'https://pln.bitcurex.com/api/0/';
begin
http := TIdHTTP.Create(nil);
post := TIdMultiPartFormDataStream.Create;
iossl := TIdSSLIOHandlerSocketOpenSSL.Create(http);
iossl.SSLOptions.Method := sslvSSLv3;
http.IOHandler := iossl;
http.ReadTimeout := 3000;
post.AddFormField('nonce', 'getFunds');
s := http.Post(link, post);
memo1.Text := s;
end;
Pokazuje mi się komunikat socket error # 0. Generalnie jak tylko użyję funkcji post to taki komunikat się pojawia. Przy wpisaniu tego adresu w get otrzymuję:
{"methods":[{"name":"getFunds","post":"nonce=#","result":"funds"},{"name":"getOrders","post":"nonce=#","result":"funds and orders"},{"name":"buyBTC","post":"nonce=#&amount=#&price=#","result":"funds and orders"},{"name":"sellBTC","post":"nonce=#&amount=#&price=#","result":"funds and orders"},{"name":"cancelOrder","post":"nonce=#&oid=#&type=#","result":"funds and orders"},{"name":"getTransactions","post":"nonce=#","result":"last 100 transactions"},{"name":"withdraw","post":"nonce=#&type=#&amount=#","result":"funds"}]}
Nie wiem czy to coś z moim kodem czy trzeba jakoś podać ten swój klucz API prywatny
--------------------- Dodano później ;)
Znalazłem taki kod w pythonie (z czym nigdy odczynienia nie miałem) który mnie nakierował na to, że dane logowania muszą być w nagłówku. Problem w tym, że nie wystarczy zwykłe podanie prywatnego klucza a jakieś kombinacje z HMAC o którym pierwszy raz słyszę. Ma ktoś jakiś pomysł jak to w delphi zaimplementować?
import math
import time
import simplejson
import urllib
import urllib2
import hmac,hashlib
def microtime():
return '%f %d' % math.modf(time.time())
def query( path, key, secret, data={} ):
mt = microtime().split()
nonce = mt[1] + mt[0][2:]
data['nonce'] = nonce
post_data = urllib.urlencode( data )
sign = hmac.new( secret.decode('base64'), post_data, hashlib.sha512 ).digest()
headers = {'Rest-Key' : key,
'Rest-Sign': sign.encode('base64').strip(),
'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
'Content-type': 'application/x-www-form-urlencoded'}
print headers
url = 'https://bitcurex.com/api/0/' + path
req = urllib2.Request( url, post_data, headers )
response = urllib2.urlopen(req)
return simplejson.loads(response.read())
print query('getFunds', '29a28e8fe234537056a8b256c0df50413f50da9c49ca61991ea8b8f108a88e09', 'y2NDxKGa/xvhtXrDP+3oscbBUFSac9+T8jzu2nRmt0vBdHbbl8NRqdmxKFr2IwwY5LAskTQZGyy2XONaNN6Jrg==')
Generalnie cały mój kod (nie ten wyżej) działa chyba poprawnie bo zwraca informację o potrzebie zalogowania tylko całe to mixowanie klucza prywatnego jest dla mnie czarną magią :(
Tutaj link do strony gdzie kod znalazłem: http://stackoverflow.com/questions/13893824/translating-php-to-python-rest-api-connection