Developing a Trading Bot using Java

Retired

This book is no longer available for sale.

Developing a Trading Bot using Java

Learn to automate forex trading using JAVA, Spring Framework and other tools

About the Book

This book will take you on an exciting journey of building an automated currency trading bot from scratch. On this journey, we will  learn not only about the nitty gritties of automated trading, but with the help of numerous code samples, have a closer look at Java, Spring Framework, Event Driven programming and other open source APIs, notably Google's Guava API. And of course, it will all be test driven with unit testing coverage > 80%. 

The central theme of the book is to aim to create a framework which can facilitate automated trading on most of the brokerage platforms, with minimum changes.

At the end of the journey, we should have a working trading bot, with a sample implementation using the OANDA REST API, which is free to use. 

About the Author

Shekhar Varshney
Shekhar Varshney

I am a Java Developer working as a free lancer in Switzerland. 

My interests include playing and experimenting with new APIs and frameworks.

I have keen interest in design, architecture, algorithms and data science.

Table of Contents

  • 1. Introduction to Trading Bot
    • 1.1 What is a Trading Bot?
    • 1.2 Why do we need a Trading Bot?
    • 1.3 The capabilities of our Trading Bot
    • 1.4 Design Goals
    • 1.5 Code Organisation and Software Stack Used
    • 1.6 OANDA REST API as Reference Implementation
      • 1.6.1 Opening an OANDA practice account
      • 1.6.2 OANDA JSON Keys
      • 1.6.3 Constructor Dependencies for OANDA implementations
    • 1.7 Event Driven Architecture
      • 1.7.1 Google EventBus
    • 1.8 Provider Helper interface
    • 1.9 TradingConfig class
    • 1.10 Obtaining the source code
    • 1.11 Try It Yourself section
  • 2. Account Management
    • 2.1 Account Provider interface
    • 2.2 A Concrete implementation for AccountDataProvider
    • 2.3 Encapulating everything behind a generic AccountInfoService
    • 2.4 Try it yourself
  • 3. Tradeable Instruments
    • 3.1 Instrument Provider interface
    • 3.2 A Concrete implementation for InstrumentDataProvider
    • 3.3 Encapsulating everything behind a generic InstrumentService
    • 3.4 Try it yourself
  • 4. Event Streaming : Market Data Events
    • 4.1 Streaming Market Data interface
    • 4.2 A concrete implementation for MarketDataStreamingService
    • 4.3 Downstream market data event dissemination: MarketEventCallback
    • 4.4 Try it yourself
  • 5. Historic Instrument Market Data
    • 5.1 How to read a candle stick
    • 5.2 Enum defining the candle stick granularity
    • 5.3 Define POJO to hold candle stick information
    • 5.4 A concrete implementation for HistoricMarketDataProvider
    • 5.5 Discussion: An alternate database implementation
    • 5.6 Candle sticks for moving average calculations
    • 5.7 MovingAverageCalculationService
    • 5.8 Try it yourself
  • 6. Placing Orders and Trades
    • 6.1 Order POJO definition
    • 6.2 Order Management Provider interface
    • 6.3 A Concrete implementation for OrderManagementProvider
    • 6.4 A Simple OrderInfoService
    • 6.5 Validating orders before execution: PreOrderValidationService
    • 6.6 Putting it all together in an OrderExecutionService
    • 6.7 Trade POJO definition
    • 6.8 Trade Management Provider interface
    • 6.9 A Concrete implementation for TradeManagementProvider
    • 6.10 Encapsulating Read operations behind TradeInfoService
    • 6.11 Try it yourself
  • 7. Event Streaming : Trade/Order/Account Events
    • 7.1 Streaming Event interface
    • 7.2 A concrete implementation for EventsStreamingService
    • 7.3 Try it yourself
  • 8. Integration With Twitter
    • 8.1 Creating a Twitter Application
    • 8.2 Spring Social
      • 8.2.1 Using and Configuring Spring Social
    • 8.3 Harvesting FX Tweets
      • 8.3.1 TweetHarvester interface
      • 8.3.2 FXTweetHandler interface
      • 8.3.3 AbstractFXTweetHandler base class
      • 8.3.4 User specific TweetHandlers
    • 8.4 Try it yourself
  • 9. Implementing Strategies
    • 9.1 Copy Twitter Strategy
    • 9.2 Fade The Move Strategy
    • 9.3 Try it yourself
  • 10. HeartBeating
    • 10.1 HeartBeatPayLoad
    • 10.2 Streaming HeartBeat interface
    • 10.3 A concrete implementation for HeartBeatStreamingService
    • 10.4 HeartBeatCallback interface
    • 10.5 DefaultHeartBeatService
    • 10.6 Try it yourself
  • 11. Email Notifications
    • 11.1 Notification Design
      • 11.1.1 EmailPayLoad POJO
      • 11.1.2 EmailContentGenerator interface
      • 11.1.3 Sample Implementations
      • 11.1.4 EventEmailNotifier Service
    • 11.2 Try it yourself
  • 12. Configuration, Deployment and Running the Bot
    • 12.1 Configuration of the trading bot
      • 12.1.1 Core Beans Configuration
      • 12.1.2 Twitter Related Beans configuration
      • 12.1.3 Provider Beans Configuration
      • 12.1.4 Strategies Configuration
      • 12.1.5 Services Configuration
    • 12.2 Building the Bot
    • 12.3 Running the bot
  • 13. Unit Testing
    • 13.1 Using Mockito as a mocking framework.
      • 13.1.1 Mocking HTTP Interaction
      • 13.1.2 Mocking Streams
      • 13.1.3 The versatile verify
      • 13.1.4 Mocking Twitter Interaction
    • 13.2 EclEmma Code Coverage Tool for Eclipse IDE

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub