Pages:
Author

Topic: MtGox API version 2: Unofficial Documentation - page 8. (Read 62428 times)

sr. member
Activity: 246
Merit: 250
Nitrous, my fault. The fast ticker seem to work with EUR too. I got confused with last_all in the crowded debug console Wink

OT:

I'm actually building a simple trading bot myself if anybody is interested in participating to the beta test, PM me!  I already collected 15 volunteers + myself. Of course you should trust it with your life, but this bot here runs locally on your machine. you can see the code yourself and the API keys are stored locally on your machine Wink

Here you can see an example of the readme :> http://www.lize.it/up/prototype-botcoin/

This was how the node version looked like  it saved me from big price drops), now I'm doing it better with java.

If any suggestion , please add Grin

Have you got the JSON decoded yet? You could make debugging easier by pretty-printing it Smiley I've updated the documentation with my findings for the new method so hopefully that will be helpful - although I still haven't been able to test the differences during a high lag period.

That sounds interesting Smiley Does it generate the trading strategy automatically or is it user-programmable? I haven't been able to dedicate any large amounts of time to tradebot development but I was planning to incorporate some forex technical indicators, have a look at http://en.wikipedia.org/wiki/MACD for example. It seems fairly accurate (although there is a bit of lag), moreso than simple limit orders. I think bitcoin needs a trading platform to monitor forex technical indicators in order to make more informed trading decisions, especially with the high volatility, you could make a really powerful tool here Cheesy
sr. member
Activity: 267
Merit: 250
Woodwallets.io
Nitrous, my fault. The fast ticker seem to work with EUR too. I got confused with last_all in the crowded debug console Wink

OT:

I'm actually building a simple trading bot myself if anybody is interested in participating to the beta test, PM me!  I already collected 15 volunteers + myself. Of course you should trust it with your life, but this bot here runs locally on your machine. you can see the code yourself and the API keys are stored locally on your machine Wink

Here you can see an example of the readme :> http://www.lize.it/up/prototype-botcoin/

This was how the node version looked like  it saved me from big price drops), now I'm doing it better with java.

If any suggestion , please add Grin
sr. member
Activity: 246
Merit: 250
I put in an order of 10 btc at $90 even though I only had funds for 5.. the order completed and I don't think I had any orders outstanding - don't now anyway.

I'm guessing it just checked my balance and adjusted # of btc before placing the order.


That sounds likely, I guess it would confuse a lot of people if they just denied all orders over the current balance.
sr. member
Activity: 406
Merit: 250
I put in an order of 10 btc at $90 even though I only had funds for 5.. the order completed and I don't think I had any orders outstanding - don't now anyway.

I'm guessing it just checked my balance and adjusted # of btc before placing the order.
sr. member
Activity: 246
Merit: 250
I'm interested in an automated trading platform myself. Glad you did some compiling for the API at least.

I had a fairly strict trailing stop strategy, and was using it in the recent climb. However, because there is no way to enter dynamic stops & sleep is a requirement - for normal humans - I found myself waking up to the recent crash. Tongue

Anyway, maybe some automatic trading software could have helped. I didn't think there was a DDOS according to the MtGox report. Evenso, I think the stop would have been placed & executed before the peak velocity of the crash.

Anyone know of any available automated trading applications out there yet?

I'm sorry to hear that, that's really unlucky especially with your strategy! Did you lose a lot?

I have heard sporadic reports of user-friendly automated trading platforms for MtGox, but I'm not sure how much you can trust these. Look out for a MetaTrader extension, as MT is the norm for trading fiat forex currencies, and I think is quite easy to use. It's tailored for monitoring and auto trading, but I don't think there's any MtGox extension yet (or any other exchanges, for that matter). I was thinking of releasing a graphical client whilst I work on my own high frequency trader, but I don't currently have the time to do any major development (not for a couple months at least).

