Code covered by the BSD License  

Highlights from
BTC-e trade api

Be the first to rate this file! 29 Downloads (last 30 days) File Size: 12.4 KB File ID: #44890
image thumbnail

BTC-e trade api

by

 

02 Jan 2014 (Updated )

This BTC-e trade api can be used to automatically trade on btc-e using their api.

| Watch this File

File Information
Description

These matlab files will allow you to use all methods of the btc-e api. These include:
response = GetInfo()
response = TransHistory()
response = TradeHistory('count',2)
response = ActiveOrders()
response = Trade('pair','btc_usd','type','buy','rate',200,'amount',1)
response = CancelOrder('order_id',651389)
ticker_output = realtime_ticker('btc_usd');
The api makes use of a Key and a Secret, please insert your own key and secret
in the btce_call function to make the matlab files work.

The script makes use of the SHA512 algorithm to encode the api calls.

If you like the code, please consider to donate bitcoins to:
16FezyuqQonxc4sp9ft8nYLa9ST2HVM542

Questions or remarks? Post a comment.

Required Products MATLAB
MATLAB release MATLAB 8.0 (R2012b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
28 Jul 2014 wout

Matlab has problems with the SSL certificate from the btc-e site. Read the following if you are experiencing this error:

Java exception occurred:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

To solve the problem:
1) go to https://btc-e.com/ (this example is for firefox users but might work in other browsers as well)
2) click on the lock icon in the url bar
3) click on more info
4) click on view certificate
5) click on details
6) click on export
7) save the certificate in your matlab folder as .crt file (default), if correct the default filename is GoDaddyRootCertificateAuthority-G2
8) run the code as seen below, you might need to change the filename. (from http://www.mathworks.com/matlabcentral/answers/92506-can-i-force-urlread-and-other-matlab-functions-which-access-internet-websites-to-open-secure-websi)
9) when asked for permission, type: yes
10) restart matlab
11) everything should work correctly now

% Run this code after saving the function below
filename = 'GoDaddyRootCertificateAuthority-G2.crt';
importcert(filename)

% Save this function
function importcert(filename)
if (nargin == 0)
% If no certificate specified show open file dialog to select
[filename,path] = uigetfile({'*.cer;*.crt','Certificates (*.cer,*.crt)'},'Select Certificate');
if (filename==0), return, end
filename = fullfile(path,filename);
end
% Determine Java keytool location and cacerts location
keytool = fullfile(matlabroot,'sys','java','jre',computer('arch'),'jre','bin','keytool');
cacerts = fullfile(matlabroot,'sys','java','jre',computer('arch'),'jre','lib','security','cacerts');
% Create backup of cacerts
if (~exist([cacerts '.org'],'file'))
copyfile(cacerts,[cacerts '.org'])
end
% Construct and execute keytool
command = sprintf('"%s" -import -file "%s" -keystore "%s" -storepass changeit',keytool,filename,cacerts);
dos(command);

13 Jan 2014 wout

So you changed the btce_call.m function to something like:

appKey = 'AB6CDE54-AB6CDE54-AB6CDE54-AB6CDE54-AB6CDE54';
appSecret = 's5f646ea4eff5a1da5htt1nrt55er48ar4g456a4gre8ga4e6eaf5sf45ewe4665';

If thats done you should run btce_api_main.m Just type btce_api_main to your command window. This should give you a nice response. If this still gives the error, could you please copy paste the whole error output here? If this solves the problem, you can use your own function with (one of) the commands:

% response = GetInfo()
% response = TransHistory()
% response = TradeHistory('count',2)
% response = ActiveOrders()
% response = Trade('pair','btc_usd','type','buy','rate',200,'amount',1)
% response = CancelOrder('order_id',651389)
% ticker_output = realtime_ticker('btc_usd');

Don't try to call btce_api_main() in your own function, since this function does not return an output, but simply displays the response from the other function an is only used as an example to get you going.

12 Jan 2014 Height

Im receiving an error of a Maximum recursion limit reached for 500. how should i adjust the code to handle the recursion?
All Ive done was enter my key and secret to the btce_call.m function file.
anything else I need to do? could you lay out a few steps?
Thank you,
Eden
ps. will donate when i get this going...

Updates
03 Apr 2014

BTC-e changed their api url, this caused the script to stop working. This update will solve the issue.

03 Apr 2014

See update below.

Contact us