8 ms·
Show HN: Simple algorithmic trading in JavaScript
- hliyan 12y agoYour login, register and demo links are not functioning.
- Cloud9Trader 12y agoThanks. Can't see any issues our side and getting plenty of successful registrations. Which browser please?
- hliyan 12y agoChrome 36. Refresh solved the problem (seems the buttons silently fail if there are network issues). Now having trouble connecting to the broker servers. Network on my end is now fine, though. I was waiting to see the thing in action before commenting, but here goes anyway. What are your latencies like (market data and orders)? Do your algo's have to depend entirely on current indicators/market data, or is there a way to use historical data? I'm a former HFT/algorithmic trading systems dev myself and the performance requirements in that particular domain was pretty high. At one point, even C++ and close-packed binary data transfer wasn't enough. I was wondering how you're managing with Javascript?
- Cloud9Trader 12y agoPlease let me know if you're continuing to have issues. All seems fine my end. You can stick the following in your browser console to log server latency stamps on incoming market data: require(["registry"], function (registry) { var instrument = registry.get("instruments").get("EUR/USD"); instrument.on("tick", function (data) { console.log("Server latency (ms):", data.get("serverLatency")); }); }); Of course replace "EUR/USD" for whichever instrument you want to monitor. 10-20ms is typical for comms between our instances and the brokers (we get similar results for outgoing trade execution requests, factoring in the round trip). Our stack is largely JavaScript. We've found NodeJS to be blisteringly fast and lending itself perfectly for this kind of application (low memory, high throughput, heavy processing). We have a backesting framework for running against historical data. Do you have a requirement for pulling historical data into an algorithm during live trading? We haven't included this in out API, though it would be fairly trivial to implement. It's key though that algos run with as little in memory data as possible. We also include a framework for writing your own custom technical indicators. These are naturally set up to pull historical data so may be what you're after. These and the built in indicators can be used in your script by just calling e.g. sma(10)
- hliyan 12y agoWorks after a re-login. Very nice!! Two final questions: 1. Does the API allow writing an algorithm that deals with more than one instrument? 2. Thought about including Bitcoin?
- Cloud9Trader 12y agoThanks! Currently the API doesn't support multiple instruments though an individual trading session already pulls in whatever currency pairs are required to convert from term currency to your account currency to calculate unrealized profit and to allow you to set quantity in as a risk percentage of account balance... basically not much work involved in supporting. Will get it prioritised. Definitely would like to include Bitcoin and are looking into our options at the moment.
- deleted 12y ago[deleted]
- foenv 12y agoSorry if I missed it - I couldn't see on your site which brokers you intend to connect with for live trading. Thanks
- Cloud9Trader 12y agoWe currently support live connections to FXCM. The welcome page gives you the option of choosing a demo account or sticking in FXCM details. We will be adding a wide selection of brokers to that list and will prioritize on basis of demand. Please let us know if there are any particular brokers you'd like us to support.
- dingdingdang 12y agoIntegration with Oanda would be great.
- Cloud9Trader 12y agoOanda offer FIX connectivity, so very doable - we've already built FIX adapters in NodeJS. Will get the ball rolling.
- UnethicalHacks 12y agoplease message me when Oanda functionality is live.
- smrtinsert 12y agoHaving worked with FIX, I feel for you.
- abrkn 12y agohttp://wiki.justcoin.com/REST_API http://wiki.justcoin.com/REST_API
- pathikrit 12y agoLooks cool! Another: https://www.quantopian.com https://www.quantopian.com
- BozeWolf 12y agoThis is actually interesting if you combine it with the other HN thread currently on the FP. Its about pyrasite.com, which allows you to read/write into another python process. https://news.ycombinator.com/item?id=8160149 https://news.ycombinator.com/item?id=8160149 Im wondering how they do this.
- neuralk 12y agoYou linked to the wrong thread. I believe you meant this one: https://news.ycombinator.com/item?id=8161586 https://news.ycombinator.com/item?id=8161586
- CmonDev 12y agoWriting critical code in JavaScript? That's interesting.
- ris 12y agoHey, well, if you're going to engage in a practice that potentially destabilizes the entire global economy, why not do it in javascript?
- logn 12y agoGarbage collection would be a problem in realtime algos. And efficiency is ~10x slower than C. But as far as writing bug free code, I'd take JavaScript over C. But I'd take Java over both of them and the JVM has a lot of GC configuration options (in addition to real-time JVMs, but those can cost a lot of money). Anyhow, for user-submitted code like this trading site, I think JS is the only realistic option since it can be sandboxed so safely.
- mikkom 12y ago> We believe algorithmic trading is simple Trading might be simple but being profitable definitely is not.
- brownegg 12y agoI'm in the "professional automated trading" space. This is by far the most common vendor mistake. "We make trading simple!" is pretty much a surefire way to mediocrity at best. "We make tax law simple!" "We make heart surgery simple!" ^^ similar silly things, only you don't ever see them The thing is, no one actually DOES make anything simpler. They just restrict the toolset with which you can solve problems to things that work for the 80% cases.
- sillysaurus3 12y agoWould you mind giving any examples?
- deleted 12y ago[deleted]
- stzup7 12y agoQuick example, I want to build a dynamic portfolio based on a subset of S&P 500, with no sectors exposure, no market exposure (delta and beta flat), no capitalisation exposure, and I want to avoid trading a stock from one week before until one week after their earning announcements. This is a very simple example of a common portfolio universe but tools like quantopian and cloud9trader (even though the latter doesn't support stocks yet so they're out of scope here) just don't provide the required data. I can't find an index historical composition, security data doesn't include its market cap, its sector, the next earnings announcement date. I can't even start working on my signals since I'm unable to select my stocks.
- Iftheshoefits 12y agoI don't think this platform is for equities (yet?). They only support FXCM, which is a spot FX outfit. Based on the pricing, it seems to me these guys are targeting, mainly, retail FX traders.
- CWIZO 12y agoGood job Kafton :) Glad you released it :)
- Cloud9Trader 12y agoHa! thanks buddy!
- cwmma 12y agoSo there is a reason you don't see much financial stuff written in JavaScript, doubles plus financial really don't mix.
- CWIZO 12y agoThat's not true. Our company (http://www.caplin.com/business/page/fx-motif http://www.caplin.com/business/page/fx-motif) provides SDP solutions written in JavaScript. Works great.
- ramchip 12y agoAutomated trading systems very often use doubles for money, and so do quant libs.
- compare 12y agoCorrect. The solution is usually that they'll just create special functions for doing numeric comparisons, that accept an adjustable epsilon margin of error, to use instead of the built-in numeric comparison functions. There're a lot of silly myths about investment software on hacker news / reddit. Truth is that the code is usually much more hastily written, but with more tests or redundant systems implemented to cross validate results. The idea that precise decimal types will be used throughout the systems is a bit silly. All the data typically will be going though off the shelf machine learning models, all of which just used plain floating types.
- sillysaurus3 12y agoA double can store every integer from -2^53 to 2^53, which seems sufficient to do financial work. 2^53 is 9,007,199,254,740,992 If you want to denote that the last three digits are for fractional dollars (i.e. each integer represents 1/10th of a penny) then you can store any monetary value from -$9 trillion to $9 trillion. EDIT: Note that it's tempting to think that you can skip converting decimal currency to integer as long as you only use <= 3 digits after the decimal and you're storing values of less than 9 trillion, i.e. it's tempting to think you're safe storing a value like $1,283.212 directly in a double without converting to integer. But I'm pretty sure that's mistaken. You always need to convert to integer so that you're storing 1,283,282 in a double, not $1,283.212 The reason is because certain decimal values which can be represented in base 10 can't be represented in base 2. For example, $0.1 can't be stored into a double as-is; if you try to store 0.1 into a double, you'll get: 0.1000000000000000055511... which is where the inaccuracies can start to come into play. Whereas if you convert $0.1 to integer, you'll be storing the value 100 into a double, which comes out to exactly 100 without any error. Of course, the error may be so small as to be insignificant, but the point is, I'm absolutely certain that integers between -2^53 and 2^53 can be perfectly represented by doubles, but I'm not certain that <= 3 digits of decimal precision can always be accurately represented by doubles for values of less than 9 trillion. EDIT2: You have to be careful when converting between currencies, too. For example, right now $2 = 204 yen. If you're storing yen, 2^53 yen is different from 2^53 one-tenth-pennies, so the max value that you can store is specific to each currency. This seems like potentially a tricky problem, and may be what the parent commenter was referring to when saying doubles aren't so good for financial work. Still, though, 2^53 integers of precision may be sufficient regardless of which currency you're using.
- jgunaratne 12y agoIt looks like this is only for currency trading at the moment. Do they allow other assets to be traded?
- Cloud9Trader 12y agoCurrently FXCM (the first broker we've integrated with - more to come) offer forex in the US and also CFDs on indices, treasury and metals elsewhere.
- chollida1 12y agoThere was a company last week that showed off their bitcoin algos and I wrote a comment that basically said don't use them and I felt bad about it for the rest of the week. I'll try to just be positive here:) To weigh in on the mention of using doubles for finance.... Using double for finance, perfectly fine. All trading systems I've seen use double, from HFT systems to deep learning AI systems that open and close potions over months. Double is fine for most algo trading, heck the exchanges and dark pools I've talked with use double. What you can possibly do with this. 1) Learn how to write the logic of an trading algorithm. 2) learn the basics of technical trading, with MACD, Keltner channels, vortex and Bollinger band indicators. They've definitely put the time in to getting the indicators that FX traders like to use. What you can't do with this system. 1) React to currency fluctuations on a tick by tick basis. FX is just so fast and precise, there is a reason that professional FX traders mix FX spot quotes from multiple sources, we use 4 at the fund I work at and some use up to 10 sources. There is also a reason why FX is quoted to 4 decimal places while equities are to 2, sometimes 3 for penny stocks. 2) Use this in a real world setting. I can't see any privacy policy or contract indicating what happens when shit goes wrong. We are talking about money here, you can't just half ass this kind of thing. Plus they use FXCM which had this new out about them: http://online.wsj.com/news/articles/SB10001424052702304255604579406640141660638 http://online.wsj.com/news/articles/SB1000142405270230425560... > LONDON—Foreign-exchange trading firm FXCM Inc. FXCM +0.08% agreed to pay fines and refunds totaling almost £10 million ($16.7 million) to settle allegations by a U.K. financial regulator that the company withheld profits from clients and failed to inform British authorities that it was under investigation in the U.S. > The Financial Conduct Authority said that U.K. units of FXCM withheld £6 million from customers on foreign-exchange transactions between August 2006 and December 2010. The regulator said the broker pocketed profits when exchange rates moved in its customers' favor while a trade was in process, but it passed on losses that occurred on other trades.
- throwaway283719 12y ago> There is also a reason why FX is quoted to 4 decimal places while equities are to 2, sometimes 3 for penny stocks. Isn't the reason that most FX rates are O(1) (eg EURUSD is about 1.34, cable is about 1.7) whereas most stocks are O(10) or even O(100) and O(1000)? If you take an FX rate that isn't O(1) eg USDJPY which is about 100, the convention is that it's quoted to 2 decimal places, like a stock (though there are some exceptions, eg USDMXN is around 13 but it's quoted to 4dp, and USDRUB is around 35 and also quoted to 4dp).
- radikalus 12y agoI hope to not come off as too critical, but there's a ridiculously wide margin between this and what trading firms in the low latency space do. I don't know of a single firm that's successful in the time horizon that a lot of pseudo-HFT systems operate in. (The 10ms-3s range) And that's assuming an ideal fee situation... Most of the people ignoring the LL arms race target RV opportunities on the 30s+ range. This involves taking a pretty big step back from microsctructure/toxicity models.
- eastbayjake 12y ago> Most of the people ignoring the LL arms race target RV opportunities on the 30s+ range. This involves taking a pretty big step back from microsctructure/toxicity models. Would you mind explaining more about this?
- ErikRogneby 12y agoCould anyone find a list of what markets this supports?
- deleted 12y ago[deleted]
- DanBC 12y agohttp://www.phrases.org.uk/meanings/on-cloud-nine.html http://www.phrases.org.uk/meanings/on-cloud-nine.html
- MalcolmDiggs 12y agoGreat concept, looking forward to checking it out. Just curious, is this the same team that did Cloud9IDE? (c9.io) or just a naming coincidence?
- Cloud9Trader 12y agoNope, purely naming coincidence... at the moment only aspiring to provide as excellent a development workspace as Cloud9IDE does.
- jaredbroad 12y agoType safety lets you avoid all sorts of wonderful JS bugs :) https://www.quantconnect.com https://www.quantconnect.com
- wwwwwwwwww 12y agowho needs type safety when you have all the web scale of javascript?