Pages:
Author

Topic: I Need a Newbs Noob Guide to Accessing the Mt Gox API (Read 4607 times)

hero member
Activity: 728
Merit: 500
Thanks, working on this in my spare time so it may be a bit. I will report back.
hero member
Activity: 532
Merit: 500
Here is a site that explains and also makes a cron job:

http://htmlbasix.com/crontab.shtml
hero member
Activity: 532
Merit: 500

Right now I am trying to get the grab ticker "command" function to repeat once a minute... Then figure out how to only display the last price from the ticker.


You need to set up a cron.  I don't know how to do that in Windows.  But in unix-like system it is easy.  First you need to make an Rscript.  This is just a file saying what you want R to do in a .R format.  It would be cool to have it make a tweet with the current ticker.  There is the twitteR package.  I was playing around with this before.

Also, you could try just have R run in a loop.  Have R run the ticker function, print out the data, then have it wait x seconds and do it again.

I think adding a tweet or email using a cron job is better.  Let me know if you need help with the cron setup.

to do the last price:

Code:
     x <- MT.BTCUSD()
      x$last
      [1] 4.4639
hero member
Activity: 532
Merit: 500
yea I figured that out. Right now I am trying to get the grab ticker "command" to repeat once a minute. Revalin's code didn't work for me. Then figure out how to only display the last price from the ticker.

Do you know why R crashes if I don't include useragent= "R"?

*well I should say I don't really get the make.dataframe part yet


Yea that is interesting about it crashing.  There is a short thing about it on the RCurl FAQ.
hero member
Activity: 728
Merit: 500
yea I figured that out. Right now I am trying to get the grab ticker "command" to repeat once a minute. Revalin's code didn't work for me. Then figure out how to only display the last price from the ticker.

Do you know why R crashes if I don't include useragent= "R"?

*well I should say I don't really get the make.dataframe part yet
hero member
Activity: 532
Merit: 500
How do I alter the mt gox script to give me ticker price as well? Like I said I am a newb's noob.

Code:
MT.BTCUSD = function ( ) {
tickMTGXurlBTCUSD = "https://mtgox.com/api/0/data/ticker.php"
y = fromJSON(getURLContent( tickMTGXurlBTCUSD, ssl.verifypeer = FALSE, useragent = "R") )
y = do.call(rbind,lapply(y,as.data.frame))
return(y)
}

MT.BTCUSD()


This will return a data frame

Code:
       high    low      avg     vwap    vol last_all last_local    last     buy  sell
ticker 4.74 4.2611 4.447009 4.453705 101154  4.46499    4.46499 4.46499 4.46218 4.464

If you ever make some money off of this, leave a tip.
hero member
Activity: 532
Merit: 500


        install.packages("RCurl")
        install.packates("RJSONIO")
        require(RCurl)
        require(RJSONIO)

        #### Make a function to get the MtGox depth, returns a list of the ask and bids in a data frame format
        MT.BTCUSDdepth = function ( ) {
             tickMTGXurlBTCUSD = "https://mtgox.com/api/0/data/getDepth.php?Currency=USD"
             y = fromJSON(getURLContent( tickMTGXurlBTCUSD, ssl.verifypeer = FALSE, useragent = "R") )
             ask = as.data.frame(matrix(unlist(y$ask),ncol=2,byrow=T))
             colnames(ask) = c("ask","amount")
             bid = as.data.frame(matrix(unlist(y$bid),ncol=2,byrow=T))
             colnames(bid) = c("bid","amount")
             list(ask=ask,bid=bid)
             }

         y = MT.BTCUSDdepth() #returns the depth and stores it in the object 'y'



BTW, I figured out why I had to install the RJSONIO package manually

You can also use rjson.

Either one is fine.
hero member
Activity: 728
Merit: 500


        install.packages("RCurl")
        install.packates("RJSONIO")
        require(RCurl)
        require(RJSONIO)

        #### Make a function to get the MtGox depth, returns a list of the ask and bids in a data frame format
        MT.BTCUSDdepth = function ( ) {
             tickMTGXurlBTCUSD = "https://mtgox.com/api/0/data/getDepth.php?Currency=USD"
             y = fromJSON(getURLContent( tickMTGXurlBTCUSD, ssl.verifypeer = FALSE, useragent = "R") )
             ask = as.data.frame(matrix(unlist(y$ask),ncol=2,byrow=T))
             colnames(ask) = c("ask","amount")
             bid = as.data.frame(matrix(unlist(y$bid),ncol=2,byrow=T))
             colnames(bid) = c("bid","amount")
             list(ask=ask,bid=bid)
             }

         y = MT.BTCUSDdepth() #returns the depth and stores it in the object 'y'



BTW, I figured out why I had to install the RJSONIO package manually
hero member
Activity: 532
Merit: 500
How do I alter the mt gox script to give me ticker price as well? Like I said I am a newb's noob.

Code:
* * * * * curl -q https://mtgox.com/api/0/data/ticker.php > `date +mtgox-ticker-%F--%T`

+1 for R.  The language itself isn't anything special; languages like Python, Ruby and Perl are much more fun.  The reason for R is it has an immense library of high-quality statistics functions.  I suggest the rkward GUI to get started.

R also has libraries for financial indicator and strategy testers.

See quantmod (available on CRAN) and quantstrat (available on R-Forge).
hero member
Activity: 728
Merit: 500
165YUuQUWhBz3d27iXKxRiazQnjEtJNG9g
How do I alter the mt gox script to give me ticker price as well? Like I said I am a newb's noob.

Code:
* * * * * curl -q https://mtgox.com/api/0/data/ticker.php > `date +mtgox-ticker-%F--%T`

+1 for R.  The language itself isn't anything special; languages like Python, Ruby and Perl are much more fun.  The reason for R is it has an immense library of high-quality statistics functions.  I suggest the rkward GUI to get started.
hero member
Activity: 728
Merit: 500
How do I alter the mt gox script to give me ticker price as well? Like I said I am a newb's noob.
hero member
Activity: 532
Merit: 500
Will do. I need to mess around for a bit though. By authentication you mean user and pass verification?

Yes, but MtGox uses a new authentication that requires a public and private key.  It is not basic authentication like Bitcoinica uses.
hero member
Activity: 728
Merit: 500
Will do. I need to mess around for a bit though. By authentication you mean user and pass verification?
hero member
Activity: 532
Merit: 500
Ah, excellent I have been messing around with R on and off over the last few months and have access to a few people with lots of experience. Thanks, I will let you know how it goes.

I translated Bitcoinica's whole API into R.  You can get the code here.

I have been having trouble getting authentication to work in R.  Let me know if those people with R experience are able to help.
hero member
Activity: 728
Merit: 500
Ah, excellent I have been messing around with R on and off over the last few months and have access to a few people with lots of experience. Thanks, I will let you know how it goes.
hero member
Activity: 532
Merit: 500
So I would like to start sampling and saving the mt gox order book and price info for analysis. I am able to gather the trade history using slush's sierrachartfeed script, but no orderbook info.

The most complicated thing I have ever programmed was a perl script that asked for username and password then attempted to play blackjack with you and failed.

It would be most convenient if this would work on windows xp, but I can install some linux distro if recommended.

Also what is the forum code to make my links like this (html example):
Code:

What kind of analysis do you want to do?

I'm not positive yet. I just love input/data. In general, look for patterns in the behavior of the price and order book before large movements.

You should work with R then.  It was designed for analyzing large data sets.

Once you open it up you  have to install two packages. (I have not tested this in Windows, only in Linux and Mac).

Code:
        install.packages("RCurl")
        install.packages("RJSONIO")
        # install.packages("rjson") #also an option
        require(RCurl)
        require(RJSONIO)
        # require(rjson)

        #### Make a function to get the MtGox depth, returns a list of the ask and bids in a data frame format
        MT.BTCUSDdepth = function ( ) {
             tickMTGXurlBTCUSD = "https://mtgox.com/api/0/data/getDepth.php?Currency=USD"
             y = fromJSON(getURLContent( tickMTGXurlBTCUSD, ssl.verifypeer = FALSE, useragent = "R") )
             ask = as.data.frame(matrix(unlist(y$ask),ncol=2,byrow=T))
             colnames(ask) = c("ask","amount")
             bid = as.data.frame(matrix(unlist(y$bid),ncol=2,byrow=T))
             colnames(bid) = c("bid","amount")
             list(ask=ask,bid=bid)
             }

         y = MT.BTCUSDdepth() #returns the depth and stores it in the object 'y'



