How does a bike or why I wrote a client for exchange

I Think many of you can say to yourself "Two years ago I didn't believe in Bitcoin, so not bought. A year ago, I thought — well, now just collapse and not bought...". You are not alone.

A month ago, I finally decided and bought coins on one of the exchanges. What was my surprise when bought at 4$ coins, steel stand 40$.

But this post is not about that.

Foreword

I started with a small analysis of the market, which led me to the conclusion — "LTC has potential, at least he is attractive to speculators. Enough — high income at low cost. For games with BTC, now we need much more investment. Nothing of course last December I started mine LTC, or at least not purchased."

So I took the plunge, bought a few coins, watching the rate fluctuations for speculative game, strategy and tactics of the big players. Gradually began to get involved in the kitchen cryptocurrency. It's hard to give any specific advice, but:
— Never rush.
— You should not panic.
— Not to burn your nerves, you need to determine in advance what you will do with a particular part of the assets.

down to business

After two weeks passed epileptic seizures when collapses on the stock exchange, I chose the tactics of behavior. Part of the assets of the long-term, and the other part to play in the market. I found I felt comfortable enough to use exchange. The website allowed them to monitor the situation on various currency pairs, quickly to bid and make a profit. Gambling in such a short period of time has become something like a go in your spare time at ... and read the news. It was easy to do when the next PC, but the courses could fluctuate significantly at any time of the day, I needed control over assets and information on the state of the market. I started to look for a client for Android, but one that I found was not very comfortable, looked rather clumsy. It was therefore decided, in his spare time to make your customer. Yes, I love bikes, this is my hobby.

Working with an API and Open Source contribution

Have selected for the trading market has its own API, it is quite easy to use. There are public and private API. The first to receive market indicators, second trades and request information about the user. Data is provided in JSON format. I have written some Java classes as a layer, for API, they will all be published in my profile on github.

Example of code for obtaining information for a currency pair, just type in:
the
BTCeTicker.getTicker(pair);

This will return you a JSON object, like this:
the
{
"ticker":{
"high":1021,
"low":928.09998,
"avg":974.54999,
"vol"15334566.88449,
"vol_cur":15600.23488,
"last":996.001,
buy:999.995,
"sell":996.093,
"updated":1386107758,
"server_time":1386107759
}
}

Then sending this object to another method in the same class, we can obtain any desired value.
For example, get the last transaction price
the
BTCeTicker.getLast(Ticker);

I think came out quite well and transparently. The issues is that the naming of the classes in my project, but let it remain on my conscience. Let me remind you, classes for working with the API of the exchange, I'll post a bit later on github.

After all the classes for working with the API was written, it remains the case for small, to customize the appearance of their application, to put a skeleton on previously written code as follows to test, and put on public display in the network. Actually here's what happened:

Screenshots

Home applications courses:
image

The page of currency pairs:


Immersive mode for Android 4.4 + action bar on the bottom:
image image
Transactions history:


Motivating purchase free version

Available in free and paid version of the app. The differences of the free version:
— No restrictions, it is fully functional.
— No ads.
— From 14 days of use, the free version when you run will say that it is free. This is the only difference from the paid one.

It looks like this:


Let me explain, the timer counts down 15 seconds, the remaining number of seconds is seen on the close button, then close button becomes active and you can work with the application in normal mode. If your nerves cannot stand, perhaps you will buy the paid version or simply uninstall the free.

For this behavior, we wrote a small method which is called at startup. He puts a tag of type long and writes it in SharedPreferences, then with each run verifies if the difference is more than 14 days, that displays AlertDialog.
the
public static void checkTrial(){
FIRST_RUN = prefs.getLong("FIRST_RUN",0);
if(FIRST_RUN==0){
prefs.edit().putLong("FIRST_RUN", System.currentTimeMillis()).commit();
FIRST_RUN = prefs.getLong("FIRST_RUN",0);
}
CURRENT_TIME = System.currentTimeMillis();

if(CURRENT_TIME/1000 - FIRST_RUN/1000 > 1209600){
AlertDialog.Action_dialog Builder = new AlertDialog.Builder(bm_MainContext);
action_dialog.setTitle(R. string.about));
LayoutInflater inflater = bm_MainState.getLayoutInflater();
Layer View = inflater.inflate(R. layout.trial,null);

final Button btnCancel = (Button) layer.findViewById(R. id.btnCancelTrial);
BtnBuyApp Button = (Button) layer.findViewById(R. id.btnAppBuy);

btnCancel.setEnabled(false);
btnBuyApp.setText(R. string.close + " (15)");

action_dialog.setCancelable(false);
action_dialog.setView(layer);

final AlertDialog AboutDialog = action_dialog.create();

btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AboutDialog.dismiss();
}
});
btnBuyApp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=com.zlab.btcmonitor");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
bm_MainState.startActivity(intent);
}
});
AboutDialog.show();

Thread thread = new Thread()
{
@Override
public void run() {
int i=14;
while(i>0){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
final int c=i;
runOnUiThread(new Runnable() {
@Override
public void run() {
btnCancel.setText(R. string.close) + " ("+c+")"); }});
i--;
}
runOnUiThread(new Runnable() {
@Override
public void run() {
btnCancel.setText(R. string.close);
btnCancel.setEnabled(true);}});}
};
thread.start();
}
}

Source code for this plot is slightly modified so as not to appear too bloated. In the IDE it looks nicer than here.
If you are even more ignorant of Java and Android than I do, perhaps you'll appreciate this piece of code.

Links

Paid version:
image

Free version:
image

p.s.: and so was born my next bike.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Why I left Google Zurich

2000 3000 icons ready — become a sponsor! (the table of orders)

New web-interface for statistics and listen to the calls for IP PBX Asterisk