From Zero to Forex Trading Bot Hero with Node.js and Typescript

From Zero to Forex Trading Bot Hero with Node.js and Typescript

From Zero to Forex Trading Bot Hero with Node.js and Typescript: During this talk, you will discover Daniele's journey building a trading bot. From building a basic prototype in Typescript to using functional programming techniques to trade autonomously across multiple foreign exchanges and generate thousands of dollars in revenue.

During this talk, you will discover Daniele's journey building a trading bot. From building a basic prototype in Typescript to using functional programming techniques to trade autonomously across multiple foreign exchanges and generate thousands of dollars in revenue.

By the end of the talk you will learn:

  • The basics of financial trading platforms from a developer's perspective (APIs/concepts/terminology)
  • How you can use the skills you've gained building full stack applications to write trading software
  • How static typing and Typescript can speed up your workflow
  • How functional programming can help you refine your trading algorithms and verify the correctness of your program

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow us on Facebook | Twitter

Further reading about Node.js and Typescript

The Complete Node.js Developer Course (3rd Edition)

Creating RESTful APIs with NodeJS and MongoDB Tutorial

Build a web scraper with Node

React + TypeScript : Why and How

From Javascript to Typescript to Elm

Python for Financial Analysis and Algorithmic Trading

Top 7 Most Popular Node.js Frameworks You Should Know

Top 7 Most Popular Node.js Frameworks You Should Know

Node.js is an open-source, cross-platform, runtime environment that allows developers to run JavaScript outside of a browser. In this post, you'll see top 7 of the most popular Node frameworks at this point in time (ranked from high to low by GitHub stars).

Node.js is an open-source, cross-platform, runtime environment that allows developers to run JavaScript outside of a browser.

One of the main advantages of Node is that it enables developers to use JavaScript on both the front-end and the back-end of an application. This not only makes the source code of any app cleaner and more consistent, but it significantly speeds up app development too, as developers only need to use one language.

Node is fast, scalable, and easy to get started with. Its default package manager is npm, which means it also sports the largest ecosystem of open-source libraries. Node is used by companies such as NASA, Uber, Netflix, and Walmart.

But Node doesn't come alone. It comes with a plethora of frameworks. A Node framework can be pictured as the external scaffolding that you can build your app in. These frameworks are built on top of Node and extend the technology's functionality, mostly by making apps easier to prototype and develop, while also making them faster and more scalable.

Below are 7of the most popular Node frameworks at this point in time (ranked from high to low by GitHub stars).

Express

With over 43,000 GitHub stars, Express is the most popular Node framework. It brands itself as a fast, unopinionated, and minimalist framework. Express acts as middleware: it helps set up and configure routes to send and receive requests between the front-end and the database of an app.

Express provides lightweight, powerful tools for HTTP servers. It's a great framework for single-page apps, websites, hybrids, or public HTTP APIs. It supports over fourteen different template engines, so developers aren't forced into any specific ORM.

Meteor

Meteor is a full-stack JavaScript platform. It allows developers to build real-time web apps, i.e. apps where code changes are pushed to all browsers and devices in real-time. Additionally, servers send data over the wire, instead of HTML. The client renders the data.

The project has over 41,000 GitHub stars and is built to power large projects. Meteor is used by companies such as Mazda, Honeywell, Qualcomm, and IKEA. It has excellent documentation and a strong community behind it.

Koa

Koa is built by the same team that built Express. It uses ES6 methods that allow developers to work without callbacks. Developers also have more control over error-handling. Koa has no middleware within its core, which means that developers have more control over configuration, but which means that traditional Node middleware (e.g. req, res, next) won't work with Koa.

Koa already has over 26,000 GitHub stars. The Express developers built Koa because they wanted a lighter framework that was more expressive and more robust than Express. You can find out more about the differences between Koa and Express here.

Sails

Sails is a real-time, MVC framework for Node that's built on Express. It supports auto-generated REST APIs and comes with an easy WebSocket integration.

The project has over 20,000 stars on GitHub and is compatible with almost all databases (MySQL, MongoDB, PostgreSQL, Redis). It's also compatible with most front-end technologies (Angular, iOS, Android, React, and even Windows Phone).

Nest

Nest has over 15,000 GitHub stars. It uses progressive JavaScript and is built with TypeScript, which means it comes with strong typing. It combines elements of object-oriented programming, functional programming, and functional reactive programming.

Nest is packaged in such a way it serves as a complete development kit for writing enterprise-level apps. The framework uses Express, but is compatible with a wide range of other libraries.

LoopBack

LoopBack is a framework that allows developers to quickly create REST APIs. It has an easy-to-use CLI wizard and allows developers to create models either on their schema or dynamically. It also has a built-in API explorer.

