Febin John James's Blog, page 6

March 24, 2018

Daniel Blank Glad to see you here :)

Daniel Blank Glad to see you here :)

 •  0 comments  •  flag
Share on Twitter
Published on March 24, 2018 17:02

How to Build a Simple Crypto Trading Simulator, Part 1

Learn to Code a Crypto Trading Simulator in Python

I am not a trader, but the whole idea of trading crypto is so tempting. I don’t want to invest real money unless I know what I am doing. I wanted someplace to test my strategies.

Credits : xkcd

So, I thought of building a Crypto Trading Simulator. The idea is to help beginner investor learn and experiment without losing real money. In this series, I will teach you how to build one. I have got a database which contains crypto prices of different exchanges between March 7th, 2018 and March 16th, 2018.

In this story, we will build a simple crypto simulator in python which allows the user to invest in a cryptocurrency, then we will run a simulator to see how the performance of his crypto asset in the next 9 days.

For now, we will display the best bid price for his asset, compare it with the initial investment and tell him if he made a profit or loss. In the coming stories, I will cover how to add live currency monitoring, how to write and test strategies, how to build the user interface, etc.. (I will need your support here, I have mentioned about the same at the end of the story.)

Here’s a video of the simulator we are building today, you can also take a look at the project’s Github Repository. You need to download the database separately from here and place it in the project’s directory.

https://medium.com/media/c14cfc3db0b20393a643544acb442d2c/hrefPseudo Code

Before we jump into coding, we need to have clarity on what are the next steps. This is important, otherwise we will often have confusions. We use pseudo code to get clarity, a pseudo code is not real code, but a roadmap in our own language.

Step 1: Welcome the user. Step 2: We will fetch the cryptocurrency prices during March 7th, 2018 since our database starts at that time. Step 3: We will ask the user to invest in one currency.Step 4: Then, we will run the simulator to see how his crypto asset does in the next 9 days. Step 5: We will find the best bid price for that currency, compare it with user's initial investment and display if he made a profit or loss.

We don’t have to do the steps in that order, we can do whichever is easier first. Because having more things completed gives us confidence and we are likely to complete the whole project.

The code used in this story uses Python 2.7 .

Let’s start by creating an empty folder, ex: “CryptoSimulator”. You also need to download the crypto price database from here and place it inside your project folder.

Make a file called “run.py”

Credits : xkcdWelcome

We will create a simple function called “welcome”. It does nothing great, just print a series of line, the program name, giving the user an idea of what the program is up to, in other words just saying “Hi”.

def welcome():
print(“Simple Crypto Trading Simulator”)
print(“Hey Yo, you are back in time. It’s Wednesday, March 7, 2018 7:39 AM”)
print(“Here are the crypto currencies you can invest.”)
print(“Fetching prices … ”)

Great, now we need to fetch the prices of the crypto currencies at March 7 2018 , 7:39 AM.

Since our database is based on sqlite3, we need to download the python library, you can do that using the following command.

pip install sqlite3

Now at the beginning of the file run.py , we need to import the library.

import sqlite3

Now let’s write the code to fetch prices from the beginning of the time and display it.

In the database we have following columns, timestamp, first_leg, second_leg, ask, bid and the exchange name. If we consider the currency pair “BTC/USD”. The first leg would be BTC and the second leg is “USD”.

In the following lines of code, we are fetching the prices at a given time.

connection = sqlite3.connect(‘./currency_monitor.db’)
cursor = connection.cursor()
query = “SELECT first_leg, ask FROM prices WHERE timestamp=’1520408341.52' AND second_leg=’USD’;” cursor.execute(query)
coinAskPrices = cursor.fetchall()

Now we will loop through the prices, remove duplicates, add then to python dictionary and print them.

coins = {}
for coinAskPrice in coinAskPrices:
if coinAskPrice[0] in coins:
continue
coins[coinAskPrice[0]] = {“price”:coinAskPrice[1], “curreny”:coinAskPrice[0]}
print(“{} — ${} \n”.format(coinAskPrice[0], round(coinAskPrice[1],4)))
return coins

If you don’t understand the code, don’t worry. Just download the repository, run it and tinker around and see what happens, slowly everything will start to sense.

Now we will combine the above pieces of code into one single function “fetchCoins”.

Credits : xkcd

Now that, the prices have been displayed, we will ask the user which crypto he wants to buy and how much. We will create a function called “inputBuy”.

