In in experience the vast majority of the code of a trading application is dedicated to safety: pre/post trade checks, price checks, open notional, pnl delta limits, order rate, fill rate etc. And of course error handling and getting out of unexpected states safely and quickly.
FWIW, I just took a look at our HFT trading system. We specialize in colocated low latency market making in an equity market in a mid-sized country. The following line counts are only for the C++ code directly used in the production system. Doesn't count research, model fitting, ETL pipelines, build systems, etc.
75 kloc - Total line count
10 kloc - Common libraries, utilities, data structures, etc.
10 kloc - Reconstitutes the limit order book from the data feed
10 kloc - General framework (order management, margin tracking, logging, runtime control hooks, etc.)
13k - Adapter for the exchange's datafeed protocol
5k - Adapter for the exchange's order gateway protocol
3k - System for correlating our orders within the datafeed
10k - Signals/alphas
8k - Trading logic
Not claiming that other people's systems will necessarily look anything like ours, but my experience jibes with this too. Trading code is only about 10% of the total codebase for a production-ready trading system. Overall strategy-specific code (signals and trading logic) only make up 25% of the codebase, with the rest being all general-purpose "plumbing".
Even a tiny inconsequential function that most people never think about- reliably identifying which orders in the data feed belong to us- takes nearly half the amount of code as nearly all the trading logic put together.
You might want to replace the `openOrders.forEach ...` call with a call to `await Promise.all(openOrders.map ...)` if you want to catch errors and stop the program when cancelling previous orders, and more importantly make sure you cancel orders before doing anything else.
It seems the price coming back from cryptonator doesn't update, TUSD is a stable coin but surely the bitcoin rate against it should be updating every 30s ?
https://api.cryptonator.com/api/ticker/btc-tusd
It also seems exceptionally risky to grab a price off some random website and then trade blindly on another. Shouldn't you be getting the prices from the market you are actually trading in?
One redeeming quality of cryptocurrencies existing is that all the exchanges have REST compliant APIs and real time data available for free
The finance sector’s biggest meme for the last decade and a half was that PhD quants were required to program trading algorithms when really a single exchange cost $12,000 a month for real time data, it came with horrible documentation, support, antiquated protocols, FIX, and then you had to figure out how to co-locate your own server to connect to the exchange fast enough to prevent front running
The gatekeeping is what kept this specialized for the most part
Those that do not understand FIX are doomed to reinvent it badly. I only got an appreciation for the protocol when I implemented a FIX server from scratch. Even the wierd text+field delimiter encoding is not bad (except for performance of course).
Session management, order entry and recovery in FIX is well designed and well documented (although it takes a few readings of the spec to put the pieces together). The biggest issue is the plethora of underdocumented extensions that have been bolted on to satisfy niche needs. If you are lucky you can ignore them most of the time.
Another big issue is a lot of exchanges treat FIX as more of a guideline than an hard spec and you have to workaround the lossage.
The best exchange binary protocols I have worked with (at least here in EU, borrow heavily from FIX.
> The gatekeeping is what kept this specialized for the most part.
It certainly kept the vast majority of retail out, but I disagree that this was the main cause of specialization. I think that the number of lone geniuses who could've beat the market using algo trading is a number approaching zero.
It's true that you don't need a PhD, or even higher education, as the math you need can be entirely self taught. However, you need plenty of specialized knowledge to avoid the accidental discharge of the vast number of very expensive footguns that litter the landscape. This knowledge can be gained from literature, but without having someone streetwise as a guide, it's going to be very difficult to discern genuine insight from wishful thinking.
This reminds me of the movie "The Hummingbird Project" - https://www.imdb.com/title/tt6866224/ , where speed matters in all Financial transactions and even a 1ms matters in the game
> Just believing really hard that the law doesn't apply to you doesn't make it true.
If you just want to trade crypto/crypto, many exchanges don't require a KYC process. If you want to deposit/withdraw actual dollars, that's a different story.
In any event, KYC is something that exchanges are responsible for, not its customers.
I'm scratching my head wondering what the hell that actually that's supposed to mean. Their terms when you sign up do mention a KYC process:
> Blockbid is registered with the Australian Transaction Reports and Analysis Centre (AUSTRAC) which is the regulatory body that deals with the Anti-Money Laundering and Counter-Terrorism Financing Act 2006 (AML/CTF Act).
> [... truncated ...]
> Blockbid operates a Know Your Customer (KYC) and AML/CTF Program that meets the requirements of the AML/CTF Act (and associated laws).
Ya, that probably wont last long if the exchange is centralized. Would have to re implement on bisq/kyber/uniswap or another decentralized exchange for this to last without KYC. Then of course you have to deal with massively increased latency/network speed to settle trades.
If any wants to try their hand at quant trading, Quantopian is a great place to get started. Great data sources and you can get allocated capital and make a little bit of money. Also the competitions are fun and you get paid $50/day for having (essentially) the best Sharpe ratio.
If you want to trade your own money, Alpaca is really awesome. Pretty easy to import an algorithm from Quantopian and use it on Alpaca.
I’ve been managing about 15% of my portfolio through Alpaca and it’s been great. On my account, I can get 4x intraday leverage, which has been absolutely awesome. Also there’s no trading costs, so I don’t have any problem with daily rebalancing (I actually rebalance to 4x leverage in the morning and deleverage at the end of the day).
Highly recommended! There’s a lot of alpha in the market for retail investors (with leverage, no transaction costs, and the ability to short).
Actually, it's not irrational for non-rich smart people to gamble ie poker is a game where skill almost always wins the day, and betting baseball parlays can, with a good deal of study, land in a positive expectation.
Furthermore, the sheer number of quite profitable high speed trading platforms seems to totally rebuke your assertion.
I understand that back-testing is a foolish way to work out whether a bot works, but it'd be interesting to see how this performs on arbitrary lengths of past history.
Like, is this enough to beat a lazy index fund calculated over the same time, with interest reinvested?
Why is backtesting foolish? As long as you haven't used the data you're using to backtest in any way, it seems like a reasonable way to test your strategy.
I can see that there is no variable of "fees" which usually applies even on a LIMIT order.
For example Coinbase Pro has Maker fees of 0.15%. Ideally this fees should be added to BUY order and subtracted from SELL order, as that will actually cost you.
Cool stuff. 20% Deviation from the market price is quite high though. I suppose orders will never get a chance to execute. What would be a more realistic percentage? Could it be based on the current volatility for example? Or am I missing something.
No, it is indeed fairly insane. It's a good proof-of-concept of API-based trading, but I am far too timid to trust this sort of thing to a bot, especially considering that other people are running better bots.
tbf, you ought to be getting alarm bells from "Australian crypto exchange, no KYC required" long before we start looking at whether the coding approaches are remotely sane.
Considering the well established likelihood of a flash crash in the markets you're trading in, the exchange's own code being stuck together with duct tape or your/their assets being frozen, you probably shouldn't be trading anything you're not willing to lose to buggy javascript anyway.
[+] [-] gpderetta|6 years ago|reply
40 lines of JS definitely scare me.
[+] [-] dcolkitt|6 years ago|reply
75 kloc - Total line count
10 kloc - Common libraries, utilities, data structures, etc.
10 kloc - Reconstitutes the limit order book from the data feed
10 kloc - General framework (order management, margin tracking, logging, runtime control hooks, etc.)
7 kloc - Safety checks (pre/post trade, price, circuit breakers, etc.)
13k - Adapter for the exchange's datafeed protocol
5k - Adapter for the exchange's order gateway protocol
3k - System for correlating our orders within the datafeed
10k - Signals/alphas
8k - Trading logic
Not claiming that other people's systems will necessarily look anything like ours, but my experience jibes with this too. Trading code is only about 10% of the total codebase for a production-ready trading system. Overall strategy-specific code (signals and trading logic) only make up 25% of the codebase, with the rest being all general-purpose "plumbing".
Even a tiny inconsequential function that most people never think about- reliably identifying which orders in the data feed belong to us- takes nearly half the amount of code as nearly all the trading logic put together.
[+] [-] thomasfromcdnjs|6 years ago|reply
The script is a tutorial to help complete beginners have an understanding of how to write a bot.
Though you're right, I should have really made it more clear because it is real money.
[+] [-] flyGuyOnTheSly|6 years ago|reply
The bot I am currently working on is pushing 6,000 lines of code, and I feel like it might double in size before it's perfect.
[+] [-] benj111|6 years ago|reply
Me too.
I suppose it depends how you want to treat this though.
As a bot programming challenge this seems fair enough. As something to entrust your or others life savings with? No.
[+] [-] gildas|6 years ago|reply
[+] [-] thomasfromcdnjs|6 years ago|reply
[+] [-] haolez|6 years ago|reply
https://github.com/ccxt/ccxt
[+] [-] dcsan|6 years ago|reply
It seems the price coming back from cryptonator doesn't update, TUSD is a stable coin but surely the bitcoin rate against it should be updating every 30s ? https://api.cryptonator.com/api/ticker/btc-tusd
https://www.cryptonator.com/api/ > Prices are updated every 30 seconds
[+] [-] joosters|6 years ago|reply
[+] [-] dcsan|6 years ago|reply
https://apiv2.bitcoinaverage.com/#price-data this seems like a better free API, wondering what others use? is there anything with tickdata not just 15s?
[+] [-] rolltiide|6 years ago|reply
The finance sector’s biggest meme for the last decade and a half was that PhD quants were required to program trading algorithms when really a single exchange cost $12,000 a month for real time data, it came with horrible documentation, support, antiquated protocols, FIX, and then you had to figure out how to co-locate your own server to connect to the exchange fast enough to prevent front running
The gatekeeping is what kept this specialized for the most part
[+] [-] gpderetta|6 years ago|reply
Those that do not understand FIX are doomed to reinvent it badly. I only got an appreciation for the protocol when I implemented a FIX server from scratch. Even the wierd text+field delimiter encoding is not bad (except for performance of course).
Session management, order entry and recovery in FIX is well designed and well documented (although it takes a few readings of the spec to put the pieces together). The biggest issue is the plethora of underdocumented extensions that have been bolted on to satisfy niche needs. If you are lucky you can ignore them most of the time.
Another big issue is a lot of exchanges treat FIX as more of a guideline than an hard spec and you have to workaround the lossage.
The best exchange binary protocols I have worked with (at least here in EU, borrow heavily from FIX.
[+] [-] short_sells_poo|6 years ago|reply
It certainly kept the vast majority of retail out, but I disagree that this was the main cause of specialization. I think that the number of lone geniuses who could've beat the market using algo trading is a number approaching zero.
It's true that you don't need a PhD, or even higher education, as the math you need can be entirely self taught. However, you need plenty of specialized knowledge to avoid the accidental discharge of the vast number of very expensive footguns that litter the landscape. This knowledge can be gained from literature, but without having someone streetwise as a guide, it's going to be very difficult to discern genuine insight from wishful thinking.
[+] [-] tardis_thad|6 years ago|reply
[+] [-] uberneo|6 years ago|reply
[+] [-] mercutio88|6 years ago|reply
[+] [-] Severian|6 years ago|reply
ie 0.2 * 0.1
[+] [-] uberneo|6 years ago|reply
parseFloat((0.2 * 0.1).toFixed(10))
[+] [-] JustFinishedBSG|6 years ago|reply
Just believing really hard that the law doesn't apply to you doesn't make it true.
[+] [-] gridlockd|6 years ago|reply
If you just want to trade crypto/crypto, many exchanges don't require a KYC process. If you want to deposit/withdraw actual dollars, that's a different story.
In any event, KYC is something that exchanges are responsible for, not its customers.
[+] [-] koolba|6 years ago|reply
> Blockbid is registered with the Australian Transaction Reports and Analysis Centre (AUSTRAC) which is the regulatory body that deals with the Anti-Money Laundering and Counter-Terrorism Financing Act 2006 (AML/CTF Act).
> [... truncated ...]
> Blockbid operates a Know Your Customer (KYC) and AML/CTF Program that meets the requirements of the AML/CTF Act (and associated laws).
[+] [-] cdiddy2|6 years ago|reply
[+] [-] mruts|6 years ago|reply
If you want to trade your own money, Alpaca is really awesome. Pretty easy to import an algorithm from Quantopian and use it on Alpaca.
I’ve been managing about 15% of my portfolio through Alpaca and it’s been great. On my account, I can get 4x intraday leverage, which has been absolutely awesome. Also there’s no trading costs, so I don’t have any problem with daily rebalancing (I actually rebalance to 4x leverage in the morning and deleverage at the end of the day).
Highly recommended! There’s a lot of alpha in the market for retail investors (with leverage, no transaction costs, and the ability to short).
[+] [-] DennisP|6 years ago|reply
[+] [-] edf13|6 years ago|reply
[+] [-] logiclogic|6 years ago|reply
[+] [-] cubano|6 years ago|reply
Furthermore, the sheer number of quite profitable high speed trading platforms seems to totally rebuke your assertion.
[+] [-] Can_K|6 years ago|reply
Luckily, there are now tools such as Accointing or CryptoTax that take care of the 30,000 transactions.
[+] [-] mercutio88|6 years ago|reply
[+] [-] unknown|6 years ago|reply
[deleted]
[+] [-] throwaway77384|6 years ago|reply
[+] [-] gentaro|6 years ago|reply
[+] [-] thomasfromcdnjs|6 years ago|reply
I will give a shout to these guys if anyone is interested in back testing -> https://www.coinapi.io/
[+] [-] thomasfromcdnjs|6 years ago|reply
I'd be happy to answer any questions to the best of my ability.
[+] [-] uberneo|6 years ago|reply
[+] [-] mercutio88|6 years ago|reply
[+] [-] snvzz|6 years ago|reply
>trading money
>in javascript
Am I alone in thinking this is insane?
[+] [-] rubbingalcohol|6 years ago|reply
[+] [-] notahacker|6 years ago|reply
Considering the well established likelihood of a flash crash in the markets you're trading in, the exchange's own code being stuck together with duct tape or your/their assets being frozen, you probably shouldn't be trading anything you're not willing to lose to buggy javascript anyway.
[+] [-] unnouinceput|6 years ago|reply
[+] [-] alexeiz|6 years ago|reply
[+] [-] throwaway857384|6 years ago|reply
[+] [-] epscylonb|6 years ago|reply
[+] [-] analpaper|6 years ago|reply
[+] [-] miroshnik|6 years ago|reply
[+] [-] justanegg|6 years ago|reply
[deleted]