Author

Topic: EasyMTGox - simple .NET API-wrapper for MTGox (Read 1444 times)

newbie
Activity: 32
Merit: 0
For all the C# devs around here: This is the basic code to use the API as of today.

        public static string GetBalance(string userName, string password)
        {
            // parameters: name1=value1&name2=value2
            var parameters = "name=" + HttpUtility.UrlEncode(userName)
                 + "&pass=" + HttpUtility.UrlEncode(password);

            var req = (HttpWebRequest) WebRequest.Create("https://mtgox.com/code/getFunds.php");

            req.ContentType = "application/x-www-form-urlencoded";
            req.Method = "POST";
            req.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
            req.Accept = "application/json";

            byte[] bytes = Encoding.ASCII.GetBytes(parameters);
            req.ContentLength = bytes.Length;

            Stream os = req.GetRequestStream();
            os.Write(bytes, 0, bytes.Length);
            os.Close();

            WebResponse resp = req.GetResponse();

            try
            {
                var sr = new StreamReader(resp.GetResponseStream());
                return sr.ReadToEnd().Trim();
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex.Message);
                Logger.FatalException(ex.InnerException.ToString(), ex);   
                return null;
            }
        } // end HttpPost


As this may become out of date pretty much any moment, also look out for comments by "SlipperySlope" on how to do it in Java. The only change you have to make is that whenever we writes that he is using HtmlEncoding, in C# the UrlEncoding is needed.


Cheers
txcoin

PS: Thus, no need to run a dubious exe and pay fees to anyone obsfuscating his code without reason. We are a community.
newbie
Activity: 28
Merit: 0
Nice to see .NET developers in here... Don't you want to make a WPF/Silverlight app as example? Tongue

+1 on seeing other .NET devs here.

As to the OP, not too sure why people would pay for a wrapper that anyone proficient in C# can write within 30 minutes.

I think the value add would be a Silverlight/WPF frontend as Maxim said

Fully, agree. But I think community don't need new MtGox watcher in .NET... We need normal Client with all necessary watchers and trackers and, of course, sexy UI...
newbie
Activity: 21
Merit: 0
Nice to see .NET developers in here... Don't you want to make a WPF/Silverlight app as example? Tongue

+1 on seeing other .NET devs here.

As to the OP, not too sure why people would pay for a wrapper that anyone proficient in C# can write within 30 minutes.

I think the value add would be a Silverlight/WPF frontend as Maxim said
newbie
Activity: 28
Merit: 0
Nice to see .NET developers in here... Don't you want to make a WPF/Silverlight app as example? Tongue
sr. member
Activity: 350
Merit: 250
Everyone can host a program on Webspace from his University. This is not a guarantee for trust.

Anyway good job and good luck but personally i not will use your program to pay to you a fee when i can make a transactions directly from their website. Other question is that I will ever use a MTGox. They have a too many hacks in last month.
full member
Activity: 131
Merit: 100
With EasyMTGox you can access MTGox from inside you own .NET Application!

In the Download is a Sampleapplication that shows nearly everything that can be done! (trader.exe)

http://www-user.tu-chemnitz.de/~rimarc/wordpress/easymtgox-simple-net-api-wrapper-to-mtgox/

Its as easy as a Hello World:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EasyMTGoxNS;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(”Lastprice:” + EasyMTGox.GetTickerData().LastPrice.ToString()+”USD/BTC”);
Console.WriteLine(”Input your username”);
string Username = Console.ReadLine();
Console.WriteLine(”Input your Password:”);
string Password = Console.ReadLine();

EasyMTGox EMTGOX = new EasyMTGox(Username, Password);
if (EMTGOX.IsConnectionFine())
{

Balance Balance = EMTGOX.GetBalance();
Console.WriteLine(”You have ” + Balance.BTC + “BTC” + ” and ” + Balance.USD + “USD”);

Console.WriteLine(”How many BTC do you want to buy?”);
string amount = Console.ReadLine();
Console.WriteLine(”Maximum price you want to pay per BTC in USD?”);
string price = Console.ReadLine();
EMTGOX.BuyBTCOrder(amount, price);
}

else
{
Console.WriteLine(”Something went wrong! Check Username Password and Internetconnection!”);
}
Console.ReadLine();
}
}
}

This little Programm shows the Last Price on MTGox and you can send an order to buy BTC!
All the API Functions are included! Get the DepthOfMarket, your open Orders, the Ticker, delet Orders!
Its not Freeware!!! You have to Pay 0.01BTC fee per Trade with a probability. Thats 0.01BTC in any case for 100 and more BTC trades.
If you send an Order over 50BTC you have to pay the fee with probability of 50%. If you trade 1 BTC, you have to pay the Fee with 1% and so on. You never have to pay more than 0.01BTC per order.

There are many Events that get trickert too, so you can write an Eventdriven Programm too. Everything that can be done Wthout an MTGox Account uses static functions.


I know, i have no reputation. But i can tell you, iam Hosting this Programm on the Webspace from my University. So i am not Anonym.

What do you think?
Jump to: