Bot that reacts to Twitter news and trades on Bittrex [part 2]

This is the second part of this article after the introduction.The goal here is to reliably and in real time fetch tweets as they are made and inspect them. The requirement is to fetch a tweet the moment it is published and not wait for 30 seconds until it is pushed to us by the twitter client.

The most reliable way is to use the Enterprise Twitter API, however this comes with additional costs. We are going to use the second best available solution which is free. According to twitter documentation it approaches the reliability and speed of the first approach so I am quite satisfied with it.

Note that the below implementation is made with node.js as everything else that is presented on this site.

This is similar to making an endless connection with twitter as it streams to us the latest tweets. However in order to do that we first need to be Authenticated, so let’s just do that first. We are not going to reinvent the wheel and we are going to use a node library which makes communication with twitter easy.

First we need to generate our access tokens here and then we are ready to start messing around. Here is what it looks like. You can generate and copy all these values from the link above. Now we are ready to start listening on twitter stream. Let’s prepare that. (Remember to fill these values below)

First of all we need to define a list of people who we want to follow and filter their tweets.  As a test I will first follow only myself. I do this because I want to see how fast I can see my tweet on stream and how fast on normal client and note the difference.

Here is the code:

Note that the follow ID is my twitter ID. Here you need to have a comma separated list of people that you follow. You can do that manually here.

Now I went on  Twitter and twitted in order to see how fast the Tweet will be captured and wow. It is real time. Twitter client displayed it after 20 seconds.

We are not done yet however, we need to make 2 corrections on the script to make it final.

Let’s create a way to easily add people we want to follow on the script, something like:

Now one really important point is that so far we listen to the stream of those people specified. That means that we also receive messages that are addressed to them. For example a tweet from some random that goes to @Daenerysc will also be included in the stream. We do not want those so we want to find a way to filter those out.

Notice that there are two differences here that we made:

  1. We get only tweets created from the people that we want
  2. We created a comma separated list of users to follow

So to sump up the final script is here, have fun with it:

Note: there is still one correction we need to do – if someone from the people who are interested in, messages another one that is included in the list, we will receive the tweet. can you find out why ? 

We will continue with the Bittrex part on the next post

Bot that reacts to Twitter news and buys coins on Bittrex [part 1]

For my next project I decided to create a single bot that will help me buy the news. What it means is that it will constantly fetch tweets from a given list of organizations/people and if the tweet includes positive news regarding a coin that is available on Bittrex I will instantly buy the coin with a click of a button.

I need to be able to interact with the bot, because I want to be able to make the decision of buying or not buying by myself. The goal is that the bot will deliver to me the interesting tweets in real time and then I will look through them and if I see that a coin is listed somewhere ( for example Coinbase/Binance ) and then buy the coin so that I can later sell it once the price is higher. I will give as an input only the name of the coin, the quantity I want to buy and the price.

Note that this is not the same as having a twitter account and checking the latest tweets – this is passive. I will be getting a notification in front of my face that there has just being a tweet made and I will go check it. This functionality will intercept my life as I must be able to check at the time the tweet is made else I will risk missing the train.

For now I want to do this only using Bittrex as this is the exchange I am using the most. If it turns out that I can effectively buy the news I will add more exchanges in the future. Also I am only gonna use this for buying and not for selling since I do not hold Altcoins anyway so I will not be given the chance to sell on the news. My goal is to automatically buy and then manually watch the coin’s course and decide what to do next.

There are of course bots like these out there but I want to give it a try as I find it an interesting concept and also I want to see If I can be fast enough to buy before the price reaches the top level.

Regarding the implementation, first I need to learn how to fetch tweets in real time and have them displayed on my phone. I want to be able to follow a predefined list of people and also be able to extend it later. I want to get notified in real time once a tweet is made, quickly read the tweet and then I want to be presented with a screen that i will input the coin,amount and limit price and make the purchase.

I think this post requires 4 more parts, one for setting up the Twitter feed, one for setting a way to observe everything over the phone, one for automatically buying on Bittrex and a last one for binding everything together.

So for this week I will be learning the twitter API and prepare the post for the next week.

 

 

 

Exploring the GraphQL API of Github to get an overview of Cryptocurrencies source code commits. [Part 2]

At the previous post we managed to get the weekly/monthly/yearly and total number of Bitcoin commits. The next step is to automate this and add more cryptocurrencies.

So let’s say for example that I would like to calculate the commits of Bitcoin and of Stellar. It would be pretty cool if I could define at the beginning as a variable the currency that I am interested in fetching, something like this :

Note: you can replace the string bitcoin with your favorite’s cryptocurrency organization name on Github

Well it turns out that we can. Now we just have to modify the initial query so that it is run for each currency. So we have the following:

We replaced the hard coded String Bitcoin that we had before with (login: $repo_name).That is pretty cool because now we can change easily the name of the currency that we are interested in investigating only once at the beginning.  If you want to play around you can go here and make some mess.

Note that the above works for GitHub organizations ( Bitcoin and Stellar are registered as organizations in GitHub. If you need to query repositories that belong to individuals instead you need to modify the query a bit, but I leave this as an exercise).

Now it is time to invoke JavaSript to automate the process. The goal is that we can write something like the following and get the below results.

This turns out to be pretty easy with the following function. ( Note that you will need to have a Valid GitHub Key and replace it under Authorization on your script . In addition you will need to require(‘util’) and require(‘request’) in node so that you can perform requests and then  inspect the full JSON body that is returned. )

And that’s it, we can now get the stats of every cryptocurrency with one line of code. This is how it looks in my console:

Now we just need to adjust the script in order to sum the commits of each repository for each time period. Something which is also pretty simple to do with your favorite language.

I put all the above in a script and fetched all the currencies that are listed on www.coinmarketcap.com that have a GitHub and you can see the results here.

On the next part  I will describe how I integrated GraphQL and Javasript to achieve the result above.

 

 

Exploring the GraphQL API of Github to get an overview of Cryptocurrencies source code commits. [Part 1]

Let’s assume that I am interested in acquiring some info about Bitcoin’s GitHub repositories. For example I would like to know how many commits were done during the last week or last month.

I can see that the organization Bitcoin has 4 different repositories in total, one of them which is forked. I want to also include the fork repository in my search.

So to sum up, I want to answer the following question:

Hello GitHub, please could you tell me how many commits where performed during the last week on all Bitcoin repositories ? 

Now the classical way to approach this is to make a REST request on Github and compile the answer. However we will approach this question differently using the GraphQL API that GitHub offers us.

Now a very simple query, using the GraphQL Query explorer is the following:

and this will return:

Note that during our query the word query was omitted instead of writing the following which is also valid.

The result gave us the data field which included the same fields that we requested, namely viewer -> login.

Note that a field can refer not only to a string ( like our example the login which return the string ) but also return multiple objects. So with one single query we get all the requested results. More on this later.

Let’s for example provide an organization and get back the information about their repositories. We should do something like this:

Here for demonstration we query the Bitcoin organization to see how many repositories they have. Then we loop through each of the repository to see how many commits each repository had. If you notice history  can accept arguments so we could pass a for example since: "2018-06-07T00:00:00Z"and this way we can limit our search history to return results not earlier than the given date The result looks like:

We see that Bitcoin organization has 4 repositories in total. In this specific request I requested in purpose only the first two as to limit the size of the output and to demonstrate an additional functionality.  We get information about the bitcoin/bitcoin repository that since the beginning of time they had 17625 commits until today. The second repository bitcoin/bips had 1752 commits.

Now if we wanted to get information about all the 4 different bitcoin repositories we could query like:

This will most likely fetch all the results if the organization has less than 100 repositories. If that is not the case then we need to use the pagination functionality that GraphQL provides us. That means that once it fetches the maximum repositories that we requested it will also provide us with a “cursor” which will point to the last repository that it fetched. In the next query we provide this cursor and it will be used as the starting point. For example below while we queried for bitcoin we limit the results to 2. The cursor that the query returned was:

Now we can make the same query and also include the endCursor in order to continue fetching results. Let’s just do that :

You notice that the query is identical with the first one however there is the after parameter which will allow us to fetch the remaining repositories.

And the result:

The remaining 2 repositories with 59 and 362 commits in total.

Now we are ready to move into the next step, combining all the above in order to reach the answer to our question:

Hello GitHub, please could you tell me how many commits where performed during the last week on all Bitcoin repositories ? 

so now we only need to find a way to limit the results to the last week only. Since today it is 14.07.2018 we want the results since 07.07.2018 ( European date format!). Turns out that this is pretty easy to do and our final query is:

You can see on the history we added the since and we also requested to return up to 100 repos ( even though we know that bitcoin has only 4). Now the result are:

So the answer to our question is the following.

During the last week Bitcoin had in total 59 commits.

Now that we have our answer we can generalize the concept a bit and summarize a lot more information. For example I would like to have a breakdown of weekly, monthly and yearly number of commits. And this not only for Bitcoin but for ALL of cryptocurrencies that are hosted on www.coinmarketcap.com.Then have a table to summarize all of the results and we can be able to sort all cryptocurrencies by source code commits – that would be pretty cool.

So let’s start with one cryptocurrency, Bitcoin. We want with 1 query to get all the information regarding the number of commits

  1. Last week
  2. Last Month
  3. Last Year
  4. Since the Beginning

Our query will look something like this:

We created aliases for the same query and we just adjusted the history field. The answer is the following:

So to sump up all the information up to this point until now:

  1. commits last week: 59
  2. commits last month: 319
  3. commits last year: 3385
  4. commits total: 19798

As pretty as it it, it does not really tell us a lot of information on it’s own. We will have to fetch also information from other currencies, automate the calculation more and present the results in a better way. Let’s do that in the next part.

To be read in 2023

Note: All dates are European Style 

This is supposed to be read in the future, meaning on a date far away from 15.07.18. But what exactly does future mean ? I will be reviewing this article yearly until 2024. What would the below image look like by then 

This is a today’s coinmarketcap.com screenshot  for the top 10 currencies. We can keep this as a reference or a baseline for our future comparison.

15.07.18 

We can prepare ourselves a bit so that we are not surprised completely. Let’s see what the same page looked like almost 5 years ago.

16.06.2013

Just to go a bit deeper, we see that there are some currencies that remain at the top 10. Bitcoin and Litecoin. What about the others ?

  1. Namecoin is still there and raised its market cap from 2M to 17M.[ 2019 update: 15 M ]
  2. Peercoin is still there and raised its market cap from 2M to 31M.[ 2019 update: 15 M ]
  3. Novacoin is still there and raised its market cap from 0.9M to 5M.[ 2019 update: 1 M ]
  4. Feathercoin is still there and raised its market cap from 0.8M to 16M.[ 2019 update: 5 M ]
  5. Terracoin is still there and raised its market cap from 0.4M to 2M[ 2019 update: 0.6 M ]
  6. Devcoin is not there from a cap of 0.4M , it was abandoned on 2015.
  7. Freicoin is almost still there from a cap of 0.3M  it was reduced to 0.1 M , you can only get it freiexchange.com. As of 2019 it is dead.
  8. CHNCoin is not there from a cap of 0.2M now it is not sold anywhere.

In general I consider successful  future predictions based on past as pure luck. The Stock market proved  multiple times in the past that in a scale large enough we cannot use historical performance as an indicator of future performance.

So for example it would not make sense and we should be very careful to say something  like the following :

From the current top 10 currencies, 2 will remain and will increase their market cap by a large amount,  5 will remain and increase their market cap by a small amount and 3 will be lost.

But what if we really want to have an opinion for the future, what we should say ? What rules or guidelines can we follow ? Would Technical / Fundamental Analysis be helpful or how about our gut feelings or a combination of all of the above. I  would go with a combination of all of them namely :history, gut feeling, technical & fundamental  analysis and with a bit of luck you can have a pretty good ( or bad ) approximation of the future.

So if you had to take something out of this article it would be the following: even considering a lot of factors trying to predict future price it would take a considering amount of work and luck to make the prediction accurate.

Having a bit of gut feeling and having done fundamental  & Technical analysis I believe Bitcoin’s price will be able to continue to imitate past performance. For the rest of smaller currencies I have done enough technical and fundamental analysis but there are not enough of  historical data ( 5 year chucks) and also I do not have a gut feeling.

First Update 12.04.2019- Almost a year after

How fast time goes by! Let’s see how the current top 10 looks like. We see not many differences since last year with one exception. Binance coin. It had an exceptionally good year and this makes me invest into it a bit. I have written down my thoughts here. I still consider it shitcoin but I believe in the next cycles leading to 2024 it can become overvalued.

Valuate Currencies by Github activity

Valuating Crypto by Market Price is the standard but I wanted to have another model in order to see how it compares with the price valuation. Therefore I thought of creating a website/extension/simple page similar to www.coinmarketcap.com which will rank all the available cryptocurrencies by their source code activity. This has the limitation however that we can only capture open source projects however I am fine with that since I only invest in open source projects where I have the opportunity to see the work done.

I am interested in seeing the following metrics:

  1. Number of commits per week, month, year and total since the beginning of the project.

I am mostly interested on a weekly interval since I believe it gives me a rounded overview of what is going on with a project. Also time of last commit is important since I noticed that a lot of projects have many commits but months since their last commit, something which is a red flag.

At the moment I am working on learning the Github API in order to get information regarding a repository. I will update this post as I learn more and I start developing code for this.

What I have achieved so far is to get daily, weekly and monthly information regarding the number of commits and also some information regarding the commits. I did this using the GitHub API query builder that I linked above. The next step would be to automate this via JavaScript and also to present it beautifully. For the presentation layer I am thinking to use either BootStrap or a custom solution to include this in this blog, I will decide this later and update this post.

Update 18.07.18 I have a working prototype for demonstration.  Here is the link.

Update 04.12.18 Since this site does it much better than me I decided to not update it anymore.