Do you know any programming languages? If not, maybe you could take this opportunity to learn one - you would then have full control over how it works (although you'd also be responsible for any money lost due to program failures Tongue).
sr. member
Activity: 246
Merit: 250
it's documented somewhere - last_all is last sale price in any currency converted to your specified currency, not sure difference between other 2 - not looking at documentation now Smiley


I have a question too - anyone know when buying through the api whether you're able to issue a buy at say 10 bitcoins at a specified price even if you only have funds for 5 ?

Just wondering if it will just buy the 5 - otherwise you have to do the calculations work out how many bitcoins you can buy.

--

edit: never mind, I tested it and you don't need to specify exact # of bitcoins to clean out your $ balance.


Don't rely on being able to buy however many btc you want even if unfunded, MtGox claims this is the source of a lot of lag and they are transitioning their engine to deny such requests.

Can you clarify what happened in your test? i.e: what you asked the api to do (how many and for how much), and what happened, and whether you still had an incomplete order pending afterwards or not?
sr. member
Activity: 246
Merit: 250
I have another question: in the ticker, what is the difference between last, last_all, last_local?

From what I can tell:
 - last and last_local are the same, and give the last trade of the selected currency
 - last_orig is the most recent trade of ALL currencies (so could be USD, GBP, EUR, anything...)
 - last_all is the same as last_orig, but it has been converted to the selected currency

As for ticker_fast, I imagine it was quickly put together so may have bugs in it. I just tested it now for BTCEUR and BTCUSD, however, and they both seemed to work and returned the same JSON properties, can you tell me what part seems not to work for EUR for you? Were you confused by last_orig being in USD?
hero member
Activity: 924
Merit: 506
I'm interested in an automated trading platform myself. Glad you did some compiling for the API at least.

I had a fairly strict trailing stop strategy, and was using it in the recent climb. However, because there is no way to enter dynamic stops & sleep is a requirement - for normal humans - I found myself waking up to the recent crash. Tongue

Anyway, maybe some automatic trading software could have helped. I didn't think there was a DDOS according to the MtGox report. Evenso, I think the stop would have been placed & executed before the peak velocity of the crash.

Anyone know of any available automated trading applications out there yet?
sr. member
Activity: 406
Merit: 250
it's documented somewhere - last_all is last sale price in any currency converted to your specified currency, not sure difference between other 2 - not looking at documentation now Smiley


I have a question too - anyone know when buying through the api whether you're able to issue a buy at say 10 bitcoins at a specified price even if you only have funds for 5 ?

Just wondering if it will just buy the 5 - otherwise you have to do the calculations work out how many bitcoins you can buy.

--

edit: never mind, I tested it and you don't need to specify exact # of bitcoins to clean out your $ balance.
sr. member
Activity: 267
Merit: 250
Woodwallets.io
I have another question: in the ticker, what is the difference between last, last_all, last_local?
sr. member
Activity: 267
Merit: 250
Woodwallets.io
Thank you nitrous Wink I'm reporting new findings here :

I'm currently using ticker_fast and it works pretty good, despite I'm not sure how. "BTCUSD/money/ticker_fast"

Works pretty good with USD, even though the answer is slightly different in the ordering:

Code:
Query to :BTCUSD/money/ticker_fast - HTTP response : 

{"result":"success","data":{"last_local":{"value":"77.60002","value_int":"7760002","display":"$77.60002","display_short":"$77.60","currency":"USD"},"last":{"value":"77.60002","value_int":"7760002","display":"$77.60002","display_short":"$77.60","currency":"USD"},"last_orig":{"value":"77.60002","value_int":"7760002","display":"$77.60002","display_short":"$77.60","currency":"USD"},"last_all":{"value":"77.60002","value_int":"7760002","display":"$77.60002","display_short":"$77.60","currency":"USD"},"buy":{"value":"77.61110","value_int":"7761110","display":"$77.61110","display_short":"$77.61","currency":"USD"},"sell":{"value":"77.61641","value_int":"7761641","display":"$77.61641","display_short":"$77.62","currency":"USD"},"now":"1366188127158506"}}
Query to :BTCUSD/money/ticker - HTTP response :

{"result":"success","data":{"high":{"value":"82.39000","value_int":"8239000","display":"$82.39000","display_short":"$82.39","currency":"USD"},"low":{"value":"53.61111","value_int":"5361111","display":"$53.61111","display_short":"$53.61","currency":"USD"},"avg":{"value":"68.58637","value_int":"6858637","display":"$68.58637","display_short":"$68.59","currency":"USD"},"vwap":{"value":"68.56407","value_int":"6856407","display":"$68.56407","display_short":"$68.56","currency":"USD"},"vol":{"value":"337373.36971644","value_int":"33737336971644","display":"337,373.36971644\u00a0BTC","display_short":"337,373.37\u00a0BTC","currency":"BTC"},"last_local":{"value":"77.60002","value_int":"7760002","display":"$77.60002","display_short":"$77.60","currency":"USD"},"last_orig":{"value":"77.60002","value_int":"7760002","display":"$77.60002","display_short":"$77.60","currency":"USD"},"last_all":{"value":"77.60002","value_int":"7760002","display":"$77.60002","display_short":"$77.60","currency":"USD"},"last":{"value":"77.60002","value_int":"7760002","display":"$77.60002","display_short":"$77.60","currency":"USD"},"buy":{"value":"77.60002","value_int":"7760002","display":"$77.60002","display_short":"$77.60","currency":"USD"},"sell":{"value":"77.61641","value_int":"7761641","display":"$77.61641","display_short":"$77.62","currency":"USD"},"item":"BTC","now":"1366188104561566"}}


Be careful with EUROS because is not working as expected, giving different values. I will stick to the normal ticker for now with euros (...):

Code:
Query to :BTCEUR/money/ticker - HTTP response : 

{"result":"success","data":{"high":{"value":"64.51361","value_int":"6451361","display":"64.51361\u00a0\u20ac","display_short":"64.51\u00a0\u20ac","currency":"EUR"},"low":{"value":"41.78000","value_int":"4178000","display":"41.78000\u00a0\u20ac","display_short":"41.78\u00a0\u20ac","currency":"EUR"},"avg":{"value":"52.17449","value_int":"5217449","display":"52.17449\u00a0\u20ac","display_short":"52.17\u00a0\u20ac","currency":"EUR"},"vwap":{"value":"53.49364","value_int":"5349364","display":"53.49364\u00a0\u20ac","display_short":"53.49\u00a0\u20ac","currency":"EUR"},"vol":{"value":"30454.26156026","value_int":"3045426156026","display":"30,454.26156026\u00a0BTC","display_short":"30,454.26\u00a0BTC","currency":"BTC"},"last_local":{"value":"60.72397","value_int":"6072397","display":"60.72397\u00a0\u20ac","display_short":"60.72\u00a0\u20ac","currency":"EUR"},"last_orig":{"value":"77.77699","value_int":"7777699","display":"$77.77699","display_short":"$77.78","currency":"USD"},"last_all":{"value":"59.24060","value_int":"5924060","display":"59.24060\u00a0\u20ac","display_short":"59.24\u00a0\u20ac","currency":"EUR"},"last":{"value":"60.72397","value_int":"6072397","display":"60.72397\u00a0\u20ac","display_short":"60.72\u00a0\u20ac","currency":"EUR"},"buy":{"value":"60.10000","value_int":"6010000","display":"60.10000\u00a0\u20ac","display_short":"60.10\u00a0\u20ac","currency":"EUR"},"sell":{"value":"60.72397","value_int":"6072397","display":"60.72397\u00a0\u20ac","display_short":"60.72\u00a0\u20ac","currency":"EUR"},"item":"BTC","now":"1366188316676566"}}
Query to :BTCEUR/money/ticker_fast - HTTP response :

{"result":"success","data":{"last_local":{"value":"60.22337","value_int":"6022337","display":"60.22337\u00a0\u20ac","display_short":"60.22\u00a0\u20ac","currency":"EUR"},"last":{"value":"60.22337","value_int":"6022337","display":"60.22337\u00a0\u20ac","display_short":"60.22\u00a0\u20ac","currency":"EUR"},"last_orig":{"value":"77.79000","value_int":"7779000","display":"$77.79000","display_short":"$77.79","currency":"USD"},"last_all":{"value":"59.25051","value_int":"5925051","display":"59.25051\u00a0\u20ac","display_short":"59.25\u00a0\u20ac","currency":"EUR"},"buy":{"value":"60.22337","value_int":"6022337","display":"60.22337\u00a0\u20ac","display_short":"60.22\u00a0\u20ac","currency":"EUR"},"sell":{"value":"60.73178","value_int":"6073178","display":"60.73178\u00a0\u20ac","display_short":"60.73\u00a0\u20ac","currency":"EUR"},"now":"1366188333851800"}}

 




sr. member
Activity: 246
Merit: 250
Glad you finally got it working, advanced. Clearly MikeH was paying closer attention  Wink
I was just giving the query as a string because I wanted to set it up quickly, using a HashMap is better.
sr. member
Activity: 406
Merit: 250
nice, unless you're a bitcoin miliionaire don't worry bout it Smiley
sr. member
Activity: 267
Merit: 250
Woodwallets.io
 Cool Where is your "donate to" address ? Cheesy

Thanks!  It was that! Now it works the ticker only with POST too Wink Yeeeeeeeeeeeeeeee
sr. member
Activity: 406
Merit: 250
the + "000" might be needed:

Code:
String nonce = "nonce=" + String.valueOf(System.currentTimeMillis()) + "000";

plus you probably need this before reading response:

Code:
DataOutputStream output = new DataOutputStream(c.getOutputStream());
            output.writeBytes(post_data);
            output.close();
sr. member
Activity: 267
Merit: 250
Woodwallets.io
Spotted another difference in my code (which doesn't seem to make a difference Sad ) :

Code:
connection.setRequestProperty("Rest-Sign", signature.replaceAll("\n", ""));
sr. member
Activity: 267
Merit: 250
Woodwallets.io
yes its ugly and it doesn't work I don't understand why.

if you want to see how it looks like at the moment : http://pastebin.com/4UZWYZix . Maybe another pair of eye can help me in finding what should be something really small and stupid compared to this which work http://pastebin.com/SmrxuJQj
sr. member
Activity: 406
Merit: 250
doesn't help that I've only done a bit of maintenance of java code but are you doing the following for the post?  seems this 'content' i'm referring is sent afterwards via DataOutputStream.

so ugly compared to perl.. may as well be using C Smiley

Code:
String urlParameters = "param1=a¶m2=b¶m3=c";
String request = "http://example.com/index.php";
URL url = new URL(request);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();          
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setUseCaches (false);

DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
connection.disconnect();
sr. member
Activity: 406
Merit: 250
I see in the pastebin java code that this is being assigned:

Code:
String post_data = this.buildQueryString(args);

but not used except as part of 'Rest-Sign'


Code:
$req->content($nonce . $args);

$hash_data = $method . chr(0) . $nonce . $args;
$req->header('Rest-Sign' => encode_base64( hmac_sha512( $hash_data, decode_base64($secret) ) ));

notice the nonce and args are being used in both 'Rest-Sign' and 'content' - this content is needed with POST but not GET where it forms part of the url.
sr. member
Activity: 267
Merit: 250
Woodwallets.io
I ran your code, inspected it line by line, tried to go back to deprecated Base64 functions, but nothing.

The only difference I was able to spot is the way you (don't) encode the post data arguments. I'm trying to use this function to add the arguments, which maybe does something weird to the request . I don't see how anyway :


Here is how I call the query and add the argument :


Code:
        String urlPath = "money/info";
        HashMap query_args = new HashMap<>();  
        String queryResult = query(urlPath, query_args);

Code:
 public String query(String path, HashMap args) {
.//here args should be empty
.
.
  args.put("nonce", nonce);        
//here the nonce is added to the args
  String hash_data = path + "\0" + this.buildQueryString(args);
//here the nonce should be added to hash_data: indeed if I print I have money/info◙nonce=1366110562837
.
.
.
}


And below is the function buildQueryString


Code:
   //Build the query string given a set of query parameters
     protected String buildQueryString(HashMap args) {
        String result = new String();
        for (String hashkey : args.keySet()) {
            if (result.length() > 0) result += '&';
            try {
                result += URLEncoder.encode(hashkey, "UTF-8") + "="
                        + URLEncoder.encode(args.get(hashkey), "UTF-8");
            } catch (Exception ex) {
                Logger.getLogger(MtGox.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return result;
    }


I wonder if is something related to the ◙  symbol, but I see it in your hash_data as well!


EDIT: nope, I tried to build the string manually and I get the same damn 'missing nonce' error.
Pages:
Jump to: