Trial and Epic Fail

Ventures of an ex indie game developer

Rich again!!!!??!!!!?!?!!!!!!!!!!!!!!!!!!!!?!!!!!!!!!!!!

Dunno if I've hyperinflated that term, but this time I think I've executed the first step of my magnum opus and found the stone of the philosopher.

I had to come up with something completely different, and in a day or two I'll know if this works or not. Since the market cap is dropping and it still is doing it's thing, I'd say it's a pretty safe bet. Since Bitcoin dropped 8% today, I've lost a little bit of fiat, but by tomorrow it should be back and there is no chance that Bitcoin is going to be able to drop as fast as I'll be gaining.

The only way to reduce this momentum would be if most people/robots/institutions stopped trading. And I have a hard time seeing that happening, as it is a gold mine for the cunning. Or a gold-mind-to-be for the cunning-wannabe.

One interesting aspect of this whole thing is that the bulk of my code is 134 lines of Python. Apart from that I reused maybe a one to two hundred lines of code from my previous attempt. If everything works out, this scales exponentially up to millionaire (not billionaire). In which case I can put all worries about uninteresting, non-scaling work aside and focus on the important work: spirituality and cold fusion energy. Yey!

Building a cryptocurrency trading bot tutorial, step 2/x

Ok, so we've downloaded and plotted some data. Over to the analysis. One of the most important things about trading is knowing if you're in a bullish or bearish trend, which is what this part of the tutorial is about.

In this part of the tutorial, we'll look at the Bitcoin currency against something called the Tether currency. Which is essentially a cryptocurrency hooked to the US dollar. Bitcoin on most sites has the trading symbol BTC, Tether has the trading symbol USDT. On Bittrex the product "Bitcoin over Tether" is called "USDT-BTC".

First we clean up our act and download the klines inside a function, let's call it download_klines(). So this is our starting code:

#!/usr/bin/env python3

import requests
from matplotlib import pyplot as plt
import pandas as pd

def download_klines(symbol):
    url = '' % symbol
    data = requests.get(url).json()
    df = pd.DataFrame(data['result'])
    return df.astype({'T':'datetime64[ns]'})

def analyze_and_plot(symbol):


So with everything is setup for you, including at the end where you see the analyze_and_plot() function call, you only need to fill in the actual analysis code. That code is going to replace where it says "pass" above. First of all, we want all our curves inside a single chart, so we'll create a coordinate system for that in matplotlib, like so:

    fig,ax = plt.subplots()

Then we download the bitcoin data and put it in a Pandas data frame, which we inventively call "df". Then we copy the close values from the column named "C" into something that is easier to understand for the reader, say "USDT-BTC" (which happens to be in the symbol variable):

    df = download_klines(symbol)
    df[symbol] = df['C']

Good. Now there are a number of different ways to analyze a curve. Some of the more common include something called MA and EMA, which I suppose is short for Mean Average and Exponential Mean Average. These are mathematical functions which help you determine trends of the curve. We'll be using MA-10, which in each point yields an arithmetic mean of the last 10 preceding points. We'll also be using EMA-30, which is an exponential arithmetic mean of the last 30 points. And EMA-200.

The code is using functions built into Pandas/Numpy, so it's very easy to do. Here we create three new columns in our matrix:

    df['ma-10'] = df['C'].rolling(10).mean()
    df['ema-30'] = df['C'].ewm(span=30).mean()
    df['trend'] = df['C'].ewm(span=200).mean()

And as you've seen before, plotting is just as easy:

    df.plot(x='T', y=symbol, ax=ax)
    df.plot(x='T', y='ma-10', ax=ax)
    df.plot(x='T', y='ema-30', ax=ax)
    df.plot(x='T', y='trend', ax=ax)

Run it! The resulting output should look something like this:

In the bearish trends you'd want to be aggressive, and in the bullish ones a bit more cautious. Also, when ma-10 is above ema-30, you'd want to be selling as late as possible, but not after ma-10 crosses and goes below ema-30.

Next part of the tutorial will show you how to do the actual trades with whatever analysis you've done.

Building a cryptocurrency trading bot tutorial, step 1/x

I'll be assuming you know merely the basics of Python3. If not, go here first.

We're going to use Bittrex, one of the biggest exchanges, based in Las Vegas. When we use Chrome to surf to, for instance, and press F12, we find that one of the URLs loaded is:
Aha! Let's curl it. Go do the command line (download MSYS if you use Windows).

$ curl ''

The curl command outputs a whole bunch of data in JSON format. This shows us that we don't need any special HTTP requests, we can just fetch the data directly from Bittrex. Great! Over to coding then.

First we need a couple of nice utility libraries for Python. You install them using the pip command, which is included in the Python installation:

$ pip install requests
$ pip install matplotlib
$ pip install pandas

The first is used to neatly download data from the web, the second to plot graphs, the third is used to manipulate data matrices.

We're going to start out in Python's interactive mode, so just start Python from the command line.

$ python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> _

 Enter the URL and the code to download it:

>>> import requests
>>> url = ''
>>> data = requests.get(url).json()

Now the coin data from Bittrex (as shown when you ran the curl command above) is stored in the variable called "data." We drag this data into Pandas, which is riddled with powerful functions for us to make good use of later on.

>>> import pandas as pd
>>> df = pd.DataFrame(data['result'])
>>> df
            BV         C         H         L         O                    T  \
0     0.306612  0.000190  0.000190  0.000188  0.000188  2018-01-16T19:15:00
1     0.067572  0.000190  0.000190  0.000190  0.000190  2018-01-16T19:20:00
2     2.641678  0.000184  0.000189  0.000184  0.000188  2018-01-16T19:25:00
3     0.449269  0.000185  0.000186  0.000185  0.000186  2018-01-16T19:30:00
4     0.248711  0.000188  0.000188  0.000185  0.000185  2018-01-16T19:35:00

And let's plot the close price over time (C over T in the data given to us by Bittrex):

>>> import matplotlib.pyplot as plt
>>> df.plot(x='T', y='C')

Step one is complete -- I'm your father! Clean it up and put it in a file together with a shebang (first line below) and you've got yourself the start of a bot. Call the script

#!/usr/bin/env python3

import requests
import matplotlib.pyplot as plt
import pandas as pd

url = ''
data = requests.get(url).json()
df = pd.DataFrame(data['result'])
df = df.astype({'T':'datetime64'})
df.plot(x='T', y='C')

(Note that I added a line to type convert the time from a string into a datetime object, so the plotting will show time stamps on the X-axis.) Next time we'll structure a bit and implement some analysis code. It's going to be dandy!