LoopBack has over 12,000 GitHub stars and is used by companies such as GoDaddy, Symantec, and the Bank of America. It's compatible with many REST services and a wide variety of databases (MongoDB, Oracle, MySQL, PostgreSQL).

Hapi

Similar to Express, hapi serves data by intermediating between server-side and client-side. As such, it's can serve as a substitute for Express. Hapi allows developers to focus on writing reusable app logic in a modular and prescriptive fashion.

The project has over 11,000 GitHub stars. It has built-in support for input validation, caching, authentication, and more. Hapi was originally developed to handle all of Walmart's mobile traffic during Black Friday.

Best Practices For Using TypeScript with Node.js

Best Practices For Using TypeScript with Node.js

Opinionated and useful examples on when and how to best use TS with Node.js

If any of you have worked on TypeScript 1.x in the past, you might remember it being difficult and unwieldy. TypeScript version 2 brings many nice improvements. One of the biggest of them is how clean and simple has it become to install TypeScript compiler.

Installing TypeScript in Node.js

You can install TypeScript compiler either globally or locally and have it run by NPM run scripts.

$ npm install –g typescript

Then we set up the Node.js bindings to say this is a Node.js project.

$ npm install --save @type/node

Finally, we run the compiler, give it outDir flag and directory it’s going to and then the file that we’re going to compile.

$ tsc –outDir dist index.ts

Nevertheless, we can do a lot more complicated configuration.

Configuration with tsconfig.json

You can configure tsconfig.json file which works a lot like the babelconfig.json if you’ve ever used it before. It has all kinds of options: you can declare module system to output files as, point source map input files.

{
“compilerOptions”: {
“module”: “commonjs”,
“outDir” : “dist”,
“sourceMap”: true
},
“include”: [
“scr/**/*.ts”
]
}

Linter

Typescript also has a linter called tslint, which is similar to eslint. If you’ve used eslint before, then tslint is going to feel right at home. You can start installing tslint like you install eslint.

$ npm install –g tslint
$ tslint file1.ts file2.ts

ES6 Considerations

If you’re used to Babel, then keep in mind that TypeScript does not ship with a runtime. There’s no equivalent to Babel-runtime if you’ve used that. That is Typescript handles all of the ES6 and a lot of the ES7 syntax but the runtime operations. So things like Object.assign(), Symbol(), etc. are not polyfilled by TypeScript.

Node.js developers made the choice to TypeScript small. If you have to target older versions of Node.js or if you’re working in the browser, you might have to do something complicated. The recommended way is to go from TypeScript to ES6, which basically just strips out the types. You can even use babel to go the rest of the way and include the babel runtime.

TypeScript →ES6 →Babel →ES5

Code Editors

Out of the box both of the Visual Studio products support TypeScript: Visual Studio and VS Code. All the JetBrains IDes have support out of the box: Webstorm, PyCharm, IntelliJ IDEA.

In addition, all the other major code editors support TypeScript via a plugin: Sublime, Atom, Vim, Emacs, etc. Whatever editor you’re used to using, you can make TypeScript to work with that editor and can stick with your typical workflows.

TypeScript Definition files

When working on TypeScript, a great point of concern is to work on modules that are not written in TypeScript. To work with those, you can use TypeScript Definition Files. A definition file creates statically-typed interface for external dynamic code on this external module. Static code is by definition slightly more limited than dynamic code. These definition files are a declaration without an implementation, which is a lot like C++ header files if you’ve ever worked with C++. TypeScript definition files have a d.ts extension.

So we’re going to create this definition file for a module called planet. It’s going to have a couple of functions on it and an interface that is exported.

declare module “planet” {
export function visit(); void;
export function getCities(); city[];
export interface City {
population: number;
founded: Date;
}
}

If you notice, these have no implementation, just the signature. That’s enough for TypeScript to give you types, auto-completion and other great stuff which is awesome.

Global Type Definition Files

If you have to write definitions for all the modules especially when there is tree of modules-inside-modules, TypeScript have this concept of a global type definition file. These are the files that have been created by Microsoft and the TypeScript community, which gets contributions from everywhere. It’s basically definition files for all of the popular modules. Typing files are stored in npm under @types scope. Everything that’s reasonably popular in TypeScript tends to have a definition file. You can install it in Express with a single command.

$ npm install — save @types/express

Once you run this command, you have these definition files for Express, which brings code completion and many more things to the editor.

When and why to choose TypeScript over JavaScript

JavaScript’s lack of type checking makes it a bad contender for enterprise applications that require a fair degree of consistency which is typical to strictly typed languages like Java, C# and C++.

In little applications, anonymous objects with loosely typed fields don’t make a difference. However, when you’re working with thousands of lines of code, you can only work as long as the compiler and runtime system help find you errors. Only a programming language with strong typing can detect certain types of code errors.

“Indeed, TypeScript is JavaScript for application-scale development”