Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 19, 2022. It is now read-only.

A stream-based approach to algorithmic trading and backtesting in Node.js

License

NotificationsYou must be signed in to change notification settings

devalpha-io/devalpha-node

Build StatusDependenciesNPM VersionCoverage Status

DevAlpha is a Javascript framework for creating and running your own algorithmic trading systems. It is built using TypeScript, weighs in at a less than 1500 lines of code, and is speedy as hell.

The internal architecture primarily consists of one big stream and a bunch of consumers. It is implemented using the excellentHighland streams library, and also makes use of some helper functions fromRedux.

Features

  • Event sourced
  • Tiny footprint
  • Easily extensible
  • Simple API
  • Thoroughly tested
  • Typescript definitions

Interested in finance?

Talos is hiring senior engineers! Send an email tofilip+hiring attalos.com.

Installation

Install using NPM:

npm install devalpha

Quickstart

(Check outdevalpha-example for a starter repo.)

Getting started is easy as pie. Hook up any source of data you like and start trading in seconds.

import{createTrader}from'devalpha'constfeeds={myQuandlFeed:[1,2,3,4],myStreamFeed:fs.createReadStream(...)}conststrategy=(context,action)=>{// Place an orderif(action.type==='myQuandlFeed'){context.order({identifier:action.payload.identifier,quantity:100*action.payload.signalStrength,price:1000})}// Get current portfolio stateconststate=context.state()// Cancel an orderif(state.capital.cash<10000){context.cancel({id:123})}}// Create the trading streamconststream=createTrader({ feeds},strategy)// Consumer the stream and make money!stream.done(()=>{console.log('Finished!')})

Settings

constsettings={/* Toggle backtesting/realtime mode. In backtesting mode, events from the feed stream are pulled  as needed rather than pushed as created. This allows you to do a number of events for each feed  item, and then pull the next one only when you're finished with the current.  NOTE: DevAlpha will only activate realtime mode when this parameter is explicitly set to `false`.  This means that setting `backtesting: 0` will not do the job. */backtesting:true,/* Only used in realtime mode. The client manages order execution, and is provided to the  internal broker middleware. */client:null,/* Define the starting capital of your algorithm. Use only in backtesting mode. In realtime mode  you're better of using the `initialStates` setting instead. */startCapital:0,/* Provide initial states for your algorithm. One obvious use case would be when realtime  trading, and you want to fetch positions, capital, or order information from your broker. */initialStates:{},/* An object mapping event names to stream-like objects. See https://highlandjs.org/#_(source)  for a definition of "stream-like". Keys will be used as event type names. */feeds:{},/* Settings for your backtest. */backtest:{/* Denotes when your backtest is started (the first date of your backtesting data). */timestamp:0,/* A number or a function used when calculating expected commission. */commission:0},/* Settings for the guard middleware, which will prevent or alter orders (based on your  configuration). */guard:{/* Allow/disallow shorting. */shorting:false,/* Allow/disallow trading on margin. */margin:false,/* An array of restricted instrument identifiers. Example: ['GOOG', 'SPOT']. */restricted:[]},/* DevAlpha dashboard settings. */dashboard:{/* Toggle the DevAlpha dashboard. */active:false,/* Port used to pipe portfolio data. */port:4449}}

Usage

ThecreateTrader-function returns an unconsumed stream, and so it is up to you to consume it (thereby running the strategy). Highland provides a number of ways of doing this (see here), but the easiest one is probably just to use.resume() like so:

constsettings={...}conststrategy=(context,action)=>{...}createTrader(settings,strategy).resume()

However, you could also do crazy things like this:

import{createTrader,ORDER_FILLED,ORDER_FAILED}from'devalpha'constsettings={...}conststrategy=(context,action)=>{...}conststream=createTrader(settings,strategy)constslackStream=stream.fork()constredisStream=stream.fork()// Get Slack notifications on filled or failed ordersslackStream.each((event)=>{if(event.action.type===ORDER_FILLED){slackLogger.log('Hooray! An order was filled!')}elseif(event.action.type===ORDER_FAILED){slackLogger.log('Whoops! One of your orders was not executed!')}})// Place the current state in a Redis storeredisStream.each((event)=>{redisClient.set('state',JSON.stringify(event.state))})

Pretty neat, huh?

Resources

License

GNU GPL license. See the LICENSE.md file for details.

Responsibilities

The author of this software is not responsible for any indirect damages (foreseeable or unforeseeable), such as, if necessary, loss or alteration of or fraudulent access to data, accidental transmission of viruses or of any other harmful element, loss of profits or opportunities, the cost of replacement goods and services or the attitude and behavior of a third party.

About

A stream-based approach to algorithmic trading and backtesting in Node.js

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2026 Movatter.jp