04 Automated Crypto Trading — Python and GDAX websocket, starting to look over indicators

Please note nothing really happened in this post

Well at this time I still don’t have my own blog setup. I kind of like Medium actually, how it tracks the stats, I imagine they have better “is this view a real person” tracking methods.

I’ve also decided that I will get to the point more, rather than just writing as I go along, I’ll save that for my own blog or as a plaintext dump of my madness.

So in this part, I’m going to access the GDAX websocket through Python and load it into either memory or database. I’m still working on learning how trading itself actually works regarding looking at charts and knowing how to make decisions. I’m better on the coding part.

In the prior story I wrote, I was able to get into GDAX through JavaScript. I think I almost had it with Python but I wasn’t constructing my JSON dictionary correctly.

You can just skip to the MEAT of the post, where you can actually learn anything useful if there is any. I don’t know if the # page skips, I forget what those are called work on Medium.

edit: there is no MEAT in this post. At the bottom of the post is the repo though with the code used in this post.

Nothing much happened in this post, mostly because I don’t have a plan regarding the indicators. Also got stuck on dumb things with Python as it’s a little different from what I normally use eg. JS/PHP.

Goals

I think these are the main goals to get done in this post.

  • *nope- get a basic understanding of an indicator to turn it into an “algorithm”
  • *nope- load data into sqlite(this is what I’m picking for now as my “in memory storage” to iterate over) <- wtf is he talking about
  • *nope- be able to create decisions/alerts then send to a webhook event(easy) maybe text, I was looking into Twilio, what the hell, I’ll feel like I have friends with these notifications
  • *nope- compare the decisions with price history to see if the predictions were good or bad
  • *nope- all running on a raspberry pi(full size quad core type) not dedicated so a thread I think would be enough
  • *nope- consider logging the would-be-buys for tax events(I just did this recently and it was a pain in the ass)

*nope means I did not get this done in this post. All I got done in this post was communicate with GDAX and consume their websocket feed using Python only and started looking over some indicators.

Working with a chart indicator visually first

So right now, at this exact moment queue time stamp, 04–16–2018 7:41 PM Central Time United States(haha), I don’t know of a single indicator. So really I can’t even begin to write the first “algorithm” part.

So far I’ve got Bollinger bands, RSI, MACD and some others in mind. Since this data is almost instant(well seconds anyway), I don’t know if some long-term approaches will work.

So I’m going to time stamp this, I know I’m supposed to provide a condensed “here are the answers/solutions post” I will. When the blog is ready, hahaha(evil laugh).

8:09 PM

Quickly comparing Bollinger Band, RSI and MACD

Bollinger Bands

source 2

three bands, uptrend, standard deviation

A friend actually told me about Bollinger Bands and even went as far as to provide an excel sheet for me with the calculations/chart ready.

Center line is exponential moving average.

Here’s the data he setup from CoinDesk. So I think I’ll work with this, but instead of days, use hours or minutes. Not really sure if that’s effective although crypto is so volatile.

This is hard to read/these photos don’t appear to link to the full scale image. From left to right eg. columns B, C, D and E are orange, yellow, green and purple respectively. The columns are original, 20 day mid, high, low.

The algo approach won’t be visual, I have to conceptually get this and then I can write the number comparisons between the moving average functions. I think it would be a shifting array that cuts off the last value and adds the new one, then do the math operation on that current array. I did this for a PIR motion sensor haha, as a way to get rid of false positives.

Touching lower band… is bad. Center moving average line.

Source 2

I guess Bollinger bands shouldn’t be used by themselves or as indicators to buy/sell. In either case I have to keep going.

RSI

…basic measure of how well a stock is performing against itself by comparing the strength of the up days versus the down days. …number computed range between 0 and 100… above 70 is bullish, below 30 is bearish.

Oh snap… 14 days for RSI haha, not sure if this will be good for a day-trading-bot. Until I keep the thread running with back up data that can be picked up if the Pi goes down, and caught-up to current data eg. fill in the holes.

I see an equation, I don’t understand what these bars refer to.

I should note at this time in my life, my brain is going in too many directions, mostly it’s worry/trying to survive. I’ve definitely never been a day trader/looked into seriously enough to really have a clue what I’m doing.