def inputBuy():
print(“Select the crypto curreny you want to buy? \n”)
curreny = raw_input(“”).upper()
print(“That’s great. How much quantity you want to buy? \n”)
quantity = float(raw_input(“”))
return curreny, quantity

Now we need to find the price of the currency which the user is interested. We can simply do that by querying the python dictionary.

price = coins[currency][‘price’]

Then we need to pass these parameters to our simulator. Let’s put together these pieces of code into the main function.

Yes, the “runSimulation” function is not defined yet, we will be doing that next. We can do this another file, create a file “simulator.py”

Credits : xkcd

We need to import these libraries

import sqlite3
import datetime

Now let’s define the function runSimulation.

def runSimulation(boughtPrice, quantity, currency):
valueThen = boughtPrice * quantity
bestPrice, timestamp = fetchBestBidPriceFromDB(currency)
bestValue = bestPrice * quantity
priceDifference = (bestValue — valueThen)/float(valueThen) * 100

Here we are are calculating the total asset price at the time of buying, then we are finding the best price for that currency during March 7th and March 16th. Later we are calculating the difference to find, if the value increased or decreased.

To find the best price, make a function called “fetchBestBidPriceFromDB”.

def fetchBestBidPriceFromDB(currency):
connection = sqlite3.connect(‘./currency_monitor.db’)
cursor = connection.cursor()
query = “SELECT max(bid),timestamp from prices WHERE first_leg=’{}’ and second_leg=’USD’ and timestamp> ‘1520408341.52’”.format(currency)
cursor.execute(query)
rows = cursor.fetchone()
return rows[0], rows[1]

We also need to add few more lines in the runSimulation function to print our findings.

print(“The best bid price for {} was ${} at {} \n”.format(currency, bestPrice, time))
if priceDifference>0:
print(“Your total asset value is ${}, it has increase by {}% \n”.format(round(bestValue, 4), round(priceDifference,2)))
else:
print(“Your total asset value is ${}, it has decreased by {} \n”.format(round(bestValue, 4), round(priceDifference,2)))

Let’s put these pieces of code together.

It’s almost done, but I want to add some drama. You know in the movies, the letters get printed one by one in the console?

Create a file called “drama.py” and add these lines of code

import time
import sysdef dramaticTyping(string):
for char in string:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.10)

Now import this file on run.py and simulator.py, then replace the function call print with dramaticTyping.

Congrats, we have got a basic version of our crypto trading simulator ready.

Claps Please

 •  0 comments  •  flag
Share on Twitter
Published on March 24, 2018 14:22

March 20, 2018

Rod Gustafson, I have noted your point. I hope to write more articles that are not sponsored.

Rod Gustafson, I have noted your point. I hope to write more articles that are not sponsored.

 •  0 comments  •  flag
Share on Twitter
Published on March 20, 2018 08:46

March 18, 2018

Here Is the Epic Future Blockchain Is Going to Create

I have been following Blockchain for quite a while now. I understood the technology was innovative. But, I always wondered if it was hyped ? Diving deep into the filed and interacting with thinkers assured me it wasn’t.

Open Business

It’s actually called Decentralised Autonomous Organisation, I use “ Open Business” to make it sound simple. Open Source communities which are the backbone of organizations like Linux, Google, etc have the least or no politics. I am not talking about the organization but their projects.

For example, Hyperledger is a project by Linux Foundation. It will help you build applications for private Blockchain. People around the world contribute to this project. It doesn’t matter who you are or what you are if you do good work your code will be merged to the source. You are recognised solely for your work.

I have observed people who know how to play cheap politics overpower people who work hard. In a Decentralised Autonomous Organisation, everyone’s work will be recorded on a transparent Blockchain. Your salary would be provided by the system which evaluates your work.

Open Business will have the future of Open Source projects. Anyone anywhere with a business idea could start a Decentralised Organisation. Anyone could be a part of it, a programmer could be automatically added to the system based on his git profile. Every member of the organisation would be paid solely based on what each one brings to the table.

The Future Is Going to Be Great For Producers

You might have been already bored by the words “Eliminating middleman”. Let me tell you why it is a big deal. If I have to sell a book on Amazon, they take 50% of the sale as commission. Writing a book is hard work. It would take months to write a book.

It would take double the time to find a publisher. These publishers have their own biases (JK Rowling Turned Down By 12 Publishers), even if your work is good it would never see the light. In case you get lucky and your book was published. The majority of the cut goes to the publisher.

If you self-publish the book you have to break your sweat on marketing it. On top of that seeing Amazon take a huge cut is really painful. Only a few people dare to fight these challenge and become producers. Producers in almost every industries are exploited.

The vegetables you ate today was produced by a farmer. In India, most farmers live in poverty. Datatery Popat Ghadwaje, 42, committed suicide after days of hushed chanting “the sky betrayed”.

India's shocking farmer suicide epidemic

We can’t control the sky. But, giving a good deal of their hard work is a must. Governments try to solve the problem by giving farmers easy/reduced loans or pensions. These things don’t work. We need to go to the root of the problem and address it. We need system thinking here. We need a system that enforces farmers to get properly rewarded for their hard work.

Middleman is hungry for power, fame, and money. Blockchain replaces them with computers. Computer systems are not hungry for power, fame, and money (Except for Bitcoin). Can a computer system replace middleman?

What does a middleman do? He finds producers and consumers, buys from the producer for less and sells it to the consumer for a higher price. This can be easily replaced by a program, except the computer will give the producer a reasonable price. It’s also important that the program is transparent and not controlled by an individual. This system is what the Blockchain enables.

The future is going to be great for writers, composers, singers, farmers, or producers in general.

What about freelancers?

Upwork takes 25% of my earnings, if I earn $1000 for a project, they take $250. That is a substantial amount! So how does Blockchain help? Upwork has infrastructure cost, they need to pay for their server, database, maintenance, etc. On a public blockchain like Ethereum, the infrastructure cost is reduced drastically. Reading data from Ethereum is free.

On a centralized infrastructure which Upwork is based on, the more the people, more servers to handle the load and more money is needed. On a decentralised network, more the people, less money is required because the load is used to favour the Blockchain network.

On a blockchain based platform, the fee can be as less as 4%–2%. I have to only pay around $40 or $20 as commission. That’s drastically less compared to $250. Vanywhere is building a blockchain based platform.

Vanywhere

I recently came across Vanywhere (yet to launch). The idea is to help people monetize their skill.

It’s not limited to freelancers like in Upwork. If you have skills in cooking, fashion, traveling, sports, etc, you have an additional source of income with Vanywhere.

The brilliant thing about Vanywhere is that they are a platform based on Blockchain. This means their infrastructure cost would be drastically less and they would take less commission compared to sites like Upwork who presently eat 25% of my revenue.

Kindly note, this post is sponsored by Vanywhere .

Claps Please

 •  0 comments  •  flag
Share on Twitter
Published on March 18, 2018 21:31

March 16, 2018

5 Simple Ways to Survive the Economic Crisis

During my life on earth, I witnessed the market crash two times. I was too immature to understand what was going on. I was only a passive observer. But, I have a plan to survive the upcoming one.

It doesn’t take a genius to predict the upcoming events. Less money would lead to cost cuttings in companies, layoffs, reduction in salaries, etc.

But, I believe in turning crisis into opportunities. Here are some things you must consider.

Multiple Sources of Revenue

Create multiple sources of revenue because there could be a delay in payments or no payments. You will be on the safer side with multiple sources of income.

There are two ways of income, passive and active. My plan for passive income is to sell ebooks, courses on trending topics like cryptocurrency, the blockchain, etc.

Vanywhere

For an active source of income, I am relying on sites like Upwork. I recently came across Vanywhere (yet to launch). The idea is to help people monetize their skill.

It’s not limited to freelancers like in Upwork. If you have skills in cooking, fashion, traveling, sports, etc, you have an additional source of income with Vanywhere.

The brilliant thing about Vanywhere is that they are a platform based on Blockchain. This means their infrastructure cost would be drastically less and they would take less commission compared to sites like Upwork who presently eat 25% of my revenue.

SteemIt

I am trying to register on SteemIt. They help content creators make money. Unfortunately, they seem to have closed registrations or restricted new users to specific countries. I am yet to receive their SMS verification code (It has been a week).

Writing on Medium is another way of generating revenue. Unfortunately, they haven’t opened it for writers from countries like India where Stripe is not supported.

Master In-Demand Skills

There is a huge demand for people who know to program, code and teach about Blockchain and Cryptocurrencies. Learning blockchain is the best decision I made, My Linkedin is filled with so many requests for writing, programming, and consultation. Please feel free to get in touch with me but be patient I might take time to respond.

If you are not comfortable with blockchain, please have a look here. If you still don’t find your interest, I am sure a google search will help you.

Investing

This point has already been covered in a previous post here. The type of companies which survived during the dot-com crash was the one that helped people make or save money. People who invested in eBay, Amazon, etc made massive returns.

