├── .github
└── workflows
│ └── gradle.yml
├── .gitignore
├── .mvn
└── wrapper
│ ├── MavenWrapperDownloader.java
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── Dockerfile
├── HELP.md
├── Maxima_minima.jpg
├── MyChartFlag.jpg
├── MyTriangles.jpg
├── README-html.md
├── README.md
├── Trendlines.jpg
├── build.gradle
├── elliott
├── RELIANCE_OneHour.jpg
└── SBIN_OneHour.jpg
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── hs_err_pid257906.log
├── settings.gradle
├── src
├── main
│ ├── java
│ │ └── com
│ │ │ └── dtech
│ │ │ ├── algo
│ │ │ ├── backtest
│ │ │ │ ├── BackTestingHandlerJson.java
│ │ │ │ ├── BacktestInput.java
│ │ │ │ ├── BacktestResult.java
│ │ │ │ ├── OrderRecord.java
│ │ │ │ └── TradeRecord.java
│ │ │ ├── config
│ │ │ │ ├── AlgoTradeMapperConfig.java
│ │ │ │ └── CachingConfig.java
│ │ │ ├── controller
│ │ │ │ ├── BacktestController.java
│ │ │ │ └── MetadataController.java
│ │ │ ├── entities
│ │ │ │ └── StrategyEntity.java
│ │ │ ├── exception
│ │ │ │ └── StrategyException.java
│ │ │ ├── indicators
│ │ │ │ ├── IndicatorConstructor.java
│ │ │ │ ├── IndicatorInfo.java
│ │ │ │ └── IndicatorRegistry.java
│ │ │ ├── mapper
│ │ │ │ ├── GenericMapper.java
│ │ │ │ └── KiteTickToDataTickMapper.java
│ │ │ ├── registry
│ │ │ │ └── common
│ │ │ │ │ ├── BaseRegistry.java
│ │ │ │ │ └── ConstructorArgs.java
│ │ │ ├── rules
│ │ │ │ ├── RuleConstructor.java
│ │ │ │ ├── RuleInfo.java
│ │ │ │ └── RuleRegistry.java
│ │ │ ├── runner
│ │ │ │ └── candle
│ │ │ │ │ ├── DataTick.java
│ │ │ │ │ ├── LatestBarSeriesProvider.java
│ │ │ │ │ └── UpdatableBarSeriesLoader.java
│ │ │ ├── series
│ │ │ │ ├── Exchange.java
│ │ │ │ ├── ExtendedBarSeries.java
│ │ │ │ ├── InstrumentType.java
│ │ │ │ ├── Interval.java
│ │ │ │ ├── IntervalBarSeries.java
│ │ │ │ └── SeriesType.java
│ │ │ ├── service
│ │ │ │ └── StrategyService.java
│ │ │ └── strategy
│ │ │ │ ├── TradeStrategy.java
│ │ │ │ ├── TradeStrategyImpl.java
│ │ │ │ ├── builder
│ │ │ │ ├── FinalStrategyBuilder.java
│ │ │ │ ├── StrategyBuilderIfc.java
│ │ │ │ ├── cache
│ │ │ │ │ ├── BarSeriesCache.java
│ │ │ │ │ ├── ConstantsCache.java
│ │ │ │ │ ├── IndicatorCache.java
│ │ │ │ │ ├── RuleCache.java
│ │ │ │ │ ├── ThreadLocalCache.java
│ │ │ │ │ └── TradingRecordCache.java
│ │ │ │ └── ifc
│ │ │ │ │ ├── BarSeriesLoader.java
│ │ │ │ │ ├── ConstantsLoader.java
│ │ │ │ │ ├── IndicatorBuilder.java
│ │ │ │ │ └── RuleBuilder.java
│ │ │ │ ├── config
│ │ │ │ ├── BarSeriesConfig.java
│ │ │ │ ├── FollowUpRuleConfig.java
│ │ │ │ ├── FollowUpRuleType.java
│ │ │ │ ├── IndicatorConfig.java
│ │ │ │ ├── IndicatorInput.java
│ │ │ │ ├── IndicatorInputType.java
│ │ │ │ ├── RuleConfig.java
│ │ │ │ ├── RuleInput.java
│ │ │ │ ├── RuleInputType.java
│ │ │ │ ├── RunnerConfig.java
│ │ │ │ └── StrategyConfig.java
│ │ │ │ ├── sync
│ │ │ │ ├── CandleSyncExecutor.java
│ │ │ │ ├── CandleSyncJob.java
│ │ │ │ └── CandleSyncToken.java
│ │ │ │ └── units
│ │ │ │ ├── AbstractObjectBuilder.java
│ │ │ │ ├── CachedIndicatorBuilder.java
│ │ │ │ ├── CachedRuleBuilder.java
│ │ │ │ └── RdbmsBarSeriesLoader.java
│ │ │ ├── kitecon
│ │ │ ├── KiteconApplication.java
│ │ │ ├── config
│ │ │ │ ├── HistoricalDateLimit.java
│ │ │ │ └── KiteConnectConfig.java
│ │ │ ├── controller
│ │ │ │ ├── BarSeriesHelper.java
│ │ │ │ ├── ConfigController.java
│ │ │ │ ├── DataFetchController.java
│ │ │ │ ├── ElliottVisualizerController.java
│ │ │ │ ├── ExecutionController.java
│ │ │ │ ├── ImageController.java
│ │ │ │ ├── OrderController.java
│ │ │ │ ├── StrategyController.java
│ │ │ │ └── TrendlineController.java
│ │ │ ├── data
│ │ │ │ ├── Candle.java
│ │ │ │ ├── IndexSymbol.java
│ │ │ │ ├── Instrument.java
│ │ │ │ ├── LocalDateTimeAttributeConverter.java
│ │ │ │ ├── StrategyParameters.java
│ │ │ │ └── TrendLine.java
│ │ │ ├── historical
│ │ │ │ └── limits
│ │ │ │ │ └── LimitsKey.java
│ │ │ ├── loader
│ │ │ │ └── DataLoader.java
│ │ │ ├── market
│ │ │ │ ├── Provider.java
│ │ │ │ ├── fetch
│ │ │ │ │ ├── DataFetchException.java
│ │ │ │ │ ├── MarketDataFetch.java
│ │ │ │ │ ├── MarketDataFetchFactory.java
│ │ │ │ │ ├── MarketDataFetchImpl.java
│ │ │ │ │ └── ZerodhaDataFetch.java
│ │ │ │ └── orders
│ │ │ │ │ ├── OrderException.java
│ │ │ │ │ ├── OrderManager.java
│ │ │ │ │ └── ZerodhaOrderManager.java
│ │ │ ├── misc
│ │ │ │ └── StrategyEnvironment.java
│ │ │ ├── repository
│ │ │ │ ├── CandleRepository.java
│ │ │ │ ├── CandleRepositoryOld.java
│ │ │ │ ├── IndexSymbolRepository.java
│ │ │ │ ├── InstrumentRepository.java
│ │ │ │ └── StrategyParametersRepository.java
│ │ │ ├── service
│ │ │ │ ├── CandleFacade.java
│ │ │ │ ├── DataDownloadRequest.java
│ │ │ │ ├── DataDownloader.java
│ │ │ │ ├── DataFetchService.java
│ │ │ │ ├── DateRange.java
│ │ │ │ ├── ExecutionService.java
│ │ │ │ ├── IndexSymbolUpdaterService.java
│ │ │ │ ├── StrategyService.java
│ │ │ │ └── TradeInfo.java
│ │ │ └── strategy
│ │ │ │ ├── TradeDirection.java
│ │ │ │ ├── TradingStrategy.java
│ │ │ │ ├── backtest
│ │ │ │ ├── BackTestingHandler.java
│ │ │ │ ├── BacktestResult.java
│ │ │ │ ├── BacktestSummary.java
│ │ │ │ ├── OrderRecord.java
│ │ │ │ └── TradeRecord.java
│ │ │ │ ├── builder
│ │ │ │ ├── BaseStrategyBuilder.java
│ │ │ │ ├── MACDDiversionStrategy.java
│ │ │ │ ├── OpeningRangeBreakoutStrategyBuiderModified.java
│ │ │ │ ├── OpeningRangeBreakoutStrategyBuilder.java
│ │ │ │ ├── PivotPointReversalStrategyBuider.java
│ │ │ │ ├── SimpleMovingAverageStrategyBuider.java
│ │ │ │ ├── StrategyBuilder.java
│ │ │ │ └── StrategyConfig.java
│ │ │ │ ├── dataloader
│ │ │ │ ├── BarsLoader.java
│ │ │ │ └── InstrumentDataLoader.java
│ │ │ │ ├── exec
│ │ │ │ ├── AlgoTradingRecord.java
│ │ │ │ ├── HybridDataLoader.java
│ │ │ │ ├── ProductionHandler.java
│ │ │ │ ├── ProductionSeriesManager.java
│ │ │ │ ├── ProductionStrategyRunner.java
│ │ │ │ └── ProductionTradingRecord.java
│ │ │ │ └── sets
│ │ │ │ └── StrategySet.java
│ │ │ ├── swagger
│ │ │ ├── SwaggerDocumentationConfig.java
│ │ │ └── SwaggerUiConfiguration.java
│ │ │ ├── ta
│ │ │ ├── BarTuple.java
│ │ │ ├── OHLC.java
│ │ │ ├── OHLCAnalyzer.java
│ │ │ ├── TrendAnalysis.java
│ │ │ ├── TrendLineCalculated.java
│ │ │ ├── TrendLineCanculator.java
│ │ │ ├── TrendLineUpside.java
│ │ │ ├── TrendlineReliability.java
│ │ │ ├── divergences
│ │ │ │ ├── Divergence.java
│ │ │ │ ├── DivergenceAnalyzer.java
│ │ │ │ ├── DivergenceDetector.java
│ │ │ │ ├── DivergenceDirection.java
│ │ │ │ ├── DivergenceType.java
│ │ │ │ ├── IndicatorType.java
│ │ │ │ ├── MACDDivergenceDetector.java
│ │ │ │ ├── RSIDivergenceDetector.java
│ │ │ │ └── StochasticDivergenceDetector.java
│ │ │ ├── elliott
│ │ │ │ ├── AdvancedElliottWaveAnalyzer.java
│ │ │ │ ├── ElliottWaveAnalyzer.java
│ │ │ │ ├── RefinedLocalExtremesDetector.java
│ │ │ │ ├── Wave.java
│ │ │ │ ├── pattern
│ │ │ │ │ ├── EndingDiagonalDetector.java
│ │ │ │ │ ├── ExpandedFlatPatternDetector.java
│ │ │ │ │ ├── FlatPatternDetector.java
│ │ │ │ │ ├── LeadingDiagonalDetector.java
│ │ │ │ │ ├── PatternDetectorBase.java
│ │ │ │ │ └── TrianglePatternDetector.java
│ │ │ │ ├── priceaction
│ │ │ │ │ ├── PriceAction.java
│ │ │ │ │ └── PriceActionAnalyzer.java
│ │ │ │ └── wave
│ │ │ │ │ ├── Wave1Detector.java
│ │ │ │ │ ├── Wave2Detector.java
│ │ │ │ │ ├── Wave3Detector.java
│ │ │ │ │ ├── Wave4Detector.java
│ │ │ │ │ ├── Wave5Detector.java
│ │ │ │ │ └── WaveDetectorBase.java
│ │ │ ├── patterns
│ │ │ │ ├── DoubleBottomDetector.java
│ │ │ │ ├── DoubleBottomPattern.java
│ │ │ │ ├── FlagPattern.java
│ │ │ │ ├── FlagPatternDetector.java
│ │ │ │ ├── IndicatorCalculator.java
│ │ │ │ ├── TriangleDetector.java
│ │ │ │ └── TrianglePattern.java
│ │ │ ├── trendline
│ │ │ │ ├── ActiveTrendlineAnalysis.java
│ │ │ │ ├── TrendLineAnalysis.java
│ │ │ │ ├── TrendLineDetection.java
│ │ │ │ ├── TrendlineAnalyser.java
│ │ │ │ ├── TrendlineTAConfirmation.java
│ │ │ │ ├── TrendlineType.java
│ │ │ │ └── Util.java
│ │ │ └── visualize
│ │ │ │ ├── MACDVisualizer.java
│ │ │ │ ├── RSIVisualizer.java
│ │ │ │ ├── StochasticVisualizer.java
│ │ │ │ ├── TrendlineVisualizer.java
│ │ │ │ └── VisualizerHelper.java
│ │ │ └── trade
│ │ │ ├── ActiveOrderManager.java
│ │ │ ├── instrument
│ │ │ └── InstrumentBarSeriesManager.java
│ │ │ ├── model
│ │ │ ├── Order.java
│ │ │ └── OrderStatus.java
│ │ │ ├── order
│ │ │ ├── OrderManager.java
│ │ │ └── RealTradeOrder.java
│ │ │ ├── repository
│ │ │ └── OrderRepository.java
│ │ │ └── zerodha
│ │ │ ├── KiteOrderManager.java
│ │ │ └── ZerodhaOrder.java
│ └── resources
│ │ ├── application.properties
│ │ └── static
│ │ ├── index.html
│ │ └── js
│ │ └── image-browser.js
└── test
│ ├── java
│ └── com
│ │ └── dtech
│ │ ├── algo
│ │ ├── backtest
│ │ │ └── BackTestingHandlerJsonTest.java
│ │ ├── controller
│ │ │ ├── BacktestControllerTest.java
│ │ │ └── MetadataControllerTest.java
│ │ ├── indicators
│ │ │ └── IndicatorRegistryTest.java
│ │ ├── rules
│ │ │ └── RuleRegistryTest.java
│ │ ├── runner
│ │ │ └── candle
│ │ │ │ ├── LatestBarSeriesProviderFromCacheTest.java
│ │ │ │ └── LatestBarSeriesProviderTest.java
│ │ ├── series
│ │ │ └── ExtendedBarSeriesTest.java
│ │ └── strategy
│ │ │ ├── TestHelper.java
│ │ │ ├── builder
│ │ │ └── FinalStrategyBuilderTest.java
│ │ │ ├── cache
│ │ │ └── ThreadLocalCacheTest.java
│ │ │ ├── config
│ │ │ └── BarSeriesConfigTest.java
│ │ │ ├── helper
│ │ │ └── ComponentHelper.java
│ │ │ ├── sync
│ │ │ ├── CandleSyncExecutorTest.java
│ │ │ └── CandleSyncJobTest.java
│ │ │ └── units
│ │ │ ├── CachedIndicatorBuilderTest.java
│ │ │ ├── CachedRuleBuilderTest.java
│ │ │ └── RdbmsBarSeriesLoaderTest.java
│ │ ├── chart
│ │ ├── ChartCreator.java
│ │ ├── FlagVisualizer.java
│ │ └── TriangleVisualizer.java
│ │ ├── kitecon
│ │ └── service
│ │ │ ├── DateRangeTest.java
│ │ │ └── PnLCalculator.java
│ │ ├── ta
│ │ ├── OHLCAnalyzerTest.java
│ │ ├── patterns
│ │ │ ├── DoubleBottomDetectorTest.java
│ │ │ ├── FlagPatternDetectorTest.java
│ │ │ ├── PatternTestHelper.java
│ │ │ └── TriangleVisualizationTest.java
│ │ └── trendline
│ │ │ └── TrendLineDetectionTest.java
│ │ └── trade
│ │ ├── ActiveOrderManagerTest.java
│ │ ├── instrument
│ │ └── InstrumentBarSeriesManagerTest.java
│ │ └── zerodha
│ │ └── KiteOrderManagerTest.java
│ └── resources
│ ├── application.properties
│ ├── bitstamp_trades_from_20131125_usd.csv
│ ├── com
│ └── dtech
│ │ └── ta
│ │ └── processed_ohlc_data.csv
│ └── mockito-extensions
│ └── org.mockito.plugins.MockMaker
├── start.sh
├── test_data
├── NSE_ROSSARI_1D.csv
├── processed_ohlc_data.csv
└── rossari_60.csv
└── tlbo
├── ASHOKLEY_Day.jpg
├── CUMMINSIND_Day.jpg
├── DIVISLAB_Day.jpg
├── DMART_Day.jpg
├── EMAMILTD_Day.jpg
├── GODREJCP_Day.jpg
├── GUJGASLTD_Day.jpg
├── IEX_Day.jpg
├── JINDALSTEL_Day.jpg
├── KAJARIACER_Day.jpg
├── MARICO_Day.jpg
├── SUPREMEIND_Day.jpg
└── VGUARD_Day.jpg
/.github/workflows/gradle.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Gradle
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
3 |
4 | name: Java CI with Gradle
5 |
6 | on:
7 | push:
8 | branches: [ master ]
9 | pull_request:
10 | branches: [ master ]
11 |
12 | jobs:
13 | build:
14 |
15 | runs-on: ubuntu-latest
16 |
17 | steps:
18 | - uses: actions/checkout@v2
19 | - name: Set up JDK 1.8
20 | uses: actions/setup-java@v1
21 | with:
22 | java-version: 11
23 | - name: Grant execute permission for gradlew
24 | run: chmod +x gradlew
25 | - name: Build with Gradle
26 | run: ./gradlew build
27 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**
5 | !**/src/test/**
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 |
30 | ### VS Code ###
31 | .vscode/
32 | .gradle/
33 | *.class
34 | out/
35 | /tlbo/
36 | /elliott/
37 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ProScriptSlinger/Zerodha-Algo-Trading/0efe9b3ca2d524a66cf0d07ce789618933b510bf/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip
2 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM gradle:jdk11
2 |
3 | ARG DEBIAN_FRONTEND=noninteractive
4 | RUN apt-get update && apt-get -y upgrade
5 | RUN apt-get -y install git wget
6 |
7 | USER root
8 |
9 | RUN mkdir code
10 | COPY . /code
11 | #RUN mkdir -p /root/.gradle/wrapper/dists/gradle-6.6.1-bin
12 | #ADD ./gradle-6.6.1-bin /root/.gradle/wrapper/dists/gradle-6.6.1-bin
13 | RUN cd /code && ./gradlew bootjar
14 |
15 | CMD /code/start.sh
--------------------------------------------------------------------------------
/HELP.md:
--------------------------------------------------------------------------------
1 | # Getting Started
2 |
3 | ### Reference Documentation
4 | For further reference, please consider the following sections:
5 |
6 | * [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
7 | * [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/maven-plugin/)
8 | * [Spring Configuration Processor](https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/htmlsingle/#configuration-metadata-annotation-processor)
9 | * [Spring Web](https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/htmlsingle/#boot-features-developing-web-applications)
10 | * [Spring Boot DevTools](https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/htmlsingle/#using-boot-devtools)
11 |
12 | ### Guides
13 | The following guides illustrate how to use some features concretely:
14 |
15 | * [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
16 | * [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
17 | * [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/)
18 | * [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/)
19 |
20 |
--------------------------------------------------------------------------------
/Maxima_minima.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ProScriptSlinger/Zerodha-Algo-Trading/0efe9b3ca2d524a66cf0d07ce789618933b510bf/Maxima_minima.jpg
--------------------------------------------------------------------------------
/MyChartFlag.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ProScriptSlinger/Zerodha-Algo-Trading/0efe9b3ca2d524a66cf0d07ce789618933b510bf/MyChartFlag.jpg
--------------------------------------------------------------------------------
/MyTriangles.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ProScriptSlinger/Zerodha-Algo-Trading/0efe9b3ca2d524a66cf0d07ce789618933b510bf/MyTriangles.jpg
--------------------------------------------------------------------------------
/README-html.md:
--------------------------------------------------------------------------------
1 | # zerodha-algo-trading
2 | A codebase to connect zerodha connect along with algo trading library to use power of algo trading with zerodha
3 |
4 |
5 | Any new code additions should go to package com.dtech.algo. This package is supposed to have 100% code coverage production ready.
6 |
7 |
8 | We started with simple MVP for fetching data from Zerodha and putting trades. When it was successful, we went ahead with
9 | building a fully working algo trading app.
10 |
11 | ### What do we want to build?
12 |
13 | We want to build a solution where users can build a strategies that can
14 | together work on different segments and make a comparison analysis in Equity, Derivatives before
15 | Putting trade. E.g. I want to buy SBIN Fut, but the best criteria to make that call is
16 | analysing open interest in the nearest In the money Put. We want to build that level of mechanism, which no one provides as of now.
17 |
18 | ### What do we have as of now?
19 |
20 | After first MVP, now we have built a server side architecture to make fully configurable strategies using
21 | different bar-series for technical analysis and different bar-series for trades. So now you can make a trade in
22 | SBIN Fut Or SBI Cash by analysing Open interest in SBIN call and puts, or PE ratio,
23 |
24 | ### What is pending?
25 |
26 | We have a huge backlog, because we want to build a market ready product. Some of them are
27 | 1. Build a usable web/mobile app that can be used by our users to build strategy
28 | 2. Integrate with zerodha websockets for now for putting trades in realtime.
29 | 3. Take the library to next level with integrating with different brokers.
30 | These are few things from the top of my mind, and the list is ever-growing!!
31 |
32 | ### Do we follow any development practices?
33 | Yes, we follow TDD, or at least we expect reasonable coverage on the code that we write
34 | We have CI setup with github actions, and the code health is tracked on it.
35 |
36 |
37 | I am looking for React/ Flutter developers to build a frontend app for this project
38 |
39 |
40 | > We welcome all sort of contributions, including your time and money!!
41 |
42 |
43 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # zerodha-algo-trading
2 | A codebase to connect zerodha connect along with algo trading library to use power of algo trading with zerodha
3 |
4 | **IMP: Any new code additions should go to package `com.dtech.algo`. This package is supposed to have 100% code coverage production ready.**
5 |
6 | **I am looking for React/ Flutter developers to build a frontend app for this project**
7 |
8 | We started with simple MVP for fetching data from Zerodha and putting trades. When it was successful, we went ahead with
9 | building a fully working algo trading app.
10 |
11 | ### What do we want to build?
12 |
13 | We want to build a solution where users can build a strategies that can
14 | together work on different segments and make a comparison analysis in Equity, Derivatives before
15 | Putting trade. E.g. I want to buy SBIN Fut, but the best criteria to make that call is
16 | analysing open interest in the nearest In the money Put. We want to build that level of mechanism, which no one provides as of now.
17 |
18 | ### What do we have as of now?
19 |
20 | After first MVP, now we have built a server side architecture to make fully configurable strategies using
21 | different bar-series for technical analysis and different bar-series for trades. So now you can make a trade in
22 | SBIN Fut Or SBI Cash by analysing Open interest in SBIN call and puts, or PE ratio,
23 |
24 | ### What is pending?
25 |
26 | We have a huge backlog, because we want to build a market ready product. Some of them are
27 | 1. Build a usable web/mobile app that can be used by our users to build strategy
28 | 2. Integrate with zerodha websockets for now for putting trades in realtime.
29 | 3. Take the library to next level with integrating with different brokers.
30 | These are few things from the top of my mind, and the list is ever-growing!!
31 |
32 | ### Do we follow any development practices?
33 | Yes, we follow TDD, or at least we expect reasonable coverage on the code that we write
34 | We have CI setup with github actions, and the code health is tracked on it.
35 |
36 | > We welcome all sort of contributions, including your time and money!!
37 |
38 |
--------------------------------------------------------------------------------
/Trendlines.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ProScriptSlinger/Zerodha-Algo-Trading/0efe9b3ca2d524a66cf0d07ce789618933b510bf/Trendlines.jpg
--------------------------------------------------------------------------------
/elliott/RELIANCE_OneHour.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ProScriptSlinger/Zerodha-Algo-Trading/0efe9b3ca2d524a66cf0d07ce789618933b510bf/elliott/RELIANCE_OneHour.jpg
--------------------------------------------------------------------------------
/elliott/SBIN_OneHour.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ProScriptSlinger/Zerodha-Algo-Trading/0efe9b3ca2d524a66cf0d07ce789618933b510bf/elliott/SBIN_OneHour.jpg
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ProScriptSlinger/Zerodha-Algo-Trading/0efe9b3ca2d524a66cf0d07ce789618933b510bf/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * This file was generated by the Gradle 'init' task.
3 | */
4 | pluginManagement {
5 | repositories {
6 | mavenLocal()
7 | maven { url 'https://repo.spring.io/milestone' }
8 | maven { url 'https://repo.spring.io/snapshot' }
9 | gradlePluginPortal()
10 | maven { url 'https://jitpack.io' }
11 | }
12 | // resolutionStrategy {
13 | // eachPlugin {
14 | // if (requested.id.id == 'org.springframework.boot') {
15 | // useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}")
16 | // }
17 | // }
18 | // }
19 | }
20 | rootProject.name = 'kitecon'
21 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/backtest/BacktestInput.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.backtest;
2 |
3 | import com.dtech.algo.strategy.config.BarSeriesConfig;
4 | import com.dtech.algo.strategy.config.StrategyConfig;
5 | import lombok.*;
6 |
7 | import java.util.List;
8 |
9 | @Data
10 | @Builder
11 | @NoArgsConstructor
12 | @AllArgsConstructor
13 | public class BacktestInput {
14 |
15 | private List barSeriesConfigs;
16 | private String barSeriesName;
17 | private StrategyConfig strategyConfig;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/backtest/BacktestResult.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.backtest;
2 |
3 | import lombok.Builder;
4 | import lombok.Value;
5 | import org.ta4j.core.Position;
6 |
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | @Value
11 | @Builder
12 | public class BacktestResult {
13 |
14 | Map aggregatesResults;
15 | List tradingRecord;
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/backtest/OrderRecord.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.backtest;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import org.ta4j.core.Trade.TradeType;
7 | import org.ta4j.core.Trade;
8 |
9 | import java.time.ZonedDateTime;
10 |
11 | @Data
12 | @AllArgsConstructor
13 | @Builder
14 | public class OrderRecord {
15 |
16 | /**
17 | * Type of the order
18 | */
19 | private TradeType type;
20 |
21 | /**
22 | * The index the order was executed
23 | */
24 | private int index;
25 |
26 | /**
27 | * The pricePerAsset for the order
28 | */
29 | private Double pricePerAsset;
30 |
31 | /**
32 | * The net price for the order, net transaction costs
33 | */
34 | private Double netPrice;
35 |
36 | /**
37 | * The amount to be (or that was) ordered
38 | */
39 | private Double amount;
40 |
41 | /**
42 | * Cost of executing the order
43 | */
44 | private Double cost;
45 |
46 | private ZonedDateTime dateTime;
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/backtest/TradeRecord.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.backtest;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 |
7 | @Builder
8 | @AllArgsConstructor
9 | @Data
10 | public class TradeRecord {
11 |
12 | /**
13 | * The type of the entry order
14 | */
15 | private Double profit;
16 |
17 | /**
18 | * The entry order
19 | */
20 | private OrderRecord entry;
21 |
22 | /**
23 | * The exit order
24 | */
25 | private OrderRecord exit;
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/config/AlgoTradeMapperConfig.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.config;
2 |
3 | import org.mapstruct.MapperConfig;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @MapperConfig(componentModel = "spring")
7 | @Configuration
8 | public class AlgoTradeMapperConfig {
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/config/CachingConfig.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.config;
2 |
3 | import org.springframework.cache.CacheManager;
4 | import org.springframework.cache.annotation.EnableCaching;
5 | import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 |
9 | @Configuration
10 | @EnableCaching
11 | public class CachingConfig {
12 |
13 | @Bean
14 | public CacheManager cacheManager() {
15 | return new ConcurrentMapCacheManager("barSeries");
16 | }
17 | }
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/controller/BacktestController.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.controller;
2 |
3 | import com.dtech.algo.backtest.BackTestingHandlerJson;
4 | import com.dtech.algo.backtest.BacktestInput;
5 | import com.dtech.algo.backtest.BacktestResult;
6 | import com.dtech.algo.exception.StrategyException;
7 | import lombok.RequiredArgsConstructor;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.web.bind.annotation.PostMapping;
10 | import org.springframework.web.bind.annotation.RequestBody;
11 | import org.springframework.web.bind.annotation.RestController;
12 |
13 | @RestController
14 | @RequiredArgsConstructor(onConstructor = @__(@Autowired))
15 | public class BacktestController {
16 |
17 | private final BackTestingHandlerJson backTestingHandlerJson;
18 |
19 | @PostMapping("/backtest")
20 | public BacktestResult runBacktest(@RequestBody BacktestInput backtestInput) throws StrategyException {
21 | return backTestingHandlerJson.execute(backtestInput);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/controller/MetadataController.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.controller;
2 |
3 | import com.dtech.algo.backtest.BackTestingHandlerJson;
4 | import com.dtech.algo.backtest.BacktestInput;
5 | import com.dtech.algo.backtest.BacktestResult;
6 | import com.dtech.algo.exception.StrategyException;
7 | import com.dtech.algo.indicators.IndicatorInfo;
8 | import com.dtech.algo.indicators.IndicatorRegistry;
9 | import com.dtech.algo.rules.RuleInfo;
10 | import com.dtech.algo.rules.RuleRegistry;
11 | import com.dtech.algo.strategy.config.IndicatorConfig;
12 | import lombok.RequiredArgsConstructor;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.web.bind.annotation.GetMapping;
15 | import org.springframework.web.bind.annotation.PostMapping;
16 | import org.springframework.web.bind.annotation.RequestBody;
17 | import org.springframework.web.bind.annotation.RestController;
18 |
19 | import java.util.Map;
20 | import java.util.stream.Collectors;
21 |
22 | @RestController
23 | @RequiredArgsConstructor(onConstructor = @__(@Autowired))
24 | public class MetadataController {
25 |
26 | private final IndicatorRegistry indicatorRegistry;
27 | private final RuleRegistry ruleRegistry;
28 |
29 | @GetMapping("/meta/indicator-detail")
30 | public Map getIndicatorDetails() throws StrategyException {
31 | return indicatorRegistry.getAllObjectNames().stream()
32 | .collect(Collectors.toMap(name -> name, name -> indicatorRegistry.getObjectInfo(name)));
33 | }
34 |
35 | @GetMapping("/meta/rule-detail")
36 | public Map getRuleDetails() throws StrategyException {
37 | return ruleRegistry.getAllObjectNames().stream()
38 | .collect(Collectors.toMap(name -> name, name -> ruleRegistry.getObjectInfo(name)));
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/entities/StrategyEntity.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.entities;
2 |
3 | import com.dtech.kitecon.data.Instrument;
4 |
5 | import jakarta.persistence.*;
6 |
7 | @Entity(name = "strategy")
8 | public class StrategyEntity {
9 | @Id
10 | @GeneratedValue(strategy = GenerationType.AUTO)
11 | private Integer id;
12 |
13 | @Column
14 | private String criteria;
15 |
16 | @Column
17 | private String barSeriesConfig;
18 |
19 | @Column(name = "order_id")
20 | private String order;
21 |
22 | @JoinColumn
23 | private String barSeriesName;
24 |
25 | @Column
26 | private Boolean enabled;
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/exception/StrategyException.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.exception;
2 |
3 | public class StrategyException extends Exception {
4 |
5 | public StrategyException() {
6 | super();
7 | }
8 |
9 | public StrategyException(String message) {
10 | super(message);
11 | }
12 |
13 | public StrategyException(String message, Throwable cause) {
14 | super(message, cause);
15 | }
16 |
17 | public StrategyException(Throwable cause) {
18 | super(cause);
19 | }
20 |
21 | protected StrategyException(String message, Throwable cause, boolean enableSuppression,
22 | boolean writableStackTrace) {
23 | super(message, cause, enableSuppression, writableStackTrace);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/indicators/IndicatorConstructor.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.indicators;
2 |
3 | import com.dtech.algo.registry.common.ConstructorArgs;
4 | import java.util.List;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Builder;
7 | import lombok.Data;
8 | import lombok.EqualsAndHashCode;
9 | import lombok.NoArgsConstructor;
10 | import lombok.ToString;
11 |
12 | @Builder
13 | @AllArgsConstructor
14 | @NoArgsConstructor
15 | @EqualsAndHashCode
16 | @Data
17 | @ToString
18 | public class IndicatorConstructor {
19 |
20 | private List args;
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/indicators/IndicatorInfo.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.indicators;
2 |
3 | import java.util.List;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Builder;
6 | import lombok.Data;
7 | import lombok.ToString;
8 |
9 | @Data
10 | @AllArgsConstructor
11 | @Builder
12 | @ToString
13 | public class IndicatorInfo {
14 | private String name;
15 | private List constructors;
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/indicators/IndicatorRegistry.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.indicators;
2 |
3 | import com.dtech.algo.registry.common.BaseRegistry;
4 | import java.lang.reflect.Constructor;
5 | import java.util.Arrays;
6 | import java.util.List;
7 | import java.util.Set;
8 | import java.util.stream.Collectors;
9 |
10 | import org.reflections.Reflections;
11 | import org.reflections.scanners.SubTypesScanner;
12 | import org.springframework.stereotype.Service;
13 | import org.ta4j.core.Indicator;
14 | import org.ta4j.core.indicators.AbstractIndicator;
15 | import org.ta4j.core.indicators.RSIIndicator;
16 | import org.ta4j.core.indicators.SMAIndicator;
17 | import org.ta4j.core.indicators.candles.DojiIndicator;
18 | import org.ta4j.core.indicators.helpers.ClosePriceIndicator;
19 | import org.ta4j.core.indicators.helpers.ConstantIndicator;
20 | import org.ta4j.core.indicators.range.OpeningRangeLow;
21 |
22 | import jakarta.annotation.PostConstruct;
23 |
24 |
25 | @Service
26 | public class IndicatorRegistry extends BaseRegistry {
27 |
28 | public static Set> getClassesFromPackage(String packageName) {
29 | Reflections reflections = new Reflections(packageName, new SubTypesScanner(false));
30 | return reflections.getSubTypesOf(AbstractIndicator.class);
31 | }
32 |
33 | @PostConstruct
34 | public void initialize() {
35 | Set> indicators = getClassesFromPackage("org.ta4j.core.indicators");
36 | indicators.stream().forEach(this::add);
37 | }
38 |
39 | public Class extends Indicator> getIndicatorClass(String name) {
40 | return registryMap.get(name);
41 | }
42 |
43 | public IndicatorInfo getObjectInfo(String name) {
44 | Class aClass = getIndicatorClass(name);
45 | String className = camelToLower(aClass.getSimpleName());
46 | Constructor[] constructors = aClass.getConstructors();
47 | List indicatorConstructors = Arrays.stream(constructors)
48 | .map(constructor -> IndicatorConstructor.builder()
49 | .args(mapConstructorArgs(constructor))
50 | .build())
51 | .collect(Collectors.toList());
52 | return IndicatorInfo.builder()
53 | .constructors(indicatorConstructors)
54 | .name(className)
55 | .build();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/mapper/GenericMapper.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.mapper;
2 |
3 | public interface GenericMapper{
4 | S reverse(T source);
5 | T map(S destination);
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/mapper/KiteTickToDataTickMapper.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.mapper;
2 |
3 | import com.dtech.algo.runner.candle.DataTick;
4 | import com.zerodhatech.models.Tick;
5 | import org.mapstruct.Mapper;
6 |
7 | @Mapper
8 | public interface KiteTickToDataTickMapper extends GenericMapper {
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/registry/common/BaseRegistry.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.registry.common;
2 |
3 | import com.dtech.algo.indicators.IndicatorInfo;
4 | import com.google.common.base.CaseFormat;
5 |
6 | import java.lang.reflect.Constructor;
7 | import java.lang.reflect.Parameter;
8 | import java.util.*;
9 | import java.util.stream.Collectors;
10 |
11 | import org.jetbrains.annotations.Nullable;
12 | import org.ta4j.core.num.DoubleNum;
13 | import org.ta4j.core.num.Num;
14 |
15 | public abstract class BaseRegistry {
16 |
17 | protected final Map> registryMap = new HashMap<>();
18 |
19 | public abstract I getObjectInfo(String name);
20 |
21 | @Nullable
22 | protected static String camelToLower(String simpleName) {
23 | return CaseFormat.UPPER_CAMEL.converterTo(CaseFormat.LOWER_HYPHEN)
24 | .convert(simpleName);
25 | }
26 |
27 | protected String getTypeName(Parameter parameter) {
28 | Class> type = parameter.getType();
29 | if (type.isPrimitive()) {
30 | return type.getName();
31 | } else if (type.isAssignableFrom(DoubleNum.class)) {
32 | return BaseRegistry.camelToLower(Num.class.getSimpleName());
33 | }
34 | {
35 | return BaseRegistry.camelToLower(type.getSimpleName());
36 | }
37 | }
38 |
39 | protected List getValues(Parameter parameter) {
40 | Class> type = parameter.getType();
41 | if (type.isEnum()) {
42 | Enum[] enumConstants = (Enum[]) type.getEnumConstants();
43 | return Arrays.stream(enumConstants).map(Enum::name)
44 | .collect(Collectors.toList());
45 | }
46 | return Collections.emptyList();
47 | }
48 |
49 | protected List mapConstructorArgs(Constructor constructor) {
50 | return Arrays.stream(constructor.getParameters())
51 | .map(parameter -> ConstructorArgs.builder()
52 | .type(getTypeName(parameter))
53 | .name(parameter.getName())
54 | .values(getValues(parameter))
55 | .build())
56 | .collect(Collectors.toList());
57 | }
58 |
59 | protected void add(Class extends T> aClass) {
60 | String simpleName = aClass.getSimpleName();
61 | String key = camelToLower(simpleName);
62 | registryMap.put(key, aClass);
63 | }
64 |
65 | public Collection getAllObjectNames() {
66 | return registryMap.keySet();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/registry/common/ConstructorArgs.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.registry.common;
2 |
3 | import java.util.List;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Builder;
6 | import lombok.EqualsAndHashCode;
7 | import lombok.Getter;
8 | import lombok.Setter;
9 | import lombok.ToString;
10 |
11 | @AllArgsConstructor
12 | @Getter
13 | @Setter
14 | @EqualsAndHashCode(exclude = "name")
15 | @Builder
16 | @ToString
17 | public class ConstructorArgs {
18 | private String type;
19 | private String name;
20 | private List values;
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/rules/RuleConstructor.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.rules;
2 |
3 | import com.dtech.algo.registry.common.ConstructorArgs;
4 | import java.util.List;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Builder;
7 | import lombok.Data;
8 | import lombok.EqualsAndHashCode;
9 | import lombok.NoArgsConstructor;
10 | import lombok.ToString;
11 |
12 | @Builder
13 | @AllArgsConstructor
14 | @NoArgsConstructor
15 | @EqualsAndHashCode
16 | @Data
17 | @ToString
18 | public class RuleConstructor {
19 |
20 | private List args;
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/rules/RuleInfo.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.rules;
2 |
3 | import com.dtech.algo.indicators.IndicatorConstructor;
4 | import java.util.List;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Builder;
7 | import lombok.Data;
8 | import lombok.ToString;
9 |
10 | @Data
11 | @AllArgsConstructor
12 | @Builder
13 | @ToString
14 | public class RuleInfo {
15 | private String name;
16 | private List constructors;
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/rules/RuleRegistry.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.rules;
2 |
3 | import com.dtech.algo.registry.common.BaseRegistry;
4 | import org.reflections.Reflections;
5 | import org.reflections.scanners.SubTypesScanner;
6 | import org.springframework.stereotype.Service;
7 | import org.ta4j.core.Rule;
8 | import org.ta4j.core.indicators.AbstractIndicator;
9 | import org.ta4j.core.rules.*;
10 |
11 | import jakarta.annotation.PostConstruct;
12 | import java.lang.reflect.Constructor;
13 | import java.util.Arrays;
14 | import java.util.List;
15 | import java.util.Set;
16 | import java.util.stream.Collectors;
17 |
18 |
19 | @Service
20 | public class RuleRegistry extends BaseRegistry {
21 |
22 | public static Set> getClassesFromPackage(String packageName) {
23 | Reflections reflections = new Reflections(packageName, new SubTypesScanner(false));
24 | return reflections.getSubTypesOf(AbstractRule.class);
25 | }
26 |
27 | @PostConstruct
28 | public void initialise() {
29 | Set> indicators = getClassesFromPackage("org.ta4j.core.rules");
30 | indicators.stream().forEach(this::add);
31 | }
32 |
33 | public Class extends Rule> getRuleClass(String name) {
34 | return registryMap.get(name);
35 | }
36 |
37 | public RuleInfo getObjectInfo(String name) {
38 | Class aClass = getRuleClass(name);
39 | String className = camelToLower(aClass.getSimpleName());
40 | Constructor[] constructors = aClass.getConstructors();
41 | List indicatorConstructors = Arrays.stream(constructors)
42 | .map(constructor -> RuleConstructor.builder()
43 | .args(mapConstructorArgs(constructor))
44 | .build())
45 | .collect(Collectors.toList());
46 | return RuleInfo.builder()
47 | .constructors(indicatorConstructors)
48 | .name(className)
49 | .build();
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/runner/candle/DataTick.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.runner.candle;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 | import com.zerodhatech.models.Depth;
5 | import lombok.Getter;
6 | import lombok.Setter;
7 |
8 | import java.util.ArrayList;
9 | import java.util.Date;
10 | import java.util.Map;
11 |
12 | @Getter
13 | @Setter
14 | public class DataTick {
15 |
16 | private String mode;
17 | private boolean tradable;
18 | private long instrumentToken;
19 | private double lastTradedPrice;
20 | private double highPrice;
21 | private double lowPrice;
22 | private double openPrice;
23 | private double closePrice;
24 | private double change;
25 | private double lastTradedQuantity;
26 | private double averageTradePrice;
27 | private double volumeTradedToday;
28 | private double totalBuyQuantity;
29 | private double totalSellQuantity;
30 | private Date lastTradedTime;
31 | private double oi;
32 | private double oiDayHigh;
33 | private double oiDayLow;
34 | private Date tickTimestamp;
35 | private Map> depth;
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/runner/candle/LatestBarSeriesProvider.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.runner.candle;
2 |
3 |
4 | import com.dtech.algo.exception.StrategyException;
5 | import com.dtech.algo.series.IntervalBarSeries;
6 | import com.dtech.algo.strategy.builder.ifc.BarSeriesLoader;
7 | import com.dtech.algo.strategy.config.BarSeriesConfig;
8 | import lombok.RequiredArgsConstructor;
9 | import org.springframework.cache.annotation.Cacheable;
10 | import org.springframework.stereotype.Component;
11 |
12 | import java.time.LocalDate;
13 | import java.time.Period;
14 |
15 | /**
16 | * Expected to cache bar series from the request, The request will be similar to that comes for strategy.
17 | */
18 | @RequiredArgsConstructor
19 | @Component
20 | public class LatestBarSeriesProvider implements UpdatableBarSeriesLoader {
21 |
22 | private final BarSeriesLoader delegate;
23 |
24 | @Cacheable(cacheNames = "barSeries")
25 | public IntervalBarSeries loadBarSeries(BarSeriesConfig barSeriesConfig) throws StrategyException {
26 | try {
27 | BarSeriesConfig refSeries = barSeriesConfig.clone();
28 | refSeries.setStartDate(refSeries.getStartDate());
29 | refSeries.setEndDate(refSeries.getEndDate());
30 | return delegate.loadBarSeries(refSeries);
31 | } catch (CloneNotSupportedException e) {
32 | throw new StrategyException(e);
33 | }
34 | }
35 |
36 |
37 | @Override
38 | public void updateBarSeries(DataTick tick) {
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/runner/candle/UpdatableBarSeriesLoader.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.runner.candle;
2 |
3 | import com.dtech.algo.strategy.builder.ifc.BarSeriesLoader;
4 |
5 | public interface UpdatableBarSeriesLoader extends BarSeriesLoader {
6 | void updateBarSeries(DataTick tick);
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/series/Exchange.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.series;
2 |
3 | public enum Exchange {
4 | NSE,
5 | BSE,
6 | NFO,
7 | CDS,
8 | BCD,
9 | MCX
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/series/InstrumentType.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.series;
2 |
3 | public enum InstrumentType {
4 | EQ,
5 | FUT,
6 | CE,
7 | PE
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/series/Interval.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.series;
2 |
3 | import lombok.Getter;
4 | import lombok.RequiredArgsConstructor;
5 |
6 | @RequiredArgsConstructor
7 | @Getter
8 | public enum Interval {
9 | OneMinute("minute", 60),
10 | ThreeMinute("3minute", 3*60),
11 | FiveMinute("5minute", 5*60),
12 | FifteenMinute("15minute", 15*60),
13 | ThirtyMinute("30minute", 30 * 60),
14 | OneHour("60minute", 60 * 60),
15 | FourHours("4hour", 4 * 60 * 60),
16 | Day("day", 24 * 60 * 60),
17 | Week("week", 7 * 24 * 60 * 60);
18 | // Month("month", 30 * 24 * 60 * 60);
19 |
20 | private final String kiteKey;
21 | private final int offset;
22 |
23 | public Interval getParent() {
24 | if( this == OneMinute || this == ThreeMinute || this == FiveMinute) {
25 | return FifteenMinute;
26 | } else if (this == FifteenMinute) {
27 | return OneHour;
28 | } else if(this == OneHour) {
29 | return Day;
30 | } else return Week;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/series/IntervalBarSeries.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.series;
2 |
3 | import org.ta4j.core.BarSeries;
4 |
5 | import java.time.ZonedDateTime;
6 |
7 | public interface IntervalBarSeries extends BarSeries {
8 | Interval getInterval();
9 | SeriesType getSeriesType();
10 | String getInstrument();
11 | void addBarWithTimeValidation(ZonedDateTime endTime, Number openPrice, Number highPrice, Number lowPrice,
12 | Number closePrice, Number volume);
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/series/SeriesType.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.series;
2 |
3 | public enum SeriesType {
4 | EQUITY,
5 | Future,
6 | PutPlus1,
7 | PutPlus2,
8 | PutPlus3,
9 | PutMinus1,
10 | PutMinus2,
11 | PutMinus3,
12 | CallPlus1,
13 | CallPlus2,
14 | CallPlus3,
15 | CallMinus1,
16 | CallMinus2,
17 | CallMinus3;
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/service/StrategyService.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.service;
2 |
3 | public class StrategyService {
4 |
5 |
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/strategy/TradeStrategy.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.strategy;
2 |
3 | import com.dtech.kitecon.strategy.TradeDirection;
4 | import org.ta4j.core.Strategy;
5 |
6 | public interface TradeStrategy extends Strategy {
7 | public TradeDirection getDirection();
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/strategy/TradeStrategyImpl.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.strategy;
2 |
3 | import com.dtech.kitecon.strategy.TradeDirection;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Builder;
6 | import lombok.Data;
7 | import lombok.NoArgsConstructor;
8 | import lombok.experimental.Delegate;
9 | import org.ta4j.core.Strategy;
10 |
11 | @Data
12 | @NoArgsConstructor
13 | @AllArgsConstructor
14 | @Builder
15 | public class TradeStrategyImpl implements TradeStrategy {
16 |
17 | @Delegate
18 | private Strategy delegate;
19 |
20 | private TradeDirection direction;
21 |
22 | private String strategyName;
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/strategy/builder/StrategyBuilderIfc.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.strategy.builder;
2 |
3 | import com.dtech.algo.exception.StrategyException;
4 | import com.dtech.algo.strategy.TradeStrategy;
5 | import com.dtech.algo.strategy.config.StrategyConfig;
6 |
7 | public interface StrategyBuilderIfc {
8 | TradeStrategy buildStrategy(StrategyConfig strategyConfig) throws StrategyException;
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/strategy/builder/cache/BarSeriesCache.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.strategy.builder.cache;
2 |
3 | import com.dtech.algo.series.IntervalBarSeries;
4 | import org.springframework.stereotype.Component;
5 | import org.ta4j.core.BarSeries;
6 |
7 | @Component
8 | public class BarSeriesCache extends ThreadLocalCache {
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/strategy/builder/cache/ConstantsCache.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.strategy.builder.cache;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | @Component
6 | public class ConstantsCache extends ThreadLocalCache {
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/strategy/builder/cache/IndicatorCache.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.strategy.builder.cache;
2 |
3 | import org.springframework.stereotype.Component;
4 | import org.ta4j.core.Indicator;
5 |
6 | @Component
7 | public class IndicatorCache extends ThreadLocalCache {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/strategy/builder/cache/RuleCache.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.strategy.builder.cache;
2 |
3 | import org.springframework.stereotype.Component;
4 | import org.ta4j.core.Indicator;
5 | import org.ta4j.core.Rule;
6 |
7 | @Component
8 | public class RuleCache extends ThreadLocalCache {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/dtech/algo/strategy/builder/cache/ThreadLocalCache.java:
--------------------------------------------------------------------------------
1 | package com.dtech.algo.strategy.builder.cache;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 | import org.springframework.stereotype.Component;
6 |
7 | @Component
8 | public class ThreadLocalCache {
9 |
10 | private ThreadLocal