Yeah what are these bars… looks like it’s volume candles?

Haha there’s a little widget on TradingView that says “buy or sell”, should just scrape their site and use that to buy/sell haha.

Damn this web interface is beautiful.

So yeah, how the F — do you get these volume candles?

five components: open, high, low, close and volume.

wide candles = high volume, narrow = low.

candle is hollow(light color) when close is above open, candle is filled when close is below open.

Yeah these candles are daily, not sure if that’s good for the “day-trading” aspect.

MACD

source 2

source 3

moving average convergence divergence

I think mostly right now I want to have a data stream built up, “where it is now” so to speak, long term and current, then feed that/tap into it at will with top-layer events… not really sure what the hell I’m saying. Classes and methods bro.

I’m just looking at my gdax websocket feed here, I have: current price, open_24h price, volume_24h, low_24h price, high_24h price, volume 30_d, not sure what last_size is.

from source 2:

Calculate simple moving average, sum 12 time periods, divide by 12.

Some more stuff about 26-period EMA, subtract… nine-period EMA…

I’m going to move ahead with the data gathering part. For one I haven’t used sqlite yet.

real quick, from source 3:

I want to know how to actually use this MACD, to make a decision. It sounds like what I should use regarding day-based-data decisions.

Oh shit… 26 and 12 days… hmm.

These arrows are pointing where these two lines cross. How do you calculate these lines and what are they based on.

Alright, TL;DR I still have no idea on indicators.

9:33 PM

Moving on to loading data into Python/Sqlite… maybe I don’t even need to use a database yet actually.

I’m just looking at this GDAX websocket feed, I can’t even tell how quickly it updates, it’s fast.

Oh snap this data is set 5 hours ahead of me, I’m -5 UTC or something I guess that makes sense?

9:49 PM, man I feel beat, taking a break

I’m having a problem with my Python websocket connection, keep getting this “an integer is required”

I realize too how bad it is to spread your focus, how little progress you make when you don’t commit.

10:24 PM, my head does not feel good.

I have this urge to get something done though. “Progress”.

Oh god I can’t stop it haha. Ahhh. Ahh trash icon.

So I got it to work, it was a serialization issue. I guess I don’t need to use pickle.

Now I have to figure out how to use onmessage for the printing not a dumb while true loop(dumb because I chose to use it).

10:56 PM

Alright I got it, so I don’t close the connection, I use a delay. Apparently you can go as fast as 3 requests per second. I may just stick with 1 request per second.

You can go even faster but I’m a noob/don’t know what I’m doing right now. Used a while True: loop with a time.sleep(1) delay.

So I can start logging prices into a couple of arrays, a main trend, then the mid, high and low trends.

I need to reverse-engineer these equations from the numbers in the excel/chart provided to me.

These numbers:

1190.89 1080.5155 1230.335886 930.6951143

Left most is original, then 20 day mid, high, low

More sources for Bollinger Bands

Source 3

Source 4

Oh man my head hurts, probably should sleep soon.

I’m F — ing bad at math.

11:43 PM

Alright… I got distracted. So it is seeming like trying to do microtransaction trades with fees/not much price action going on with crypto and random big buys from 1 person or few people, may not be a good plan overall.

Let’s get it done… something.

11:57 PM

Ahhhh distraction

Interesting thoughts about HFT and crypto currencies.

I can’t get these numbers to match on this chart. I’ll have to learn about these SMA/EMA terms more.

Simple thing I can do is to isolate the prices, and put them into an array. I do want another set though “moving average” to compare against then when they cross eg. match values at some point, that would be an indicator of some sort.

12:25 PM

Wow… that was dumb. So you don’t always get a response, especially the first response from the websocket, so trying to call the missing key for the dict that does not exist fails. Have to add a check. Then it works as expected.

I can also get the time and volume and whatever, for the data that is published, it’s possible I’ll increase the frequency too, but it may not be necessary. Ehh I’ll try it, it’s just listening right so I’m not polling them.

Well I think overall this was not productive. I mean I got the data source, isolated it, it’s in Python not JavaScript.

I worked on the repo some regarding the wiki.

There’s nothing really right now, I gotta learn indicators and come up with a plan. As someone pointed out trying to do quick trades with the fees/probably not going to work out.

Repo entry for today

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store