eBay, Amazon helped producers take their products to the masses but it came with a cost. They take a huge commission in the revenue generated.

In the Blockchain era, the kind of companies that would thrive would be the ones that would eliminate the middleman. Hence enabling producers to make more money and consumers save money.

I would leave you to find such companies, but the popular ones are SteemIt, Vanywhere, and Siacoin.

Trading

Investing might take a while to generate revenue. Day trading is an alternative that would help revenue faster, this doesn’t mean it is a quick way of getting rich. I recommend you to read How to Day Trade for a Living.

I am not an expert in trading, but after reading a series of posts about trading, I have curated few books, they are Insider Buy Superstocks,
The Complete TurtleTrader, and Trend Following

Collecting Freebies

This is the easiest way of all, I am a verified user of Earn.com. They pay you bitcoins for reading emails, those are mostly from ICOs. They even airdrop you free tokens, you can also cash out some of these tokens in crypto exchanges.

If you have more ideas please comment here. I would be happy to update this story.

Kindly note, this post was sponsored by Vanywhere .

Claps Please

 •  0 comments  •  flag
Share on Twitter
Published on March 16, 2018 08:01

March 9, 2018

It’s a decentralised database and also uses cryptography

It’s a decentralised database and also uses cryptography

 •  0 comments  •  flag
Share on Twitter
Published on March 09, 2018 07:41

March 8, 2018

Agile Skeptic If I have to sell a book on Amazon, they take 50% of the profits.

Agile Skeptic If I have to sell a book on Amazon, they take 50% of the profits. On a blockchain platform that can be reduced to 5%. Since, I am getting more profits, I can reduce the price of the book.

The cost is reduce to 5% because you don’t have to maintain the middle technology layer. It is self maintained.

 •  0 comments  •  flag
Share on Twitter
Published on March 08, 2018 07:48

March 7, 2018

Again depends on the document size, some documents can be few kbs.

Again depends on the document size, some documents can be few kbs. If the documents are large then you can link it with a decentralised storage like Storj.

 •  0 comments  •  flag
Share on Twitter
Published on March 07, 2018 18:39

March 1, 2018

3 Popular EdTech Platforms You Need to Know

Education Ecosystem

Education Ecosystem(LiveEdu) is working on a Blockchain based professional development platform. They connect different participants like content creators, learners, API developers, moderators, etc. You can register on their platform and learn from industry experts. They reached their ICO hard cap recently. They have an internal ecosystem competition and are giving away a Tesla Model S. Read about it here. Their LEDU tokens are available for purchase on Gate.io(March 1st) or Bibox (March 2nd).

https://medium.com/media/69688c1e448cbeeb026ef9793cffb77d/href

LEDU tokens can be used for various purposes like downloading course materials, requesting custom projects, getting replies from the content creator, etc. The more you learn, the more you earn. You earn tokens for watching project videos, submitting project suggestions, inviting friends etc. You also get rewarded for being a community moderator. You get rewarded for quality assurance activities such as reporting bugs, content moderation, etc. Education Ecosystem incentivises its content creators. They receive tokens for creating content. The more learners engage with the content the more its creator is rewarded.

ODEM

ODEM is a decentralised education marketplace. ODEM connects students and professors directly. Individual attention can be improved with one-one interaction. This is a value add MOOCs fail to provide.They use smart contracts to mediate financial relationships between its members (eg. students, tutors) and remove intermediaries. Hence drastically reducing cost. Their crowdsale is still going on.

https://medium.com/media/37f6524d5ec258c754b208e220f828d2/hrefBitDegree

Bitdegree bridges the gap between industry needs and student skills. This happens because study materials are hardly updated. Blockchain Developers are gonna be in huge demand in the coming years. In India having Blockchain Development listed in the curriculum is years away. BitDigree is already launching a solidity course on March 2nd. They even connect students with employers. This increases your chances of getting hired.

https://medium.com/media/3b92fc425a5c35afadf6843a552e54b9/href

We still need a lot more ideas for Education in Blockchain. I feel this sector is yet to be disrupted. I suggest you take this free course on solidity programming in CryptoZombies (It’s fun). Hack around, write a few contracts and who knows you may be upto something. You should also checkout the free hyperledger course in EdX by Linux Foundation. The other sector which would see immediate disruption is on Private Permissioned Blockchains.

Do checkout my popular stories on Blockchain In Education.

What Happens When You Combine Blockchain and Education?How Can Blockchain Technology Innovate Your Education

Claps Please

 •  0 comments  •  flag
Share on Twitter
Published on March 01, 2018 09:40