To inspect the data you can do a lot of different things in R.  There are a lot of user guides as R is an open source community.  But to get started you can call the bid and ask objects by typing in R:

Code:
          y$bid
          y$ask

EDIT:  fixed the typ.
legendary
Activity: 1137
Merit: 1001
Sooner or later you'll have to learn a lot before you can do something useful with that much data.  Smiley

But let me give you some leads to explain what that last thing meant.

Cron is the task scheduler for Unix.  Lots about that here: https://en.wikipedia.org/wiki/Cron

The * * * * * means to run something every minute.

curl is a simple http client.  It grabs the web page and spits it to stdout.  https://en.wikipedia.org/wiki/CURL

> means to redirect stdout to a file.

putting stuff in backticks ` ` means to run the command inside and then put the result on the command line.

running "date +mtgox-%F--%T" outputs:  mtgox-2012-02-16--00:30:53

So the actual command that gets run looks like:

curl https://mtgox.com/api/0/data/getDepth.php > mtgox-2012-02-16--00:30:53

To set up the cron job, run "crontab -e".  An editor will come up, and you paste in the line:

* * * * * curl -q https://mtgox.com/api/0/data/getDepth.php > `date +mtgox-%F--%T`

(I added a -q so curl won't output progress messages on stderr; otherwise they would be emailed to you with every run)

Go install Linux somewhere (you can install it in a VirtualBox VM if you don't have a spare computer), try it out, and let me know if you get stuck.

Thanks for doing this. I can read the man pages, but this is easier for me to understand.
hero member
Activity: 728
Merit: 500
So I would like to start sampling and saving the mt gox order book and price info for analysis. I am able to gather the trade history using slush's sierrachartfeed script, but no orderbook info.

The most complicated thing I have ever programmed was a perl script that asked for username and password then attempted to play blackjack with you and failed.

It would be most convenient if this would work on windows xp, but I can install some linux distro if recommended.

Also what is the forum code to make my links like this (html example):
Code:

What kind of analysis do you want to do?

I'm not positive yet. I just love input/data. In general, look for patterns in the behavior of the price and order book before large movements.
hero member
Activity: 532
Merit: 500
So I would like to start sampling and saving the mt gox order book and price info for analysis. I am able to gather the trade history using slush's sierrachartfeed script, but no orderbook info.

The most complicated thing I have ever programmed was a perl script that asked for username and password then attempted to play blackjack with you and failed.

It would be most convenient if this would work on windows xp, but I can install some linux distro if recommended.

Also what is the forum code to make my links like this (html example):
Code:

What kind of analysis do you want to do?
hero member
Activity: 728
Merit: 500
165YUuQUWhBz3d27iXKxRiazQnjEtJNG9g
Sooner or later you'll have to learn a lot before you can do something useful with that much data.  Smiley

But let me give you some leads to explain what that last thing meant.

Cron is the task scheduler for Unix.  Lots about that here: https://en.wikipedia.org/wiki/Cron

The * * * * * means to run something every minute.

curl is a simple http client.  It grabs the web page and spits it to stdout.  https://en.wikipedia.org/wiki/CURL

> means to redirect stdout to a file.

putting stuff in backticks ` ` means to run the command inside and then put the result on the command line.

running "date +mtgox-%F--%T" outputs:  mtgox-2012-02-16--00:30:53

So the actual command that gets run looks like:

curl https://mtgox.com/api/0/data/getDepth.php > mtgox-2012-02-16--00:30:53

To set up the cron job, run "crontab -e".  An editor will come up, and you paste in the line:

* * * * * curl -q https://mtgox.com/api/0/data/getDepth.php > `date +mtgox-%F--%T`

(I added a -q so curl won't output progress messages on stderr; otherwise they would be emailed to you with every run)

Go install Linux somewhere (you can install it in a VirtualBox VM if you don't have a spare computer), try it out, and let me know if you get stuck.
Pages:
Jump to: