In this article (continued from this one) I am going to play with Python a little bit. So, I will check whether a Python library installed previously (ccxt) is fit for purpose. I need to make some GET requests to Liquid.com’s API in order to retrieve some data and send some POST requests to place trades (sell orders or buy orders).
In the previous article (PART 1) I have achieved the followings:
- I have successfully opened an account with the Liquid exchange where my trading experience started and created an API token (and a Secret Key) both to be used in my Python scripts;
- Python was already installed on both a VPS (Virtual Private Server) and my laptop, and I have installed also the pip utility – useful to add Python open source code that generally is available on github;
- and I have installed (using pip) the first open source library, i.e. ccxt – mentioned above i.e. a Python wrapper of REST API, these APIs being available for the majority of crypto exchanges (Liquid.com included).
Also, in this article I will try to define my trading strategy and see what other discounts this cryptocurrencies exchange (Liquid.com) has to offer.
Well, I will start with discounts: Liquid exchange has a huge discount at trading fees upon the condition to buy their crypto token named “Qash” (or coin? … whatever) and allow paying fees with it (I don’t know if Qash has its own blockchain to be a coin or it is a token issued on Ethereum chain, but it does not matter because traders can buy Qash using Liquid exchange). Below an excerpt taken from their site:
“What role does Qash play?
All users are still able to receive a 50% discount on trading fees by paying with Qash. To pay your trading fees with Qash you must have a Qash balance in your Liquid account and turn on the option to pay fees with Qash in your account settings“.
So, one needs to buy a sufficient amount of Qash to cover the trading fees, configure the relevant setting as displayed above and bingo!
You got 50% discount on trading fees for all products 👍
Testing Liquid’s API using Python (ccxt library)
The code below lists the pairs existent on Liquid exchange:
import ccxt exchange = ccxt.liquid() exchange.loadMarkets() listaPerechilor=list() listaPerechilor=exchange.symbols for i in listaPerechilor: print(i)
When I hit the run button, the above code produces the following output:
That is a list of symbols (I counted 383 elements but above you see an excerpt).
By “symbols” ccxt library means trading pairs.
Therefore, I have successfully tested the connection of my code to Liquid.com’s API and I can obtain (using the mentioned code snippet) all 383 pairs available at Liquid exchange.
If a trader wants to buy Bitcoin and uses his/her available US Dollars for that purpose (assuming this is done through calling the API like I am going to show in this series of articles), then the trader has to use the symbol (trading pair) “BTC/USD”.
To sell Bitcoin and receive the equivalent of US Dollars, the same pair is to be used (of course) but in the opposite direction.
In this series of articles when I write in code a pair to be used further to any of the following activities: (i) place orders, (ii) get an order status or (iii) cancel an order or (iv) update an order, etc etc (to enumerate at least a few basic operations in trading using API) it would be like below:
pair="BTC/USD" # the variable pair will be used to communicate to Liquid API what # assets are to be bought or sold
Remark: the code snippet used to list the pairs did not use the API token because … it was not required. API token is something private to each and every trader and the list of pairs is public information.
On the contrary, placing orders using API is private. Therefore, such requests to Liquid’s API need to be authenticated first, meaning the API token created in the previous article (see this -> PART 1) will be used to (privately) manage your orders or checking your balances at Liquid.com exchange.
Available products at Liquid.com. Decisions, decisions … which one to pick?
Let’s analyze first two products:
- Spot Trading? Yes, but only when a crypto asset is going up. If you buy and then price goes lower the trader records a loss if he / she sells that asset. So, opportunities are only one way (price goes up) to make a profit.
- Margin Trading? As per this link (on Liquid website): “A margin trade is basically a bet, made with borrowed money, on 1) which way a product price will move and 2) how much it will move“.
I like more the “Margin Trading” product because I can take upon both opportunities, i.e. (i) when price goes up (ii) when price goes down. Is there any other possibility? 🤷♂️ Aah … yes: (iii) price doesn’t move.
Really? Nah … price will move. Especially in crypto. You now that joke? Daughter (blonde, sweet and persuading): Dad, I want to buy Bitcoin. Dad: Yes, sweety, of course. How much dollars do you need? Daughter: I don’t know, I just want to have 1 bitcoin as a souvenir (…). Dad: ok, one Bitcoin at …hold on … 35k dollars? So much? Why do you need to spend … (dad looking at the price chart) aaaa .. 36k dollars? I know someone who bought it for less, but now I have to pay … (chart doing its job) … aaaa … 38k $ ?!?
Plenty of volatility in crypto currencies … it’s bad for long term investors because … hmm .. well you don’t know if placing money today, until the year end an investor will gain or lose. Or until end of next year. It’s well known that bitcoin (and crypto market in general usually follows bitcoin) is so unpredictable … but for a speculative trader (this is one of my hobbies) it’s … quite a good chance to accummulate some profit! 👍
However, I am not greedy. I decided that I want to have 1% percent profit. Daily. I think in crypto assets market this is feasible. Won’t you think so?
If no, I understand. You say I am greedy.
Nah … I don’t give up.
If you don’t believe me this is achievable, please take a look at Bitcoin chart. It’s impossible not to take some opportunities for scalping that chart.
Problem is I don’t want to do a manual trading (I don’t have time), but what I am going to do is to start building a code aimed to be running 24/7 that is programmed beforehand to trigger a buy when a few pre-defined conditions are met.
If I buy (on Spot Trading) or I go long in Trading with Margin, after buying I expect a sell order will be placed also by that script. I expect my code to perform a sale when a profit is reached, or to sell at a pre-defined loss (let’s say at minus -15% referrenced to the buy level) if the target price is not reached and price goes so low.
And that’s all. Rinse and repeat.
Stop loss is a tool that is strongly recommended to be used if one is wise in trading, especially in crypto currencies. I want to protect my capital (although 2000 EUR is a small amount and this amount I can afford to lose, still I am going to do my best to not arrive with accounts emptied by bad trades).
Soooooo …… I studied some sources and looked at charts and … the pre-defined conditions to buy will be as follows:
- RSI (Relative Strength Index): <= 25
- Price increase: 0.1%
The above are two simple conditions that will trigger a buy order (when I will play in Spot and buy some crypto currency / asset or when I am going long on an asset in Margin Trading). They have to be both fulfilled (in the same time), or else there is no buy.
- The basics of trading reveal that RSI indicator shows the underlying (crypto) asset (token or coin) is oversold when RSI is below 30 and is overbought when RSI is over 70. This is valid in any timeframe, no matter the trading pair.
- The other condition, also valid for all pairs, i.e price to rise up (by 0.1% from the buy level – as compared to the previous candle) always does happen within a cycle. In fact, it happens all the time, but I am interested only when RSI enters the oversold range.
When RSI is going up (from oversold range) this means many traders start to buy, so price goes up quickly.
The second condition ensures buying at a lower price in the cycle. More precisely, I want to catch the moment at the change of trend, so when the price goes low, then RSI goes low too. Price continuing to go low, it comes a moment when price reaches the bottom of that cycle. At this moment (RSI being in oversold range) the price starts to rise and when it is going up by 0.1% (compared to the close of the previous candle) then … bam => buy order is placed.
If you look at majority of trading charts you might notice this pattern. When RSI approaches the bottom of oversold range (meaning price goes also at the bottom of that swing), if you wait a little bit more, there is a change. Then the price is going up quickly, so it is a very short window of opportunity to catch. A bot can help to get the job done and catch that moment (and buy earlier, i.e. when the price is yet no so high) by simply program it adequatelly.
So, the Python code will place a buy when the increase in price is yet a small increase, which I noticed watching charts that it is around 0.1%.
Selling part: hopefully, after placing the buy order the price will go up and the code I am going to build will place a sell order – let’s say – when price is +3% up (referenced to the buy level).
What is still to define – that I a have not yet decided – is the timeframe and the pair. But those are easy to code.
- The above trading strategy should work on both Spot Trading and Margin Trading. If one choses to trade with margin the difference between trading in Spot and trading with Margin is more profit / more loss when he/she trades with margin. This is because losses happen when market turns in the opposite direction of your trade and if the trader borrows money (this is the nature of Margin Trading product), the loss is larger. Vice-versa, i.e. more profit with Margin compared with Spot trading (when market “behaves”, i.e. the trade is going as planned) it’s also true because you borrow money and make profit also with those funds (besides the profit you make with your own funds).
- I know the trading strategy I am going to employ is a not a strong one. A professional trader expects a couple of conditions / indicators to be met plus another couple of other conditions / indicators to confirm a trend change before he/she becomes confident to buy, but I am good with it. So, I don’t expect my accout to go slim, at least not so soon (if it will ever do). But if so, then so be it. This experiment will stop. That’s it.
- Although this is not a super trading strategy, I expect to accummulate some profit in my account, but the most important target to be achieved is to have a 24/7 bot running and placing trades (some of them will be winning, some will be losing). Later on I will be tweakening this bot / code until it gives me a satisfactorily profit. If it will ever do that … ha ha ha …
- Improvement comes with experience in trading and I think I am gonna gain some experience during this exercise. Not much – because I will not allocate significant time for it (see this series of article that is published during week-ends), but some will mount (hopefully). I am prepared to take also some paid courses on internet – if I can make available more time for this. Finally, I hope at some point to have been added other conditions that need to be meet in order to trigger a buy/long or a sell/short. I am talking about – for example – 1) confirmations of trend change like MAs* crossover 2) other bullish flags like volume increase 3) bullish divergences 4) candlestick patterns and so on. For me the beauty of this experiment is more the automation of such trading, no matter the strategy employed.
- Let’s say I have success with the above strategy (hopefully) and first signs are good, profit is reached. I am aware that going further with any trading strategy and before to add more money into it, some tests will have to take place. So, at a later stage I am going to make my homework how this testing is done elsewhere and will employ some form of testing (or backtesting) in this project.
*) MA = Moving Averages. There are three MAs: 9 days, 21 days and 99 days used in trading stocks, but also in trading crypto currencies (I saw all of them defined as such in most crypto-currencies exchanges by default). Details will be provided at a later stage.
Coming back to the products existent in Liquid.com exchange. I look at that option no.2 (Margin Trading). This is with … borrowed money… Hmm … What is the interest on those borrowings? I want to know because an interest is a cost, so profit diminishes. But it shouldn’t be a fortune, right?
Let’s dig in to see exactly how high is this interest (will do this in PART 3).
So far I have completed the below steps:
- I took advantage of reduced fees at Liquid exchange and I configured some setting in my account opened with Liquid in order to pay such fees with Qash (50% discount on trading fees …. yeeyee…) 👍
- I started to assess the available products at Liquid exchange besides Spot Trading, namely Margin Trading (not decided though if I want to trade with margin or not) because fees are to be assessed (I will do it in the next article) and – most important – trading with high leverage is addicting and if you are wrong on a trade your account could be wiped out (liquidated) easily. Therefore, if I am going to trade with margin I’ll do it with minimum of leverage (I think 2x could be enough for this experiment – I will provide details as this series or articles unfolds) and with Stop Loss (of course).
- I have build a small code snippet using ccxt library (a Python wrapper for APIs of 100+ crypto exchanges that includes Liquid.com’s API) that lists all the available pairs at this exchange
- I have defined my trading strategy, not a perfect one, but subject of further improvements that hopefully will come along with gaining experience in trading, yet sufficient to get me motivated to achieve the final objective of this series of article: to automate trading by creating a bot that will trade 24/7 based on the underlying trading strategy. With good profits. Let’s hope for the best, but prepare for the worst (crypto is so volatile and a market in early stages of development that one needs to be very, very careful as many reported losses)
- I did not place (not yet) any buy or sell order in this article because first I needed to design a trading strategy. Rushing is not my strong point, better to plan twice and execute once. A trading strategy is a must. I am comfortable with learning by doing and the readers might need to be patient enough … because they will be rewarded with a Python code that will be soon shown in its splendor … 🏆 … and will be accessible to all for free.
In PART THREE of this series of articles I am going to continue with this endeavor that is challenging and started already to motivate me because it looks … veeeeery promissing 👍