Skip to main content
Top

2016 | Book

Building Trading Bots Using Java

insite
SEARCH

About this book

Build an automated currency trading bot from scratch with java. In this book, you will learn about the nitty-gritty of automated trading and have a closer look at Java, the Spring Framework, event-driven programming, and other open source APIs, notably Google's Guava API. And of course, development will all be test-driven with unit testing coverage.

The central theme of Building Trading Bots Using Java is to create a framework that can facilitate automated trading on most of the brokerage platforms, with minimum changes. At the end of the journey, you will have a working trading bot, with a sample implementation using the OANDA REST API, which is free to use.

What You'll Learn

Find out about trading botsDiscover the details of tradeable instruments and apply bots to themTrack and use market data eventsPlace orders and tradesWork with trade/order and account events

Who This Book Is For

Experienced programmers new to bots and other algorithmic trading and finance techniques.

Table of Contents

Frontmatter
Chapter 1. Introduction to Trading Bot
Abstract
Welcome to the world of automated trading! The fact that you are reading this book suggests that you want to probably build your own bot, which hopefully can make you some money while you are busy with your day job or, like me, want to experiment with the technology that goes into building such a bot using Java.
Shekhar Varshney
Chapter 2. Account Management
Abstract
The ability to manage the account is probably the first thing we need to build into our bot. When you open a trading account with a brokerage/exchange, an account is created that can be funded directly by bank transfer, credit card, PayPal, etc. An account has a base currency, which is normally the currency of the funding source. For example, if you are based in the UK and have an account with one of the UK banks used to fund the trading account, then the trading account will have a base currency of GBP (British pounds).
Shekhar Varshney
Chapter 3. Tradeable Instruments
Abstract
In this chapter we will focus our attention on instruments available to trade on the brokerage platform. The instrument entity is pretty much the core of a trading platform, as everything revolves around it. From obtaining prices, to placing orders/trades, the instrument is what is the principal actor. Before much further ado, let’s dive into the POJO, which describes the tradeable instrument.
Shekhar Varshney
Chapter 4. Event Streaming: Market Data Events
Abstract
Now we have reached the point where the true existence of the trading bot will start to become apparent. From here onward, we are going to step into the real aspects of trading, one of which is to handle realtime events and act on them, after meaningfully analyzing them.
Shekhar Varshney
Chapter 5. Historic Instrument Market Data
Abstract
In this chapter we discuss some of the techniques to build services to query historic market data. This could be of real interest for folks who want to build strategies based on analysis of historic data for given instruments. Traditionally, historical instrument data on charts are represented as candlesticks. Candlestick patterns are a form of technical analysis that can be used over any time frame. They are similar to bar charts and provide opening and closing values, the high and low price for the time frame in question.
Shekhar Varshney
Chapter 6. Placing Orders and Trades
Abstract
In this chapter, we turn our attention to arguably the most interesting part of the whole trading process, placing orders and trades. An order is an intention to trade. When you place an order for a security, you intend that your order is filled and hope that the price moves to your advantage. When an order is fully or partly filled, it results in the creation of a trading position. An active trading position creates an unrealized profit or loss situation. When this trading position is closed, the unrealized profit/loss is realized and the trader is left with an increased/decreased total book amount.
Shekhar Varshney
Chapter 7. Event Streaming: Trade/Order/Account Events
Abstract
Events are generated on a trading platform when a state of an order/trade/account or any other entity changes on the platform. Here are some examples that could trigger an event:
Shekhar Varshney
Chapter 8. Integration with Twitter
Abstract
We have now reached probably the most exciting part of our journey in building the trading bot. Interacting with social media is probably one of the most important things a bot should be able to do. It probably wasn’t important a few years ago but now it is extremely so because most news, events, and leaks seem to appear on social media first, which affect the markets. The ability to subscribe to these feeds in realtime, make sense of them and make a decision, adds a layer of sophistication to any bot. Ours is no exception, except that we will not attempt to consume thousands of tweets per second but learn the basics of integrating with Twitter. We aim to achieve the following by the end of this chapter:
Shekhar Varshney
Chapter 9. Implementing Strategies
Abstract
It is now time to give our bot wings and make it fly!! Well, what I mean is that the time has come to add capabilities to our bot so that it can make decisions in terms of placing orders based on a certain set of rules that we know is a strategy. Basically, we want to add the power of analysis to our bot to determine whether to buy or sell a currency pair or to stay put and wait for the right moment. The analysis can be based on several external parameters, including:
Shekhar Varshney
Chapter 10. Heartbeating
Abstract
Heartbeats are a crucial element of any trading system. Any streaming or persistent connection over a long period of time must send a heartbeat down the pipe to let the consumer know that all is well and alive. Ours is no exception. In short, the heartbeat indicates the health of a system.
Shekhar Varshney
Chapter 11. E-Mail Notifications
Abstract
In this chapter we discuss e-mail notifications that are extremely useful to notify users when certain events are triggered inside the bot. These notifications are closely coupled to the trade/order/account events discussed in the Chapter 7 might be triggered on the OANDA platform, which suggests that the account faces an urgent margin call. On the other hand, these notifications serve as a useful tool to keep track of what the automated trading bot is up to. By switching on notifications for trade/order and account events, users can have a useful appreciation of the state of things happening inside the bot.
Shekhar Varshney
Chapter 12. Configuration, Deployment, and Running the Bot
Abstract
We are now all set to put the bot into action. All that remains before pressing the button is the configuration and deployment. Configuration of the bot involves the following steps:
Shekhar Varshney
Chapter 13. Unit Testing
Abstract
In this chapter we discuss a very important topic, unit testing our code. Proper unit testing coverage of our bot will ensure that we do not create many regressions when we make changes or add enhancements to the existing code. For some of the target audience of this book, the trading bot may be deployed to place real orders with a live account where huge sums of money could be involved. Making sure that we have enough test coverage will ensure that a code bug would be unlikely to place bad orders. We briefly summarize the immense benefits of unit testing here. Proper unit tests:
Shekhar Varshney
Backmatter
Metadata
Title
Building Trading Bots Using Java
Author
Shekhar Varshney
Copyright Year
2016
Publisher
Apress
Electronic ISBN
978-1-4842-2520-2
Print ISBN
978-1-4842-2519-6
DOI
https://doi.org/10.1007/978-1-4842-2520-2

Premium Partner