The post-mortem will have to be post-poned a few more days. A huge anxiety about a cryptocurrency called Tether, or USDT, bound to the dollar, has spawned a selling frenzy and thus a baisse in the market. It is currently impossible to make money there, so bringing my bucks out into a standstill in Tether. (Yes, I still think that's my best option.)

I expect to see at least two more days of this, and at least another 20% reduction in the market, before it's time to start growing the dough. I very much doubt it could go on for another week in this pace, as that would render pretty much every cryptocurrency worthless. That would however be a dream for many of us, as buying low is going to increase the yield massively in the comeback.

First days of freedom

Ahh, it's good to be my own entirely! I've just started a never-ending vacation, and time will tell what I'll engage in and how, but for now it's wonderful. We just visited the Swedish mountain Hundfjället ("Dog mountain") for some downhill action. Mm-mm, I could get used to this.

I consider myself rich when I've payed my mortgage, can work with whatever I want (in the words of Steve Jobs, "follow your intuition"), have an economic buffer and can choose when, where and how I want to go on vacations.

How did my journey towards being rich start then? I suppose it started as I got divorced. For a looong time I had been trying to make a game engine with some shitty games on top. It's not possible for one person to compete against UnrealEngine, and it's not like I didn't know that; it's just that I didn't want to let go of my hopes of doing something I love instead of working at a boring place developing crap for someone who hardly cares. My main mistake was to think that I was so heavily invested in game engine development that I couldn't let it go. Like a gambler trying to win everything back on the next round. Now I find my self in a position where I can do what I love, but without pressure.

Anyway, when me and my ex split up, I guess I had some time to think. Suddenly the hurdles of everyday life became smaller and I was able to get a slightly better "outside" perspective of my life. So five months after the divorce, as I released Trabant 1.1, I came to the conclusion that I should try to get earn my dough some sensible way. I don't remember why I settled on finance, since I find it super-dull and offensively unproductive for society, but finance it was. From March until I resigned in December I tried three different trading assets: leverage instruments (i.e. margin trading of stocks, which pretty much means that when a stock goes up, the leverage goes up by a factor X, when the stock goes down, the leverage goes down with factor X), stock and finally cryptocurrencies.

Those trading assets are pretty much the same thing though. You let the computer sit and buy and sell through a broker. But one one small, but highly important, difference between stock trading and trading cryptocurrencies is that the latter incurs almost no fees. That means that you can sell BitCoin when it has gone up by 1%, and that's pretty much what you'll earn.

My pigheadedness, and industriousness got me a long way towards getting rich. For instance I was close to giving up before attempting to trade in cryptocurrencies as a last attempt. I'm also fairly intelligent, which correlates with success, so that helped too (far from genius level though). You don't need to be smart to make it, but if you're not you'd be wise to follow in the footsteps of someone who is. Another important factor is my intentional focus on a richer future; this I can really recommend, no matter if you believe in Jungian synchronicity, psychic functioning or just yourself, as it allows you to home in on your target.

Another important factor is that I'm fairly agreeable, which has a negative correlation with most career paths. If I'd be more of a bully and lower in agreeableness I'd probably be some boring manager somewhere thinking that my life was great, and I would have never come up with this idea.

One realization I've gotten - now that I'm earning my income in a way which should probably be prohibited as society has very little to gain from speculation - is that I have a lot of time on my hands. So soon I'll start working on some ideas on how to improve society. Sort of like charity but with time instead of money. (Actually I'll donate 10% of my profits to charity too, but that's beside the point.) I'm very much looking forward to it all!

My next post will be a post-mortem btw.

+100% BTC

When I first started the bot, 33 days ago, I inserted a careful 1/4th of a BitCoin for it to toy with. A few days later, 29 days ago, I fixed a couple of bugs. Then I let it sit for 2 days. Looked fine. I injected another 3/4 of a BitCoin (totalling 1.01 BTC invested). I let that sit for 8 days and then reduced the risk by tweaking some parameters. The reason was the funds had been up by +58% in my original investment, but then backed down to a meager +33% BTC. Since then it's been cewing up more and more, and now it's up to +1 BTC, i.e. +100% in terms of BitCoins. Looking very stable indeed.

Since BitCoin to the dollar is down, I am currently "only" up +40% USD of my both investments. This is the USD curve:

I suspect BTC will drop some time still, but when it stabilizes I'll be getting that Tesla.

It's not that I'm a car guy, it's just that the P100D is both a rocket on wheels and good for the environment. (I know, I know, battery production is sheit. They'll have to fix that first. Then I'll buy!)

Tomorrow is my last day at the day-job. It's been 10 months since I started trying to get rich, so not too bad considering I had two failed attempts (stock and margin trading) before finding the golden calf. "Fail fast" is my best advice, next to "stay hungry" and "look into parapsychology." Especially that last part. If you want to be poor and wise.

PS. I'll be making a basic tutorial on how you could write your own trading bot in Python at some point in time. Basic Python skillz required, so start digging in if you're lame.

PPS. I actually suspect me wanting this, and the opportunity appearing, being less of luck and more of a "law of attraction" and a synchronistic event. I also scored 14/24 in ESP Trainer when I tried it for the first time in months today. So perhaps there's more to my parapsychology pointers than meets the eye.

Crypto currency trading

Trading has been immensely good since my last post, ten days ago. That does, however, not even compare to the average alt-coin as the total market cap has continued to grow like crazy. The result is that everything keeps doubling in even shorter time periods.

All good things must come to an end, and this is a gigantic balloon waiting to pop. On the way there I noted a couple of things that made a big difference to me, and my scared little bubble. For one, this is a totally decentralized system, which does not have employees, customers and can't go bankrupt. Therefore a total collapse is always both avoidable and unlikely. So unlike the .com bubble around '00, this is probably not going to crash as fast as soon. And no one currency is likely to disappear, it's not a company! Since it's just a trading instrument, it may be reduced in price and volume, but that's only scaling down.

The other thing is that I think that to a large degree we already see fractional banking causing much of the exponential increase in market cap. Very few people have bought crypto currencies, but despite that we still see 1% of all the world's money in there.

Both those things are probably good news, as they might mean that there will be an S-curve instead of a huge crash in many coins, and also that a total collapse is somewhat unrealistic.

PS. 'Musk,' the trading bot, is up some 100% USD in the 21 days it's been running. :)

About the author

Mitt foto
Gothenburg, Sweden