Kraken margin trading calculator

Determining position size, leverage, and liquidation levels

If we are indeed at the start of a bitcoin bull run, then it is going to get progressively harder to accumulate a full BTC. Raising the FIAT needed to buy one outright is beyond my means without taking some credit risk. Trading alts is another to do this, but I’m not willing to risk much of the BTC that I already have on alts. Instead I’ve decided to see what I can do with a small amount of fait and some margin trading. So I opened an account on Kraken.

US residents don’t have many options when it comes to leveraged trading. Kraken is one of the few, and the one that seemed most accessible to me. Getting verified was simple enough, but I was a bit shocked to find that they don’t allow ACH transfers from bank accounts, only wire. Alas. I was able to use stablecoins to transfer from my preferred exchange, as well as some BTC I had earmarked in a trading wallet, as well as some ETH I had mined.

With these meager funds, I made a small swing trade on spot. I’ll admit that I didn’t know much about leverage, but I did know that there was a call level and a liquidation level. For the life of me though, I couldn’t find a way to calculate this. Kraken’s documentation shows that they have a profit and loss / liquidation calculator, but it’s on the futures site, and not available to me. I’m not sure this is an oversight, or a way for them to get over on noobs.

I spent an hour or two last night trying to calculate these numbers myself. With a few examples and some algebra, I was able to put together a spreadsheet that allows me to plan my entry and stops, and validate that they are well outside of liquidation range.

Using an example from Kraken’s documentation: Using $5000 in equity to open a $10,000 position with 5x leverage results in a $2000 margin level. The margin ratio on the account is (5000/2000) x 100 = 250%. A ratio of one hundred percent put us in danger of liquidation. Kraken can margin call at around 80% (the exact percentage depends on some obtuse factor), and the liquidation process starts at 40%. But how to figure this out.

Kraken’s example gives us a hint. If the account takes a paper loss of $3500, this puts the equity at $1500 (5000-3500), and the margin level is now 1500/2000 = 75%. So we know have enough information to write it out as an equation.

margin rate = (equity - original position price - current position value) / margin amount

What we really want, though, is to estimate the current position value. Using a bit of algebra we can isolate it as such:

current position value = (margin rate * margin amount) - equity + position cost

Now we can substitute the call and liquidation rates in our spreadsheet to determine the current position value, further breaking it down by market price and position size.

In order to use the spreadsheet, fill out your equity size, entry and stop loss. The risk amount is set to two percent, change as you like. If the position size is more than five times your equity, OVERLEVERAGE will return true, which means that the parameters you’ve entered are so conservative that you won’t come close to the full risk amount. You can lower your stop loss to find the sweet spot.

In our example, we have $10,000 in equity, and are going to enter a position at $10,000, with a stop loss of $9900. This will allow us to open a $20,000 position, which we will be able to open using $4000 of margin (collateral) at 5x.

As you can see, the spot price will have to drop to $7000 before our margin level falls to 100%: (14,000 position value + 6,000 equity remaining = original position size of $20,000.) Since our stop loss is well, well above this level, we shouldn’t have to worry about getting called at 80% or liquidated at 40%.

Hopefully this spreadsheet is helpful, and please, please use risk management before you take these trades. If you’re new to leverage, as I am, I recommend you read CryptoCred’s Comprehensive Guide to Position Size and Leverage.


Boom time

Today was absolutely insane. There was some good news about another COVID vaccine which set the equities markets up today, and $ETH hit $600, which set the crypto markets roaring. It was amazing. I finished the day up eight percent, for my first five digit day, (and then some.)

The news behind $DPW was that they announced some partnerships with restaurants to provide electric vehicle charging stations. I’ve had a standing trigger since September to set a trailing stop next time it pumped past five dollars, and it triggered at 5.39, which cut me out of a couple hundred dollars to the close.

Overall, I’m glad to be out of this one. I had picked it after I misinterpreted some news about their involvement with bitcoin, and got caught up in that first big pump gap a week after I opened the position. By the time I hit my value averaging targets in the grey box, I was down, so I set the trigger, hoping that it would have another big spike that I could capitalize on. Turns out it worked, so yay me. I feel a lot better about the other, pure-crypto plays in my portfolio, and would rather put my focus there than worry about these guys in the future.

Ethereum was obviously the driver in today’s rally, and again, the fact that the mining companies are up even more shows me where I need to be focusing my cash. $RIOT and $MARA and the rest are doing really good.

Strangely, BTC has been pretty flat despite a big dip over the weekend, I think the fact that it’s basically back where it was Friday has proven really bullish for the market. In fact, $BTC was down from Friday’s levels, but $GBTC was up five percent.

I have actually been anticipating a BTC dip when we get near ATH levels, and I had calculated a GBTC price of 22.40 for a sell order. Today’s close set us at 22.15, so I’m thinking I may want to reconsider that order. If the premium keeps running up like today, we may hit it without any price movement by BTC, and I may get stuck holding the cash. I’m going to sleep on it and see what happens overnight.

In spite of today’s mind-blowing rally, I still managed to get pulled into four different fires at work. And it gave me a bit of solace while dealing with the bullshit, knowing that none of it mattered and that ultimately I didn’t have to put up with any of it if I didn’t want to. I got so much done today, I even managed to take the girls to the playground for an hour this afternoon, cooked lunch and dinner and did grocery shopping.

All in all, today kicked ass in more ways that one.

Uniswap limit orders

Most people who are used to trading on centralized exchanges are familiar with using limit orders, where one is able to set orders that are off from the market price. Automated market makers such as Uniswap don’t have these features, which makes trading Uniswap-only pairs a bit of a problem, especially when one is trying to take advantage of volatile tokens such as $PRIA.

I’ve been looking for ways to set limit orders with Uniswap, and after several dead ends I’ve found two that may work. One is an on-chain protocol, the other is a bot.

On-chain method

Pine.Finance calls itself an AMM order engine. They only support limit orders on Uniswap v1 and v2, but they say they plan on adding stop loss and market functionality across the DEX space, like Aave, Balancer, and others. In order to use it, you have to submit the input token along with your order details through an on-chain transaction, then wait. When the price hits the target, Pine’s network relayer’s should execute the transaction.

There’s a lot more detail in the link above. What is important to note is that each order gets its own order vault, meaning that your order input funds will be stored in a discrete Ethereum address. You can see them on chain.

The project is in beta, and hasn’t been audited, so this one is use at your own risk. I did go ahead and put in a very small order that I’m still waiting on to execute. The gas cost was nominal, about as much as a standard transfer, but I’ll also have to pay gas if I want to cancel the order. This is similar to the way that on-chain DEX like iDEX or Metamask have worked in the past, although Pine is a custodial solution, probably a requirement of the fact that the relayer pays the gas when they execute the trade (and arbitrages the difference).

[Update: Pine replied wanted to clarify the custodial claims:

I’ll need some more time to delve into the process used here. What I am sure of is that during the order process, a deterministic funds vault is created, and tokens are transferred to this vault. Even trusting that these funds are self-custodial, they are removed from the user’s wallet. This may be similar to how 0x works, as mentioned below, and I promise to do more research and follow up on this. ]

Bot method

LimitSwap is a Uniswap limit order bot that is available on Github. After downloading, you’ll need to export your private keys and configure several settings to get things up and running. Set the tokens you want to trade, set your prices, and then let it go. You’ll also need to hold LimitSwap’s $LIMIT token in your wallet in order for the bot to function.

That’s the promise, anyways. I wasn’t willing to actually give it a shot. The project’s sole developer, who goes by the handle Crypt0Gnome, seem legit, but has taken steps to obfuscate his code. I understand his motives is to fund his development efforts via the $LIMIT token and prevent people from easily modifying his code to circumvent this requirement, but I’m not willing to trust my private keys with something like that.

I won’t go too far into the technical details but to say that he’s written the bot in Python using a Flask front-end and packaged all the dependencies in the zip file. This may make it easy for Windows users to get up and running, but shocked me a bit when I went to download the source code and found an empty repo.

I’m not trying to be unjustly harsh here, Crypt0Gnome seems to be sincere and to be community focused. However, in addition to the closed source nature of the project, I did find the Flask interface buggy and less than polished, and it was hard to justify digging into it when all I wanted to do was set a single limit order for a small amount. I do hope Crypt0Gnome can find a way to fund his project and open it up so that others might contribute to it as well. We’ll see.

The search continues

So while I’ve decided to do a small test transaction with Pine for now, I’m still looking for other solutions, preferably non custodial ones. The 0x protocol may offer a solution if one can find relayers supporting the tokens one wishes to trade, but I’ll need to do more research on that front to say more.

The bot approach would also be preferred over a custodial, on-chain solution if one is willing to maintain the bot, but a closed source solution with a single dev is a bit to risky for me to use, let alone recommend to others.

Google is a graveyard of dead links and others looking for solutions to this problem, so there is a need for it, but for now it seems that there is no good solution. I’ll keep searching and will probably do more research into both of these solutions for a future update.

Trading notes

Today was a pretty good day for crypto markets.

Jack Dorsey, CEO of Twitter and Square, announced that Square bought $50 million of bitcoin, about one percent of Square’s treasury. Markets pumped, and my portfolio did pretty good, up 4.52%.

That puts me up 50% in $GLDC after a week! $ETHE is above water finally, after a month. I spent a good deal of time trying to refine my new trade plan calculator, to figure out how to protect my position. I need to protect my capital, but I don’t have a rule yet on how to do that. The TD Sequential was supposed to be my indicator for stepping my stops, but I’m beginning to wonder whether my strategy is sound.

My recent strategy has been a bit of knife catching, trying to open a position when it marks a ‘nine’ down on the TDSeq. I set my far enough below support lines that I don’t get taken out by some whale hunting stops, and then wait. Here’s the most perfect example of what I’m talking about.

The hypothesis is that seller exhaustion will spawn a turn around on the nine mark, and the price will move up. I got lucky here.

The question now is what to do. From a capital preservation standpoint, I should raise my stop above my entry point to make sure that I don’t lose money. This will also open up my capital for another trade, since I’ve already got six percent of my capital at risk. I could tighten the stop to just under my entry, which would have a lesser protective effect.

Or I could take profit. I’m not going to do this, however, as I’ve started noticing another trend off of these TD Sequential signals. I’ve noticed that breaking above a green sell signal can mark the start of a parabolic run. In the GDLC chart above, you’ll see the green dotted line coming from the left. We have a daily close above it, and then two days later… POW! Seven to thirty-six dollars in three days. GDLC is a bit of a bad one to use as an example though, as the pump lagged a similar movement in BTC by three days.

While I figure out my strategy, I’ve been working on my trading spreadsheet, incorporating some new tips I’ve learned with regard to some formulas. Hopefully it will make my planning process more coherent in the future.

I really feel that things are really close to popping off. The fundamentals of bitcoin are strong, and despite all the bad news that has been going on lately, the market has been holding strong. I’m trying to prepare for some crazy times coming up. We’re less than a month away from the election, and who knows how things could go at this point. The fact that BTC hasn’t taken a tumble these last few weeks is very, very bullish, and I can’t wait to see what happens next.