📜 ⬆️ ⬇️

How a bicycle is born or why I wrote a client for the exchange

I think many of you can say about yourself “Two years ago I did not believe in Bitcoin, so I did not buy it. A year ago, I thought - well, now it’s definitely a collapse and I did not buy ... ” You are not alone.

A month ago, I still decided and bought coins on one of the exchanges. What was my surprise when the coins bought at $ 4 began to cost $ 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 it is attractive for speculators. Little cost - high income at low cost. To play with BTC now you need a lot more investment. In vain, of course, last December I did not start mining LTC, or at least I did not buy it. ”

So I made up my mind, bought some coins, watched course fluctuations, speculative game, tactics and strategy of big players. He began to gradually get into the kitchen cryptocurrency. It's hard to give some definite advice, but:
- You can never hurry.
- You can not panic.
- In order not to burn your nerves, you need to decide in advance what you will do with one or another part of the assets.

Closer to the point

After two weeks there were epileptic seizures with collapses on the stock exchange, I chose my tactics of behavior. Part of the assets of long-term, and the other part for the game on the market. I found it seemed to me quite comfortable in terms of using the exchange. The site allowed to control the situation in different currency pairs, quickly make bets and make a profit. Playing on the stock exchange in such a short period of time has become something like entering a free minute on Habrahabr and reading the news. It was easy to do when there were a number of PCs, but the courses could fluctuate significantly at any time of the day, I needed control over assets and information on the market conditions. I started looking for a client for Android, but the one that I found was not very comfortable, looked rather coarse. Therefore, it was decided to make his client in his free time. Yes, I love bicycles, this is my hobby.

Working with API and contributing to open source

The market chosen for trading has its API, it is quite simple to use. There is a public and private API. The first is for obtaining market indicators, the second is for bidding and requesting information about the user. Data is provided in JSON format. I have written several Java classes as an interlayer, for convenient work with the API, all of them will be published in my profile on github.

An example from the code, to obtain information on a currency pair, is sufficient to execute:
BTCeTicker.getTicker(pair); 

This will return a JSON object of this type:
 { "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 by sending this object to another method of the same class, you can get any desired value.
For example, we get the price of the last transaction:
 BTCeTicker.getLast(Ticker); 

In my opinion, it turned out quite well and transparently. Questions except for the naming of classes in my project, but let it remain on my conscience. Let me remind you that I will post the classes for working with the Exchange API a little later on github.

After all the classes for working with the API have been written, it remains to be easy, to shape the appearance of the application, put the skeleton on the previously written code, how to test everything, and put it out for public viewing on the network. Actually, that's what happened:

Screenshots

Application homepage, courses:
image

Currency pair page:


Immersive mode for Android 4.4 + action bar below:
imageimage

Transaction history:


Purchase motivation free version

Available for free and paid version of the application. Differences free version:
- No restrictions, it is fully functional.
- No ads.
- Starting from the 14th day of use, the free version at startup will say that it is free. This is the only difference from the paid.

It looks like this:


Let me explain, the timer counts 15 seconds, the remaining number of seconds can be seen on the close button, after which the close button of the window will become active and you can work with the application in normal mode. If your nerves can not stand, maybe you buy a paid version, well, or just delete the free one.

For this behavior, a small method was written that is called at startup. He puts a long type label and writes it to SharedPreferences, then checks each time it is started, if the difference is more than 14 days, it displays AlertDialog.
 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.Builder action_dialog = new AlertDialog.Builder(bm_MainContext); action_dialog.setTitle(R.string.about)); LayoutInflater inflater = bm_MainState.getLayoutInflater(); View layer = inflater.inflate(R.layout.trial,null); final Button btnCancel = (Button) layer.findViewById(R.id.btnCancelTrial); Button btnBuyApp = (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(); } } 

The source code of this site is slightly modified, so as not to seem too bloated. In IDE, it looks nicer than here.
If you're even more uninformed in Java and Android than me, then maybe this piece of code is useful to you.

Links

Paid version:
image

Free version:
image

ps: this is how my next bicycle was born.

Source: https://habr.com/ru/post/204742/


All Articles