├── 9781484225196.jpg ├── LICENSE.txt ├── README.md ├── book-code-master ├── README.md ├── java │ ├── .classpath │ ├── .project │ ├── .springBeans │ ├── buildbot.bsh │ ├── oanda-historic-transactions │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ │ ├── org.eclipse.core.resources.prefs │ │ │ ├── org.eclipse.jdt.core.prefs │ │ │ └── org.eclipse.m2e.core.prefs │ │ ├── .springBeans │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── precioustech │ │ │ │ └── fxtrading │ │ │ │ └── oanda │ │ │ │ └── restapi │ │ │ │ └── account │ │ │ │ └── transaction │ │ │ │ ├── AnalyseTransactionResultService.java │ │ │ │ ├── DailyInterestOandaTransactionTypeHandler.java │ │ │ │ ├── DefaultOandaTransactionTypeHandler.java │ │ │ │ ├── IOandaTransactionTypeHandler.java │ │ │ │ ├── OandaTransactionService.java │ │ │ │ ├── dao │ │ │ │ ├── AbstractDao.java │ │ │ │ ├── OandaAccountDao.java │ │ │ │ ├── OandaTransactionDao.java │ │ │ │ └── TradeDataDao.java │ │ │ │ └── entities │ │ │ │ ├── OandaAccount.java │ │ │ │ ├── OandaTransaction.java │ │ │ │ ├── OandaTransactionResult.java │ │ │ │ └── TradeData.java │ │ │ └── resources │ │ │ ├── ddl_mysql.sql │ │ │ ├── fixTranTypes.sql │ │ │ ├── log4j.properties │ │ │ ├── oanda-transactions-app.xml │ │ │ └── oanda-transactions.properties │ ├── oanda-restapi │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ │ ├── org.eclipse.core.resources.prefs │ │ │ ├── org.eclipse.jdt.core.prefs │ │ │ ├── org.eclipse.m2e.core.prefs │ │ │ ├── org.eclipse.wst.common.component │ │ │ ├── org.eclipse.wst.common.project.facet.core.xml │ │ │ └── org.eclipse.wst.validation.prefs │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── precioustech │ │ │ │ │ └── fxtrading │ │ │ │ │ └── oanda │ │ │ │ │ └── restapi │ │ │ │ │ ├── OandaConstants.java │ │ │ │ │ ├── OandaJsonKeys.java │ │ │ │ │ ├── account │ │ │ │ │ ├── OandaAccountDataProviderService.java │ │ │ │ │ └── transaction │ │ │ │ │ │ └── OandaTransactionDataProviderService.java │ │ │ │ │ ├── events │ │ │ │ │ ├── AccountEventPayLoad.java │ │ │ │ │ ├── AccountEvents.java │ │ │ │ │ ├── OrderEventPayLoad.java │ │ │ │ │ ├── OrderEvents.java │ │ │ │ │ ├── OrderFilledEventHandler.java │ │ │ │ │ ├── OrderPayLoadToTweet.java │ │ │ │ │ ├── TradeEventHandler.java │ │ │ │ │ ├── TradeEventPayLoad.java │ │ │ │ │ └── TradeEvents.java │ │ │ │ │ ├── helper │ │ │ │ │ └── OandaProviderHelper.java │ │ │ │ │ ├── instrument │ │ │ │ │ └── OandaInstrumentDataProviderService.java │ │ │ │ │ ├── marketdata │ │ │ │ │ ├── OandaCurrentPriceInfoProvider.java │ │ │ │ │ └── historic │ │ │ │ │ │ ├── OandaHistoricMarketDataProvider.java │ │ │ │ │ │ └── OandaLimitExceededException.java │ │ │ │ │ ├── order │ │ │ │ │ └── OandaOrderManagementProvider.java │ │ │ │ │ ├── position │ │ │ │ │ └── OandaPositionManagementProvider.java │ │ │ │ │ ├── streaming │ │ │ │ │ ├── OandaStreamingService.java │ │ │ │ │ ├── events │ │ │ │ │ │ └── OandaEventsStreamingService.java │ │ │ │ │ └── marketdata │ │ │ │ │ │ └── OandaMarketDataStreamingService.java │ │ │ │ │ ├── trade │ │ │ │ │ └── OandaTradeManagementProvider.java │ │ │ │ │ └── utils │ │ │ │ │ └── OandaUtils.java │ │ │ └── resources │ │ │ │ └── log4j.properties │ │ │ └── test │ │ │ ├── java │ │ │ └── com │ │ │ │ └── precioustech │ │ │ │ └── fxtrading │ │ │ │ └── oanda │ │ │ │ └── restapi │ │ │ │ ├── OandaTestConstants.java │ │ │ │ ├── OandaTestUtils.java │ │ │ │ ├── account │ │ │ │ ├── OandaAccountDataProviderServiceTest.java │ │ │ │ └── transaction │ │ │ │ │ └── OandaTransactionDataProviderServiceTest.java │ │ │ │ ├── events │ │ │ │ ├── OrderFilledEventHandlerTest.java │ │ │ │ ├── OrderPayLoadToTweetTest.java │ │ │ │ └── TradeEventHandlerTest.java │ │ │ │ ├── helper │ │ │ │ └── OandaProviderHelperTest.java │ │ │ │ ├── instrument │ │ │ │ └── OandaInstrumentDataProviderServiceTest.java │ │ │ │ ├── marketdata │ │ │ │ ├── OandaCurrentPriceInfoProviderTest.java │ │ │ │ └── historic │ │ │ │ │ └── OandaHistoricMarketDataProviderTest.java │ │ │ │ ├── order │ │ │ │ └── OandaOrderManagementProviderTest.java │ │ │ │ ├── position │ │ │ │ └── OandaPositionManagementProviderTest.java │ │ │ │ ├── streaming │ │ │ │ └── OandaStreamingServiceTest.java │ │ │ │ └── trade │ │ │ │ ├── OandaTradeManagementProviderTest.java │ │ │ │ └── utils │ │ │ │ └── OandaUtilsTest.java │ │ │ └── resources │ │ │ ├── account123456.txt │ │ │ ├── accountsAll.txt │ │ │ ├── allOrders.txt │ │ │ ├── candlesCountM.txt │ │ │ ├── candlesFromToS5.txt │ │ │ ├── currentPrices.txt │ │ │ ├── events.txt │ │ │ ├── historicTransactions.txt │ │ │ ├── instruments.txt │ │ │ ├── marketData123456.txt │ │ │ ├── newOrder.txt │ │ │ ├── newOrderLimit.txt │ │ │ ├── orderForAccount123456.txt │ │ │ ├── positionForInstrument.txt │ │ │ ├── positionsForAccount123456.txt │ │ │ ├── trade1800805337ForAccount123456.txt │ │ │ ├── tradeModify.txt │ │ │ ├── tradesForAccount123456.txt │ │ │ └── transaction123456.txt │ ├── pom.xml │ ├── runbot-oanda.bsh │ ├── tradingbot-app │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ │ ├── org.eclipse.core.resources.prefs │ │ │ ├── org.eclipse.jdt.core.prefs │ │ │ ├── org.eclipse.m2e.core.prefs │ │ │ ├── org.eclipse.wst.common.component │ │ │ ├── org.eclipse.wst.common.project.facet.core.xml │ │ │ └── org.eclipse.wst.validation.prefs │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── precioustech │ │ │ │ │ └── fxtrading │ │ │ │ │ └── tradingbot │ │ │ │ │ ├── FXTradingBot.java │ │ │ │ │ ├── TradingConfig.java │ │ │ │ │ ├── events │ │ │ │ │ └── notification │ │ │ │ │ │ └── email │ │ │ │ │ │ └── EventEmailNotifier.java │ │ │ │ │ ├── social │ │ │ │ │ └── twitter │ │ │ │ │ │ ├── CloseFXTradeTweet.java │ │ │ │ │ │ ├── FXTradeTweet.java │ │ │ │ │ │ ├── NewFXTradeTweet.java │ │ │ │ │ │ └── tweethandler │ │ │ │ │ │ ├── AbstractFXTweetHandler.java │ │ │ │ │ │ ├── FXTweetHandler.java │ │ │ │ │ │ ├── SFOsignalsTweetHandler.java │ │ │ │ │ │ ├── SignalFactoryFXTweetHandler.java │ │ │ │ │ │ ├── TheDailyIncomeFXTweetHandler.java │ │ │ │ │ │ ├── ThirdBrainFx2TweetHandler.java │ │ │ │ │ │ ├── TweetFXTradeService.java │ │ │ │ │ │ ├── TweetHarvester.java │ │ │ │ │ │ └── ZuluTrader101FXTweetHandler.java │ │ │ │ │ ├── spring │ │ │ │ │ └── FindEventBusSubscribers.java │ │ │ │ │ └── strategies │ │ │ │ │ ├── CopyTwitterStrategy.java │ │ │ │ │ └── FadeTheMoveStrategy.java │ │ │ └── resources │ │ │ │ ├── log4j.properties │ │ │ │ ├── tradingbot-app.xml │ │ │ │ ├── tradingbot-oanda-test.properties │ │ │ │ ├── tradingbot-oanda.properties │ │ │ │ ├── tradingbot-oanda.xml │ │ │ │ └── tradingbot.properties │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── precioustech │ │ │ └── fxtrading │ │ │ └── tradingbot │ │ │ ├── TradingAppTestConstants.java │ │ │ ├── events │ │ │ └── notification │ │ │ │ └── email │ │ │ │ └── EventEmailNotifierTest.java │ │ │ ├── social │ │ │ └── twitter │ │ │ │ └── tweethandler │ │ │ │ ├── SignalFactoryFXTweetHandlerTest.java │ │ │ │ ├── TweetFXTradeServiceTest.java │ │ │ │ └── ZuluTrader101FXTweetHandlerTest.java │ │ │ └── strategies │ │ │ ├── CopyTwitterStrategyTest.java │ │ │ └── FadeTheMoveStrategyTest.java │ ├── tradingbot-core │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ │ ├── org.eclipse.core.resources.prefs │ │ │ ├── org.eclipse.jdt.core.prefs │ │ │ ├── org.eclipse.m2e.core.prefs │ │ │ ├── org.eclipse.wst.common.component │ │ │ ├── org.eclipse.wst.common.project.facet.core.xml │ │ │ └── org.eclipse.wst.validation.prefs │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── precioustech │ │ │ │ └── fxtrading │ │ │ │ ├── BaseTradingConfig.java │ │ │ │ ├── TradingConstants.java │ │ │ │ ├── TradingDecision.java │ │ │ │ ├── TradingSignal.java │ │ │ │ ├── account │ │ │ │ ├── Account.java │ │ │ │ ├── AccountDataProvider.java │ │ │ │ ├── AccountInfoService.java │ │ │ │ └── transaction │ │ │ │ │ ├── Transaction.java │ │ │ │ │ └── TransactionDataProvider.java │ │ │ │ ├── events │ │ │ │ ├── Event.java │ │ │ │ ├── EventCallback.java │ │ │ │ ├── EventCallbackImpl.java │ │ │ │ ├── EventHandler.java │ │ │ │ ├── EventPayLoad.java │ │ │ │ ├── EventPayLoadToTweet.java │ │ │ │ └── notification │ │ │ │ │ └── email │ │ │ │ │ ├── EmailContentGenerator.java │ │ │ │ │ └── EmailPayLoad.java │ │ │ │ ├── heartbeats │ │ │ │ ├── AbstractHeartBeatService.java │ │ │ │ ├── DefaultHeartBeatService.java │ │ │ │ ├── HeartBeatCallback.java │ │ │ │ ├── HeartBeatCallbackImpl.java │ │ │ │ └── HeartBeatPayLoad.java │ │ │ │ ├── helper │ │ │ │ └── ProviderHelper.java │ │ │ │ ├── instrument │ │ │ │ ├── InstrumentDataProvider.java │ │ │ │ ├── InstrumentPairInterestRate.java │ │ │ │ ├── InstrumentService.java │ │ │ │ ├── TradeableInstrument.java │ │ │ │ └── economicevent │ │ │ │ │ ├── InstrumentEconomicEvent.java │ │ │ │ │ └── InstrumentEconomicEventImpact.java │ │ │ │ ├── marketdata │ │ │ │ ├── CurrentPriceInfoProvider.java │ │ │ │ ├── MarketDataPayLoad.java │ │ │ │ ├── MarketEventCallback.java │ │ │ │ ├── MarketEventHandlerImpl.java │ │ │ │ ├── PipJumpCutOffCalculator.java │ │ │ │ ├── PipJumpCutOffCalculatorService.java │ │ │ │ ├── Price.java │ │ │ │ └── historic │ │ │ │ │ ├── CandleStick.java │ │ │ │ │ ├── CandleStickGranularity.java │ │ │ │ │ ├── HistoricMarketDataProvider.java │ │ │ │ │ └── MovingAverageCalculationService.java │ │ │ │ ├── order │ │ │ │ ├── Order.java │ │ │ │ ├── OrderExecutionService.java │ │ │ │ ├── OrderInfoService.java │ │ │ │ ├── OrderManagementProvider.java │ │ │ │ ├── OrderType.java │ │ │ │ └── PreOrderValidationService.java │ │ │ │ ├── position │ │ │ │ ├── Position.java │ │ │ │ └── PositionManagementProvider.java │ │ │ │ ├── streaming │ │ │ │ ├── events │ │ │ │ │ └── EventsStreamingService.java │ │ │ │ ├── heartbeats │ │ │ │ │ └── HeartBeatStreamingService.java │ │ │ │ └── marketdata │ │ │ │ │ └── MarketDataStreamingService.java │ │ │ │ ├── trade │ │ │ │ ├── Trade.java │ │ │ │ ├── TradeInfoService.java │ │ │ │ ├── TradeManagementProvider.java │ │ │ │ └── strategies │ │ │ │ │ └── TradingStrategy.java │ │ │ │ └── utils │ │ │ │ └── TradingUtils.java │ │ │ └── test │ │ │ ├── java │ │ │ └── com │ │ │ │ └── precioustech │ │ │ │ └── fxtrading │ │ │ │ ├── TradingTestConstants.java │ │ │ │ ├── account │ │ │ │ └── AccountInfoServiceTest.java │ │ │ │ ├── heartbeats │ │ │ │ └── DefaultHeartBeatServiceTest.java │ │ │ │ ├── instrument │ │ │ │ └── InstrumentServiceTest.java │ │ │ │ ├── marketdata │ │ │ │ ├── MarketEventHandlerImplTest.java │ │ │ │ ├── PipJumpCutOffCalculatorServiceTest.java │ │ │ │ └── historic │ │ │ │ │ └── MovingAverageCalculationServiceTest.java │ │ │ │ ├── order │ │ │ │ ├── OrderExecutionServiceTest.java │ │ │ │ ├── OrderInfoServiceTest.java │ │ │ │ └── PreOrderValidationServiceTest.java │ │ │ │ ├── trade │ │ │ │ └── TradeInfoServiceTest.java │ │ │ │ └── utils │ │ │ │ └── TradingUtilsTest.java │ │ │ └── resources │ │ │ ├── foobar.txt │ │ │ └── log4j.properties │ ├── tradingbot-demo-programs │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ │ ├── org.eclipse.core.resources.prefs │ │ │ ├── org.eclipse.jdt.core.prefs │ │ │ └── org.eclipse.m2e.core.prefs │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── precioustech │ │ │ │ └── fxtrading │ │ │ │ ├── account │ │ │ │ └── AccountInfoServiceDemo.java │ │ │ │ ├── heartbeats │ │ │ │ └── DefaultHeartBeatServiceDemo.java │ │ │ │ ├── instrument │ │ │ │ └── InstrumentServiceDemo.java │ │ │ │ ├── oanda │ │ │ │ └── restapi │ │ │ │ │ ├── account │ │ │ │ │ └── transaction │ │ │ │ │ │ └── TransactionDataProviderDemo.java │ │ │ │ │ ├── marketdata │ │ │ │ │ └── historic │ │ │ │ │ │ ├── HistoricMarketDataOnDemandDemo.java │ │ │ │ │ │ └── HistoricMarketDataProviderDemo.java │ │ │ │ │ └── streaming │ │ │ │ │ ├── events │ │ │ │ │ └── EventsStreamingServiceDemo.java │ │ │ │ │ └── marketdata │ │ │ │ │ ├── MarketDataStreamingServiceDemo.java │ │ │ │ │ └── MovingAverageCalculationServiceDemo.java │ │ │ │ ├── order │ │ │ │ ├── OrderExecutionServiceDemo.java │ │ │ │ ├── OrderInfoServiceDemo.java │ │ │ │ └── PreValidationServiceDemo.java │ │ │ │ ├── trade │ │ │ │ └── TradeInfoServiceDemo.java │ │ │ │ └── tradingbot │ │ │ │ ├── events │ │ │ │ └── notification │ │ │ │ │ └── email │ │ │ │ │ └── EventEmailNotifierDemo.java │ │ │ │ ├── social │ │ │ │ └── twitter │ │ │ │ │ └── tweethandler │ │ │ │ │ ├── TweetFXTradeServiceDemo.java │ │ │ │ │ └── TweetHarvesterDemo.java │ │ │ │ └── strategies │ │ │ │ └── FadeTheMoveStrategyDemo.java │ │ │ └── resources │ │ │ ├── emailnotify-demo.xml │ │ │ ├── fadethemove-demo.xml │ │ │ ├── log4j.properties │ │ │ ├── tweetfxtrade-demo.xml │ │ │ └── tweetharvester-demo.xml │ ├── tradingbot-prediction-api │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ │ ├── org.eclipse.core.resources.prefs │ │ │ ├── org.eclipse.jdt.core.prefs │ │ │ ├── org.eclipse.m2e.core.prefs │ │ │ ├── org.eclipse.wst.common.component │ │ │ └── org.eclipse.wst.common.project.facet.core.xml │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── precioustech │ │ │ │ └── fxtrading │ │ │ │ └── prediction │ │ │ │ ├── DirectionEnum.java │ │ │ │ ├── NaiveBayesPredictionService.java │ │ │ │ ├── PredictionData.java │ │ │ │ ├── TradingSessionEnum.java │ │ │ │ ├── dao │ │ │ │ ├── PredictionDao.java │ │ │ │ └── PredictionDaoJdbcTemplImpl.java │ │ │ │ └── utils │ │ │ │ └── PredictionUtils.java │ │ │ └── resources │ │ │ ├── log4j.properties │ │ │ ├── tradingbot-prediction-app.xml │ │ │ └── tradingbot-prediction.properties │ └── tradingbot-web │ │ ├── .classpath │ │ ├── .project │ │ ├── .settings │ │ ├── org.eclipse.jdt.core.prefs │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.wst.common.component │ │ ├── org.eclipse.wst.common.project.facet.core.xml │ │ ├── org.eclipse.wst.validation.prefs │ │ ├── org.springframework.ide.eclipse.beans.core.prefs │ │ └── org.springframework.ide.eclipse.core.prefs │ │ ├── .springBeans │ │ ├── pom.xml │ │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── precioustech │ │ │ │ └── fxtrading │ │ │ │ └── web │ │ │ │ ├── HomeController.java │ │ │ │ └── marketdata │ │ │ │ └── historic │ │ │ │ └── MarketDataController.java │ │ ├── resources │ │ │ └── log4j.xml │ │ └── webapp │ │ │ ├── WEB-INF │ │ │ ├── spring │ │ │ │ ├── appServlet │ │ │ │ │ └── servlet-context.xml │ │ │ │ └── root-context.xml │ │ │ ├── views │ │ │ │ ├── candles.jsp │ │ │ │ └── home.jsp │ │ │ └── web.xml │ │ │ └── resources │ │ │ ├── css │ │ │ ├── images │ │ │ │ ├── Sorting icons.psd │ │ │ │ ├── favicon.ico │ │ │ │ ├── sort_asc.png │ │ │ │ ├── sort_asc_disabled.png │ │ │ │ ├── sort_both.png │ │ │ │ ├── sort_desc.png │ │ │ │ └── sort_desc_disabled.png │ │ │ └── jquery │ │ │ │ ├── jquery-ui-timepicker-addon.css │ │ │ │ ├── jquery-ui.css │ │ │ │ ├── jquery-ui.min.css │ │ │ │ ├── jquery-ui.structure.css │ │ │ │ ├── jquery-ui.structure.min.css │ │ │ │ ├── jquery-ui.theme.css │ │ │ │ ├── jquery-ui.theme.min.css │ │ │ │ └── jquery.dataTables.min.css │ │ │ └── js │ │ │ └── jquery │ │ │ ├── images │ │ │ ├── ui-bg_diagonals-thick_90_eeeeee_40x40.png │ │ │ ├── ui-bg_glass_100_e4f1fb_1x400.png │ │ │ ├── ui-bg_glass_50_3baae3_1x400.png │ │ │ ├── ui-bg_glass_80_d7ebf9_1x400.png │ │ │ ├── ui-bg_highlight-hard_100_f2f5f7_1x100.png │ │ │ ├── ui-bg_highlight-hard_70_000000_1x100.png │ │ │ ├── ui-bg_highlight-soft_100_deedf7_1x100.png │ │ │ ├── ui-bg_highlight-soft_25_ffef8f_1x100.png │ │ │ ├── ui-icons_2694e8_256x240.png │ │ │ ├── ui-icons_2e83ff_256x240.png │ │ │ ├── ui-icons_3d80b3_256x240.png │ │ │ ├── ui-icons_72a7cf_256x240.png │ │ │ └── ui-icons_ffffff_256x240.png │ │ │ ├── jquery-ui-timepicker-addon.js │ │ │ ├── jquery-ui.js │ │ │ ├── jquery-ui.min.js │ │ │ ├── jquery.dataTables.min.js │ │ │ ├── jquery.js │ │ │ └── jquery.min.js │ │ └── test │ │ └── resources │ │ └── log4j.xml └── python │ └── naivebayes.py └── contributing.md /9781484225196.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/9781484225196.jpg -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/LICENSE.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apress Source Code 2 | 3 | This repository accompanies [*Building Trading Bots Using Java*](http://www.apress.com/9781484225196) by Shekhar Varshney (Apress, 2016). 4 | 5 | ![Cover image](9781484225196.jpg) 6 | 7 | Download the files as a zip using the green button, or clone the repository to your machine using Git. 8 | 9 | ## Releases 10 | 11 | Release v1.0 corresponds to the code in the published book, without corrections or updates. 12 | 13 | ## Contributions 14 | 15 | See the file Contributing.md for more information on how you can contribute to this repository. 16 | -------------------------------------------------------------------------------- /book-code-master/README.md: -------------------------------------------------------------------------------- 1 | # Automated Trading Bot Framework 2 | 3 | The software is covered by the *Apache License* and is discussed in my book [Developing a Trading Bot using JAVA](http://www.leanpub.com/tradingbot) 4 | 5 | ##How to run the software 6 | 7 | 1. Download the source code. 8 | 2. Change the **tradingbot.properties** by configuring the email and twitter properties 9 | 3. Change the **tradingbot-oanda.properties** by configuring the your oanda account specific properties 10 | 4. Build the bot by executing script **buildbot.bsh**. The script uses maven. Please make sure its properly configured. 11 | 5. Run the bot using script **runbot-oanda.bsh** 12 | 13 | Follow live tweets of trades executed by the bot at [Java TradingBot Twitter Feed](https://twitter.com/javatradingbot). 14 | 15 | The bot is currently using the strategies discussed in the book and some experimental strategies which are implemented in the branch **new_ideas**. 16 | -------------------------------------------------------------------------------- /book-code-master/java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /book-code-master/java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | oanda-historic-transactions 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /book-code-master/java/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /book-code-master/java/buildbot.bsh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function buildmodule { 4 | cd $SCRIPT_DIR/$1 5 | mvn clean install 6 | if [[ "$?" -ne 0 ]]; then 7 | echo "ERROR: $1 project build failed. BUILD FAILED"; exit -1; 8 | fi 9 | } 10 | SCRIPT_DIR=`pwd` 11 | buildmodule tradingbot-core 12 | buildmodule oanda-restapi 13 | buildmodule tradingbot-app 14 | 15 | echo "TRADING BOT built successfully" 16 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | oanda-historic-transactions 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/src/main/java/com/precioustech/fxtrading/oanda/restapi/account/transaction/DailyInterestOandaTransactionTypeHandler.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.oanda.restapi.account.transaction; 2 | 3 | import java.util.Collection; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Qualifier; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | import com.precioustech.fxtrading.TradingSignal; 10 | import com.precioustech.fxtrading.account.transaction.Transaction; 11 | import com.precioustech.fxtrading.oanda.restapi.account.transaction.entities.OandaTransaction; 12 | import com.precioustech.fxtrading.trade.Trade; 13 | import com.precioustech.fxtrading.trade.TradeInfoService; 14 | 15 | //@Component("dailyInterestHandler") 16 | public class DailyInterestOandaTransactionTypeHandler implements IOandaTransactionTypeHandler { 17 | 18 | @Autowired 19 | private TradeInfoService tradeInfoService; 20 | 21 | @Autowired 22 | @Qualifier(value = "defaultTransactionTypeHandler") 23 | private IOandaTransactionTypeHandler defaultTransactionTypeHandler; 24 | 25 | @Override 26 | @Transactional 27 | public OandaTransaction handle(Transaction transaction) { 28 | OandaTransaction oandaTransaction = defaultTransactionTypeHandler.handle(transaction); 29 | 30 | Collection> instrumentTrades = this.tradeInfoService 31 | .getTradesForAccountAndInstrument(transaction.getAccountId(), transaction.getInstrument()); 32 | if (!instrumentTrades.isEmpty()) { 33 | Trade instrumentTrade = instrumentTrades.iterator().next(); 34 | long units = instrumentTrade.getUnits(); 35 | if (transaction.getSide() == TradingSignal.SHORT) { 36 | units *= -1; 37 | } 38 | oandaTransaction.setUnits(units); 39 | } 40 | oandaTransaction.setPrice(0.0); 41 | return oandaTransaction; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/src/main/java/com/precioustech/fxtrading/oanda/restapi/account/transaction/DefaultOandaTransactionTypeHandler.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.oanda.restapi.account.transaction; 2 | 3 | import java.util.Collection; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | import com.precioustech.fxtrading.account.transaction.Transaction; 9 | import com.precioustech.fxtrading.oanda.restapi.account.transaction.dao.OandaAccountDao; 10 | import com.precioustech.fxtrading.oanda.restapi.account.transaction.entities.OandaAccount; 11 | import com.precioustech.fxtrading.oanda.restapi.account.transaction.entities.OandaTransaction; 12 | 13 | //@Component("defaultHandler") 14 | public class DefaultOandaTransactionTypeHandler implements IOandaTransactionTypeHandler { 15 | 16 | @Autowired 17 | protected OandaAccountDao accountDao; 18 | 19 | @Override 20 | @Transactional 21 | public OandaTransaction handle(Transaction transaction) { 22 | OandaTransaction oandaTransaction = new OandaTransaction(); 23 | OandaAccount account = fetchAccountPojo(transaction.getAccountId()); 24 | oandaTransaction.setAccount(account); 25 | oandaTransaction.setInterest(transaction.getInterest()); 26 | oandaTransaction.setLinkedTransactionId(transaction.getLinkedTransactionId()); 27 | oandaTransaction.setPnl(transaction.getPnl()); 28 | oandaTransaction.setPrice(transaction.getPrice() == null ? 0.0 : transaction.getPrice()); 29 | oandaTransaction.setTransactionId(transaction.getTransactionId()); 30 | oandaTransaction.setTransactionTime(transaction.getTransactionTime()); 31 | oandaTransaction.setTransactionType(transaction.getTransactionType().name()); 32 | oandaTransaction.setUnits(transaction.getUnits()); 33 | oandaTransaction.setInstrument(transaction.getInstrument().getInstrument()); 34 | return oandaTransaction; 35 | } 36 | 37 | private OandaAccount fetchAccountPojo(Long accountId) { 38 | Collection allAccounts = this.accountDao.allAccounts(); 39 | for (OandaAccount account : allAccounts) { 40 | if (accountId.equals(account.getAccountId())) { 41 | return account; 42 | } 43 | } 44 | return null; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/src/main/java/com/precioustech/fxtrading/oanda/restapi/account/transaction/IOandaTransactionTypeHandler.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.oanda.restapi.account.transaction; 2 | 3 | import com.precioustech.fxtrading.account.transaction.Transaction; 4 | import com.precioustech.fxtrading.oanda.restapi.account.transaction.entities.OandaTransaction; 5 | 6 | public interface IOandaTransactionTypeHandler { 7 | 8 | OandaTransaction handle(Transaction transaction); 9 | } 10 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/src/main/java/com/precioustech/fxtrading/oanda/restapi/account/transaction/dao/AbstractDao.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.oanda.restapi.account.transaction.dao; 2 | 3 | import org.hibernate.Session; 4 | import org.hibernate.SessionFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | public abstract class AbstractDao { 8 | @Autowired 9 | private SessionFactory sessionFactory; 10 | 11 | protected Session getSession() { 12 | return this.sessionFactory.getCurrentSession(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/src/main/java/com/precioustech/fxtrading/oanda/restapi/account/transaction/dao/OandaAccountDao.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.oanda.restapi.account.transaction.dao; 2 | 3 | import java.util.Collection; 4 | import java.util.List; 5 | 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | import com.google.common.collect.Lists; 9 | import com.precioustech.fxtrading.oanda.restapi.account.transaction.entities.OandaAccount; 10 | 11 | public class OandaAccountDao extends AbstractDao { 12 | 13 | @Transactional 14 | public Collection allAccounts() { 15 | @SuppressWarnings("rawtypes") 16 | List results = getSession().createCriteria(OandaAccount.class).list(); 17 | Collection accounts = Lists.newArrayList(); 18 | for (Object row : results) { 19 | accounts.add((OandaAccount) row); 20 | } 21 | return accounts; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/src/main/java/com/precioustech/fxtrading/oanda/restapi/account/transaction/dao/TradeDataDao.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.oanda.restapi.account.transaction.dao; 2 | 3 | import java.util.List; 4 | 5 | import org.hibernate.Criteria; 6 | import org.hibernate.Session; 7 | import org.hibernate.criterion.DetachedCriteria; 8 | import org.hibernate.criterion.Projections; 9 | import org.hibernate.criterion.Restrictions; 10 | import org.hibernate.criterion.Subqueries; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import com.precioustech.fxtrading.oanda.restapi.account.transaction.entities.OandaTransactionResult; 14 | import com.precioustech.fxtrading.oanda.restapi.account.transaction.entities.TradeData; 15 | 16 | public class TradeDataDao extends AbstractDao { 17 | 18 | @Transactional 19 | public List findTradeDataWithMissingTransactionResults() { 20 | Session session = getSession(); 21 | Criteria criteria = session.createCriteria(TradeData.class, "td"); 22 | DetachedCriteria detCriteria = DetachedCriteria.forClass(OandaTransactionResult.class, "tr"); 23 | detCriteria.add(Restrictions.eqProperty("td.transactionId", "tr.transactionId")); 24 | criteria.add(Subqueries.notExists(detCriteria.setProjection(Projections.property("tr.transactionId")))); 25 | return criteria.list(); 26 | } 27 | 28 | @Transactional 29 | public void saveTransactionResult(OandaTransactionResult transactionResult) { 30 | getSession().saveOrUpdate(transactionResult); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/src/main/java/com/precioustech/fxtrading/oanda/restapi/account/transaction/entities/OandaAccount.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.oanda.restapi.account.transaction.entities; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | 10 | import org.hibernate.annotations.Cache; 11 | import org.hibernate.annotations.CacheConcurrencyStrategy; 12 | 13 | @Entity 14 | @Table(name = "oanda_account") 15 | @Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "accounts") 16 | public class OandaAccount implements Serializable { 17 | 18 | private static final long serialVersionUID = 7551620715795946711L; 19 | @Id 20 | @Column(name = "account_id") 21 | private Long accountId; 22 | @Column(name = "currency", nullable = false, unique = true) 23 | private String accountCurrency; 24 | 25 | public OandaAccount() { 26 | 27 | } 28 | 29 | public OandaAccount(Long accountId, String accountCurrency) { 30 | this.accountCurrency = accountCurrency; 31 | this.accountId = accountId; 32 | } 33 | 34 | public Long getAccountId() { 35 | return accountId; 36 | } 37 | 38 | public void setAccountId(Long accountId) { 39 | this.accountId = accountId; 40 | } 41 | 42 | public String getAccountCurrency() { 43 | return accountCurrency; 44 | } 45 | 46 | public void setAccountCurrency(String accountCurrency) { 47 | this.accountCurrency = accountCurrency; 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | final int prime = 31; 53 | int result = 1; 54 | result = prime * result + ((accountCurrency == null) ? 0 : accountCurrency.hashCode()); 55 | return result; 56 | } 57 | 58 | @Override 59 | public boolean equals(Object obj) { 60 | if (this == obj) 61 | return true; 62 | if (obj == null) 63 | return false; 64 | if (getClass() != obj.getClass()) 65 | return false; 66 | OandaAccount other = (OandaAccount) obj; 67 | if (accountCurrency == null) { 68 | if (other.accountCurrency != null) 69 | return false; 70 | } else if (!accountCurrency.equals(other.accountCurrency)) 71 | return false; 72 | return true; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return String.format("%d - %s", this.accountId, this.accountCurrency); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/src/main/java/com/precioustech/fxtrading/oanda/restapi/account/transaction/entities/OandaTransactionResult.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.oanda.restapi.account.transaction.entities; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | 10 | @Entity 11 | @Table(name = "oanda_transaction_result") 12 | public class OandaTransactionResult implements Serializable { 13 | 14 | private static final long serialVersionUID = 4206656523672868773L; 15 | 16 | @Id 17 | @Column(name = "transaction_id") 18 | private Long transactionId; 19 | 20 | @Column(name = "max_adverse_price", nullable = true) 21 | private Double maxAdversePrice; 22 | 23 | @Column(name = "is_bad_decision", nullable = true) 24 | private String badDecision; 25 | 26 | public Long getTransactionId() { 27 | return transactionId; 28 | } 29 | 30 | public void setTransactionId(Long transactionId) { 31 | this.transactionId = transactionId; 32 | } 33 | 34 | public Double getMaxAdversePrice() { 35 | return maxAdversePrice; 36 | } 37 | 38 | public void setMaxAdversePrice(Double maxAdversePrice) { 39 | this.maxAdversePrice = maxAdversePrice; 40 | } 41 | 42 | public String getBadDecision() { 43 | return badDecision; 44 | } 45 | 46 | public void setBadDecision(String badDecision) { 47 | this.badDecision = badDecision; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/src/main/resources/ddl_mysql.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `oanda_account` ( 2 | `account_id` int(11) NOT NULL, 3 | `currency` char(3) NOT NULL, 4 | PRIMARY KEY (`account_id`) 5 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 6 | 7 | CREATE TABLE `oanda_transaction_history` ( 8 | `transaction_id` bigint(20) NOT NULL, 9 | `transaction_type` varchar(128) NOT NULL, 10 | `account_id` int(11) NOT NULL, 11 | `instrument` char(7) NOT NULL, 12 | `units` int(11) NOT NULL, 13 | `transaction_time` datetime NOT NULL, 14 | `price` decimal(20,5) NOT NULL, 15 | `interest` decimal(10,5) DEFAULT NULL, 16 | `pnl` decimal(10,5) DEFAULT NULL, 17 | `lnk_transaction_id` bigint(20) DEFAULT NULL, 18 | PRIMARY KEY (`transaction_id`), 19 | KEY `fk_oanda_acc_id` (`account_id`), 20 | CONSTRAINT `fk_oanda_acc_id` FOREIGN KEY (`account_id`) REFERENCES `oanda_account` (`account_id`) 21 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 22 | 23 | create table oanda_transaction_result 24 | ( 25 | transaction_id bigint(20) not null primary key, 26 | max_adverse_price decimal(20,5) null, 27 | is_bad_decision char(1) not null check(is_bad_decision in ('Y','N')), 28 | constraint fk_tran_id foreign key(transaction_id) 29 | references oanda_transaction_history(transaction_id) 30 | ); 31 | 32 | CREATE or replace VIEW `trade_data` 33 | AS 34 | select `t1`.`transaction_id` AS `transaction_id`,`t1`.`instrument` AS `instrument`, 35 | `t1`.`units` AS `units`,`t1`.`price` AS `close_price`,`t1`.`pnl` AS `pnl`, 36 | `t1`.`account_id` AS `account_id`,`t1`.`transaction_time` AS `transaction_close`, 37 | `t2`.`price` AS `transaction_price`,`t2`.`transaction_time` AS `transaction_open`, 38 | `t1`.`transaction_type` AS `transaction_type`, 39 | timestampdiff(MINUTE,`t2`.`transaction_time`,`t1`.`transaction_time`) AS `duration_open`, 40 | (case when (hour(`t1`.`transaction_time`) <= 6) then 'NIGHT' 41 | when (hour(`t1`.`transaction_time`) <= 14) then 'MORNING' 42 | when (hour(`t1`.`transaction_time`) <= 22) then 'EVENING' else 'NIGHT' end) AS `session`, 43 | (case when (t1.pnl >=0) 44 | then (case when `t1`.`price` > `t2`.`price` then 'LONG' 45 | else 'SHORT' end) 46 | else (case when `t1`.`price` > `t2`.`price` then 'SHORT' 47 | else 'LONG' end) 48 | end) as direction 49 | from (`oanda_transaction_history` `t1` 50 | join `oanda_transaction_history` `t2` on((`t1`.`lnk_transaction_id` = `t2`.`transaction_id`))) 51 | where (`t1`.`transaction_type` in ('TRADE_CLOSE','STOP_LOSS_FILLED','TAKE_PROFIT_FILLED')); 52 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | #Nike log4j log file 2 | 3 | log4j.rootLogger=INFO, stdout, file 4 | 5 | #stdout Log 6 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 7 | log4j.appender.stdout.Threshold=INFO 8 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] - %m%n 10 | log4j.appender.stdout.org.hibernate.type=TRACE 11 | 12 | #file Log 13 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 14 | log4j.appender.file.Threshold=INFO 15 | log4j.appender.file.File=/app/logs/transactions.log 16 | log4j.appender.file.Append=false 17 | log4j.appender.file.ImmediateFlush=true 18 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 19 | log4j.appender.file.layout.ConversionPattern=%-5p %d [%t] %c(%M)\: %m%n -------------------------------------------------------------------------------- /book-code-master/java/oanda-historic-transactions/src/main/resources/oanda-transactions.properties: -------------------------------------------------------------------------------- 1 | oanda.url=https://api-fxtrade.oanda.com 2 | oanda.accessToken=******************************** 3 | oanda.userName=****** 4 | oanda.accountId=****** 5 | jdbc.driverClassName=com.mysql.jdbc.Driver 6 | jdbc.url=jdbc:mysql://localhost:3306/test 7 | jdbc.username=test 8 | jdbc.password=test 9 | hibernate.dialect=org.hibernate.dialect.MySQLDialect 10 | hibernate.show_sql=true 11 | hibernate.format_sql=true 12 | hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory 13 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | oanda-restapi 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | 36 | 37 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding//src/test/resources=UTF-8 6 | encoding/=UTF-8 7 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.source=1.8 14 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.precioustech 6 | oanda-restapi 7 | 1.0 8 | jar 9 | 10 | oanda-restapi 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 1.1.1 16 | 1.8 17 | 18 | 19 | 20 | 21 | com.googlecode.json-simple 22 | json-simple 23 | ${json.simple.version} 24 | 25 | 26 | com.precioustech 27 | tradingbot-core 28 | 1.0 29 | 30 | 31 | junit 32 | junit 33 | 4.9 34 | test 35 | 36 | 37 | org.mockito 38 | mockito-core 39 | 1.9.5 40 | test 41 | 42 | 43 | 44 | install 45 | 46 | 47 | org.apache.maven.plugins 48 | maven-compiler-plugin 49 | 50 | ${jdk.version} 51 | ${jdk.version} 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/main/java/com/precioustech/fxtrading/oanda/restapi/events/AccountEventPayLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi.events; 17 | 18 | import org.json.simple.JSONObject; 19 | 20 | import com.precioustech.fxtrading.events.EventPayLoad; 21 | 22 | public class AccountEventPayLoad extends EventPayLoad { 23 | 24 | public AccountEventPayLoad(AccountEvents event, JSONObject payLoad) { 25 | super(event, payLoad); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/main/java/com/precioustech/fxtrading/oanda/restapi/events/AccountEvents.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi.events; 17 | 18 | import com.precioustech.fxtrading.events.Event; 19 | 20 | public enum AccountEvents implements Event { 21 | MARGIN_CALL_ENTER, MARGIN_CALL_EXIT, MARGIN_CLOSEOUT, SET_MARGIN_RATE, TRANSFER_FUNDS, DAILY_INTEREST, FEE; 22 | } 23 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/main/java/com/precioustech/fxtrading/oanda/restapi/events/OrderEventPayLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi.events; 17 | 18 | import org.json.simple.JSONObject; 19 | 20 | import com.precioustech.fxtrading.events.EventPayLoad; 21 | 22 | public class OrderEventPayLoad extends EventPayLoad { 23 | 24 | private final OrderEvents orderEvent; 25 | 26 | public OrderEventPayLoad(OrderEvents event, JSONObject payLoad) { 27 | super(event, payLoad); 28 | this.orderEvent = event; 29 | } 30 | 31 | @Override 32 | public OrderEvents getEvent() { 33 | return this.orderEvent; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/main/java/com/precioustech/fxtrading/oanda/restapi/events/OrderEvents.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi.events; 17 | 18 | import com.precioustech.fxtrading.events.Event; 19 | 20 | public enum OrderEvents implements Event { 21 | MARKET_ORDER_CREATE, 22 | STOP_ORDER_CREATE, 23 | LIMIT_ORDER_CREATE, 24 | MARKET_IF_TOUCHED_ORDER_CREATE, 25 | ORDER_UPDATE, 26 | ORDER_CANCEL, 27 | ORDER_FILLED; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/main/java/com/precioustech/fxtrading/oanda/restapi/events/OrderPayLoadToTweet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi.events; 17 | 18 | import java.util.Set; 19 | 20 | import org.json.simple.JSONObject; 21 | 22 | import com.google.common.collect.Sets; 23 | import com.precioustech.fxtrading.TradingSignal; 24 | import com.precioustech.fxtrading.events.EventPayLoadToTweet; 25 | import com.precioustech.fxtrading.oanda.restapi.OandaJsonKeys; 26 | import com.precioustech.fxtrading.oanda.restapi.utils.OandaUtils; 27 | 28 | public class OrderPayLoadToTweet implements EventPayLoadToTweet { 29 | 30 | private final Set orderEventsSupported = Sets.newHashSet(OrderEvents.ORDER_FILLED, 31 | OrderEvents.LIMIT_ORDER_CREATE); 32 | 33 | @Override 34 | public String toTweet(OrderEventPayLoad payLoad) { 35 | if (!orderEventsSupported.contains(payLoad.getEvent())) { 36 | return null; 37 | } 38 | final JSONObject jsonPayLoad = payLoad.getPayLoad(); 39 | final String instrument = jsonPayLoad.get(OandaJsonKeys.instrument).toString(); 40 | 41 | final String instrumentAsHashtag = OandaUtils.oandaToHashTagCcy(instrument); 42 | final long tradeUnits = (Long) jsonPayLoad.get(OandaJsonKeys.units); 43 | final double price = ((Number) jsonPayLoad.get(OandaJsonKeys.price)).doubleValue(); 44 | final String side = jsonPayLoad.get(OandaJsonKeys.side).toString(); 45 | TradingSignal signal = OandaUtils.toTradingSignal(side); 46 | 47 | switch (payLoad.getEvent()) { 48 | case ORDER_FILLED: 49 | return String.format("Opened %s position of %d units for %s@%2.5f", signal.name(), tradeUnits, 50 | instrumentAsHashtag, price); 51 | case LIMIT_ORDER_CREATE: 52 | return String.format("%s LIMIT order of %d units for %s@%2.5f", signal.name(), tradeUnits, 53 | instrumentAsHashtag, price); 54 | default: 55 | return null; 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/main/java/com/precioustech/fxtrading/oanda/restapi/events/TradeEventPayLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi.events; 17 | 18 | import org.json.simple.JSONObject; 19 | 20 | import com.precioustech.fxtrading.events.EventPayLoad; 21 | 22 | public class TradeEventPayLoad extends EventPayLoad { 23 | 24 | public TradeEventPayLoad(TradeEvents event, JSONObject payLoad) { 25 | super(event, payLoad); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/main/java/com/precioustech/fxtrading/oanda/restapi/events/TradeEvents.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi.events; 17 | 18 | import com.precioustech.fxtrading.events.Event; 19 | 20 | public enum TradeEvents implements Event { 21 | TRADE_UPDATE, 22 | TRADE_CLOSE, 23 | MIGRATE_TRADE_OPEN, 24 | MIGRATE_TRADE_CLOSE, 25 | STOP_LOSS_FILLED, 26 | TAKE_PROFIT_FILLED, 27 | TRAILING_STOP_FILLED; 28 | } 29 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/main/java/com/precioustech/fxtrading/oanda/restapi/helper/OandaProviderHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi.helper; 17 | 18 | import com.precioustech.fxtrading.TradingConstants; 19 | import com.precioustech.fxtrading.helper.ProviderHelper; 20 | import com.precioustech.fxtrading.oanda.restapi.OandaConstants; 21 | import com.precioustech.fxtrading.oanda.restapi.utils.OandaUtils; 22 | import com.precioustech.fxtrading.utils.TradingUtils; 23 | 24 | public class OandaProviderHelper implements ProviderHelper { 25 | 26 | @Override 27 | public String fromIsoFormat(String instrument) { 28 | return OandaUtils.isoCcyToOandaCcy(instrument); 29 | } 30 | 31 | @Override 32 | public String fromPairSeparatorFormat(String instrument) { 33 | String[] pair = TradingUtils.splitInstrumentPair(instrument); 34 | return String.format("%s%s%s", pair[0], OandaConstants.CCY_PAIR_SEP, pair[1]); 35 | } 36 | 37 | @Override 38 | public String toIsoFormat(String instrument) { 39 | String tokens[] = TradingUtils.splitCcyPair(instrument, TradingConstants.CURRENCY_PAIR_SEP_UNDERSCORE); 40 | String isoInstrument = tokens[0] + tokens[1]; 41 | return isoInstrument; 42 | } 43 | 44 | @Override 45 | public String fromHashTagCurrency(String instrument) { 46 | return OandaUtils.hashTagCcyToOandaCcy(instrument); 47 | } 48 | 49 | @Override 50 | public String getLongNotation() { 51 | return OandaConstants.BUY; 52 | } 53 | 54 | @Override 55 | public String getShortNotation() { 56 | return OandaConstants.SELL; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/main/java/com/precioustech/fxtrading/oanda/restapi/marketdata/historic/OandaLimitExceededException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi.marketdata.historic; 17 | 18 | public class OandaLimitExceededException extends Exception { 19 | 20 | private static final long serialVersionUID = 2943484039263195666L; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | #Nike log4j log file 2 | 3 | log4j.rootLogger=INFO, stdout, file 4 | 5 | #stdout Log 6 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 7 | log4j.appender.stdout.Threshold=INFO 8 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] - %m%n 10 | 11 | #file Log 12 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 13 | log4j.appender.file.Threshold=INFO 14 | #log4j.appender.file.File=/home/a_nike/sv/logs/loader.log 15 | log4j.appender.file.File=/app/logs/trading.log 16 | log4j.appender.file.Append=true 17 | log4j.appender.file.ImmediateFlush=true 18 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 19 | log4j.appender.file.layout.ConversionPattern=%-5p %d [%t] %c(%M)\: %m%n -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/java/com/precioustech/fxtrading/oanda/restapi/OandaTestConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi; 17 | 18 | public class OandaTestConstants { 19 | 20 | private OandaTestConstants() { 21 | } 22 | 23 | public static final String url = "https://api-fxtrade.oanda.com"; 24 | public static final String streaming_url = "https://stream-fxtrade.oanda.com"; 25 | public static String userName = "testTrader"; 26 | public static String accessToken = "foobar"; 27 | public static Long accountId = 123456L; 28 | public static Long accountId2 = 234567L; 29 | public static Long tradeId = 1800805337L; 30 | public static Long orderId = 1001L; 31 | public static Long transactionId = 1800806000L; 32 | public static double precision = 0.0001; 33 | } 34 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/java/com/precioustech/fxtrading/oanda/restapi/OandaTestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi; 17 | 18 | import static org.mockito.Matchers.any; 19 | import static org.mockito.Mockito.mock; 20 | import static org.mockito.Mockito.when; 21 | 22 | import java.io.FileInputStream; 23 | 24 | import org.apache.http.HttpEntity; 25 | import org.apache.http.HttpStatus; 26 | import org.apache.http.StatusLine; 27 | import org.apache.http.client.HttpClient; 28 | import org.apache.http.client.methods.CloseableHttpResponse; 29 | import org.apache.http.client.methods.HttpUriRequest; 30 | 31 | public class OandaTestUtils { 32 | private OandaTestUtils() { 33 | 34 | } 35 | 36 | public static final void mockHttpInteraction(String fname, HttpClient mockHttpClient) throws Exception { 37 | CloseableHttpResponse mockResp = mock(CloseableHttpResponse.class); 38 | when(mockHttpClient.execute(any(HttpUriRequest.class))).thenReturn(mockResp); 39 | 40 | HttpEntity mockEntity = mock(HttpEntity.class); 41 | 42 | when(mockResp.getEntity()).thenReturn(mockEntity); 43 | 44 | StatusLine mockStatusLine = mock(StatusLine.class); 45 | 46 | when(mockResp.getStatusLine()).thenReturn(mockStatusLine); 47 | when(mockStatusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK); 48 | when(mockEntity.getContent()).thenReturn(new FileInputStream(fname)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/java/com/precioustech/fxtrading/oanda/restapi/events/OrderPayLoadToTweetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi.events; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import static org.junit.Assert.assertNotNull; 20 | import static org.junit.Assert.assertNull; 21 | import static org.mockito.Mockito.mock; 22 | import static org.mockito.Mockito.when; 23 | 24 | import org.json.simple.JSONObject; 25 | import org.junit.Test; 26 | 27 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 28 | import com.precioustech.fxtrading.oanda.restapi.OandaJsonKeys; 29 | 30 | public class OrderPayLoadToTweetTest { 31 | 32 | @Test 33 | public void payLoadToTweet() { 34 | OrderPayLoadToTweet payLoadToTweet = new OrderPayLoadToTweet(); 35 | JSONObject jsonPayLoad = mock(JSONObject.class); 36 | 37 | TradeableInstrument eurchf = new TradeableInstrument("EUR_CHF"); 38 | // TradeEventPayLoad payLoad = new 39 | // TradeEventPayLoad(TradeEvents.TAKE_PROFIT_FILLED, jsonPayLoad); 40 | when(jsonPayLoad.get(OandaJsonKeys.instrument)).thenReturn(eurchf.getInstrument()); 41 | when(jsonPayLoad.get(OandaJsonKeys.units)).thenReturn(200l); 42 | when(jsonPayLoad.get(OandaJsonKeys.price)).thenReturn(1.10325); 43 | when(jsonPayLoad.get(OandaJsonKeys.side)).thenReturn("sell"); 44 | OrderEventPayLoad payLoad = new OrderEventPayLoad(OrderEvents.ORDER_FILLED, jsonPayLoad); 45 | String tweet = payLoadToTweet.toTweet(payLoad); 46 | assertNotNull(tweet); 47 | assertEquals("Opened SHORT position of 200 units for #EURCHF@1.10325", tweet); 48 | 49 | payLoad = new OrderEventPayLoad(OrderEvents.LIMIT_ORDER_CREATE, jsonPayLoad); 50 | tweet = payLoadToTweet.toTweet(payLoad); 51 | assertNotNull(tweet); 52 | assertEquals("SHORT LIMIT order of 200 units for #EURCHF@1.10325", tweet); 53 | 54 | payLoad = new OrderEventPayLoad(OrderEvents.ORDER_CANCEL, jsonPayLoad); 55 | tweet = payLoadToTweet.toTweet(payLoad); 56 | assertNull(tweet); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/java/com/precioustech/fxtrading/oanda/restapi/helper/OandaProviderHelperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.oanda.restapi.helper; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import org.junit.Test; 21 | 22 | import com.precioustech.fxtrading.helper.ProviderHelper; 23 | 24 | public class OandaProviderHelperTest { 25 | 26 | private final ProviderHelper providerHelper = new OandaProviderHelper(); 27 | 28 | @Test 29 | public void fromIsoFormatTest() { 30 | String currencyPair = providerHelper.fromIsoFormat("XAUUSD"); 31 | assertEquals("XAU_USD", currencyPair); 32 | } 33 | 34 | @Test 35 | public void fromPairSeparatorFormatTest() { 36 | assertEquals("GBP_NZD", this.providerHelper.fromPairSeparatorFormat("GBP/NZD")); 37 | } 38 | 39 | @Test 40 | public void toIsoFormatTest() { 41 | assertEquals("USDJPY", this.providerHelper.toIsoFormat("USD_JPY")); 42 | } 43 | 44 | @Test 45 | public void fromHashTagCurrencyTest() { 46 | assertEquals("AUD_USD", this.providerHelper.fromHashTagCurrency("#AUDUSD")); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/account123456.txt: -------------------------------------------------------------------------------- 1 | { 2 | "accountId" : 123456, 3 | "accountName" : "main", 4 | "balance" : 20567.9, 5 | "unrealizedPl" : -897.1, 6 | "realizedPl" : 1123.65, 7 | "marginUsed" : 89.98, 8 | "marginAvail" : 645.3, 9 | "openTrades" : 5, 10 | "openOrders" : 0, 11 | "marginRate" : 0.05, 12 | "accountCurrency" : "CHF" 13 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/accountsAll.txt: -------------------------------------------------------------------------------- 1 | { 2 | "accounts": [ 3 | { 4 | "accountId" : 1898212, 5 | "accountName" : "GreenBack", 6 | "accountCurrency" : "USD", 7 | "marginRate" : 0.05 8 | }, 9 | { 10 | "accountId" : 2093221, 11 | "accountName" : "Loonie", 12 | "accountCurrency" : "CAD", 13 | "marginRate" : 0.02 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/allOrders.txt: -------------------------------------------------------------------------------- 1 | { 2 | "orders": [ 3 | { 4 | "id": 1001, 5 | "instrument": "USD_CAD", 6 | "units": 100, 7 | "side": "buy", 8 | "type": "marketIfTouched", 9 | "time": "1444116207000000", 10 | "price": 1.3, 11 | "takeProfit": 1.31, 12 | "stopLoss": 1.2, 13 | "expiry": "1444721003000000", 14 | "upperBound": 0, 15 | "lowerBound": 0, 16 | "trailingStop": 0 17 | }, 18 | { 19 | "id": 1002, 20 | "instrument": "EUR_USD", 21 | "units": 150, 22 | "side": "buy", 23 | "type": "marketIfTouched", 24 | "time": "1444108460000000", 25 | "price": 1.115, 26 | "takeProfit": 0, 27 | "stopLoss": 0, 28 | "expiry": "1444713259000000", 29 | "upperBound": 0, 30 | "lowerBound": 0, 31 | "trailingStop": 0 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/candlesCountM.txt: -------------------------------------------------------------------------------- 1 | { 2 | "instrument": "GBP_USD", 3 | "granularity": "D", 4 | "candles": [ 5 | { 6 | "time": "1442098800000000", 7 | "openMid": 1.54301, 8 | "highMid": 1.544695, 9 | "lowMid": 1.54284, 10 | "closeMid": 1.544295, 11 | "volume": 868, 12 | "complete": true 13 | }, 14 | { 15 | "time": "1442185200000000", 16 | "openMid": 1.544245, 17 | "highMid": 1.54594, 18 | "lowMid": 1.54376, 19 | "closeMid": 1.54406, 20 | "volume": 3765, 21 | "complete": false 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/currentPrices.txt: -------------------------------------------------------------------------------- 1 | { 2 | "prices": [ 3 | { 4 | "instrument": "GBP_USD", 5 | "time": "1442216738184236", 6 | "bid": 1.54682, 7 | "ask": 1.547 8 | }, 9 | { 10 | "instrument": "GBP_CHF", 11 | "time": "1442216737600312", 12 | "bid": 1.50008, 13 | "ask": 1.50058 14 | }, 15 | { 16 | "instrument": "GBP_NZD", 17 | "time": "1442216738184363", 18 | "bid": 2.44355, 19 | "ask": 2.44473 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/events.txt: -------------------------------------------------------------------------------- 1 | {"heartbeat":{"time":"1443967961000000"}} 2 | {"heartbeat":{"time":"1443967981000000"}} 3 | {"heartbeat":{"time":"1443968001000000"}} 4 | {"heartbeat":{"time":"1443968021000000"}} 5 | {"transaction":{"id":10002,"accountId":123456,"time":"1443968041000000","type":"ORDER_FILLED","instrument":"EUR_USD","units":10,"side":"sell","price":1,"pl":1.234,"interest":0.034,"accountBalance":10000,"orderId":0,"tradeReduced":{"id":54321,"units":10,"pl":1.234,"interest":0.034}}} 6 | {"transaction":{"id":10003,"accountId":234567,"time":"1443968061000000","type":"TAKE_PROFIT_FILLED","tradeId":1800805337,"instrument":"USD_CHF","units":3000,"side":"sell","price":1.00877,"pl":3.48,"interest":0.0002,"accountBalance":5912.5829}} 7 | {"heartbeat":{"time":"1443968081000000"}} 8 | {"transaction":{"id":10004,"accountId":234567,"time":"1443968081000000","type":"STOP_LOSS_FILLED","tradeId":1782812741,"instrument":"USD_SGD","units":3000,"side":"sell","price":1.39101,"pl":3.3039,"interest":-0.0123,"accountBalance":5915.8745}} 9 | {"heartbeat":{"time":"1443968101000000"}} 10 | {"disconnect":{"code":64,"message":"bye","moreInfo":"none"}} -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/instruments.txt: -------------------------------------------------------------------------------- 1 | { 2 | "instruments": [ 3 | { 4 | "instrument": "AUD_CAD", 5 | "pip": "0.0001", 6 | "interestRate": { 7 | "AUD": { 8 | "bid": 0.0164, 9 | "ask": 0.0274 10 | }, 11 | "CAD": { 12 | "bid": 0.002, 13 | "ask": 0.008 14 | } 15 | } 16 | }, 17 | { 18 | "instrument": "AUD_CHF", 19 | "pip": "0.0001", 20 | "interestRate": { 21 | "AUD": { 22 | "bid": 0.0164, 23 | "ask": 0.0274 24 | }, 25 | "CHF": { 26 | "bid": -0.013, 27 | "ask": 0.003 28 | } 29 | } 30 | } 31 | ] 32 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/newOrder.txt: -------------------------------------------------------------------------------- 1 | { 2 | "instrument" : "EUR_JPY", 3 | "time" : "2015-09-22T20:36:06Z", 4 | "price" : 133.75, 5 | "tradeOpened" : { 6 | "id" : 175517237, 7 | "units" : 150, 8 | "side" : "sell", 9 | "takeProfit" : 132.65, 10 | "stopLoss" : 136.00, 11 | "trailingStop" : 133.75 12 | }, 13 | "tradesClosed" : [], 14 | "tradeReduced" : {} 15 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/newOrderLimit.txt: -------------------------------------------------------------------------------- 1 | { 2 | "instrument" : "EUR_USD", 3 | "time" : "2015-12-02T06:47:51.000000Z", 4 | "price" : 1.1, 5 | "orderOpened" : { 6 | "id" : 12211080075, 7 | "units" : 10, 8 | "side" : "sell", 9 | "takeProfit" : 1.09, 10 | "stopLoss" : 0, 11 | "expiry" : "2015-12-02T11:47:39.000000Z", 12 | "upperBound" : 0, 13 | "lowerBound" : 0, 14 | "trailingStop" : 0 15 | } 16 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/orderForAccount123456.txt: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1001, 3 | "instrument": "USD_JPY", 4 | "units": 125, 5 | "side": "sell", 6 | "type": "marketIfTouched", 7 | "time": "1444116207000000", 8 | "price": 122.15, 9 | "takeProfit": 119.25, 10 | "stopLoss": 125.00, 11 | "expiry": "1444721003000000", 12 | "upperBound": 0, 13 | "lowerBound": 0, 14 | "trailingStop": 0 15 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/positionForInstrument.txt: -------------------------------------------------------------------------------- 1 | { 2 | "side" : "buy", 3 | "instrument" : "GBP_CHF", 4 | "units" : 4516, 5 | "avgPrice" : 1.3093 6 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/positionsForAccount123456.txt: -------------------------------------------------------------------------------- 1 | { 2 | "positions" : [ 3 | { 4 | "instrument" : "EUR_USD", 5 | "units" : 6723, 6 | "side" : "sell", 7 | "avgPrice" : 1.2419 8 | }, 9 | { 10 | "instrument" : "GBP_USD", 11 | "units" : 3000, 12 | "side" : "sell", 13 | "avgPrice" : 1.5982 14 | }, 15 | { 16 | "instrument" : "USD_JPY", 17 | "units" : 2388, 18 | "side" : "buy", 19 | "avgPrice" : 112.455 20 | } 21 | { 22 | "instrument" : "EUR_CHF", 23 | "units" : 11020, 24 | "side" : "sell", 25 | "avgPrice" : 1.2306 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/trade1800805337ForAccount123456.txt: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1800805337, 3 | "units": 3000, 4 | "side": "sell", 5 | "instrument": "CHF_JPY", 6 | "time": "1426660416000000", 7 | "price": 120.521, 8 | "takeProfit": 105.521, 9 | "stopLoss": 121.521, 10 | "trailingStop": 0, 11 | "trailingAmount": 0 12 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/tradeModify.txt: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1800805337, 3 | "units": 3000, 4 | "side": "sell", 5 | "instrument": "CHF_JPY", 6 | "time": "2015-03-18T06:33:36.000000Z", 7 | "price": 120.521, 8 | "takeProfit": 110, 9 | "stopLoss": 150, 10 | "trailingStop": 0, 11 | "trailingAmount": 0 12 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/tradesForAccount123456.txt: -------------------------------------------------------------------------------- 1 | { 2 | "trades": [ 3 | { 4 | "id": 1800805337, 5 | "units": 3000, 6 | "side": "sell", 7 | "instrument": "CHF_JPY", 8 | "time": "1426660416000000", 9 | "price": 120.521, 10 | "takeProfit": 105.521, 11 | "stopLoss": 121.521, 12 | "trailingStop": 0, 13 | "trailingAmount": 0 14 | }, 15 | { 16 | "id": 1800511850, 17 | "units": 3000, 18 | "side": "buy", 19 | "instrument": "USD_CHF", 20 | "time": "1426260592000000", 21 | "price": 1.0098, 22 | "takeProfit": 1.15979, 23 | "stopLoss": 0.9854, 24 | "trailingStop": 0, 25 | "trailingAmount": 0 26 | }, 27 | ] 28 | } -------------------------------------------------------------------------------- /book-code-master/java/oanda-restapi/src/test/resources/transaction123456.txt: -------------------------------------------------------------------------------- 1 | { 2 | "id" : 1800806000, 3 | "accountId" : 123456, 4 | "time" : "1442216738184236", 5 | "type" : "TRADE_CLOSE", 6 | "instrument" : "EUR_CHF", 7 | "units" : 200, 8 | "side" : "sell", 9 | "price" : 1.10642, 10 | "pl" : 0.2538, 11 | "interest" : 0, 12 | "accountBalance" : 1345.89, 13 | "tradeId" : 1800805337 14 | } -------------------------------------------------------------------------------- /book-code-master/java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.springframework.samples 4 | oanda-historic-transactions 5 | 0.0.1-SNAPSHOT 6 | 7 | 8 | 9 | 10 | 1.6 11 | UTF-8 12 | UTF-8 13 | 14 | 15 | 3.2.3.RELEASE 16 | 17 | 18 | 4.2.1.Final 19 | 20 | 21 | 1.0.13 22 | 1.7.5 23 | 24 | 25 | 4.11 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.springframework 33 | spring-context 34 | ${spring-framework.version} 35 | 36 | 37 | org.springframework 38 | spring-tx 39 | ${spring-framework.version} 40 | 41 | 42 | 43 | 44 | org.slf4j 45 | slf4j-api 46 | ${slf4j.version} 47 | compile 48 | 49 | 50 | ch.qos.logback 51 | logback-classic 52 | ${logback.version} 53 | runtime 54 | 55 | 56 | 57 | 58 | org.hibernate 59 | hibernate-entitymanager 60 | ${hibernate.version} 61 | 62 | 63 | 64 | 65 | 66 | org.springframework 67 | spring-test 68 | ${spring-framework.version} 69 | test 70 | 71 | 72 | junit 73 | junit 74 | ${junit.version} 75 | test 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /book-code-master/java/runbot-oanda.bsh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd tradingbot-app 4 | mvn exec:java -Dexec.mainClass="com.precioustech.fxtrading.tradingbot.FXTradingBot" -Dexec.args="tradingbot-oanda.xml" 5 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | tradingbot-app 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.springframework.ide.eclipse.core.springbuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.springframework.ide.eclipse.core.springnature 38 | org.eclipse.jdt.core.javanature 39 | org.eclipse.m2e.core.maven2Nature 40 | org.eclipse.wst.common.project.facet.core.nature 41 | 42 | 43 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/java/com/precioustech/fxtrading/tradingbot/FXTradingBot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.tradingbot; 17 | 18 | import org.apache.log4j.Logger; 19 | import org.springframework.context.ApplicationContext; 20 | import org.springframework.context.support.ClassPathXmlApplicationContext; 21 | 22 | import com.precioustech.fxtrading.streaming.events.EventsStreamingService; 23 | import com.precioustech.fxtrading.streaming.marketdata.MarketDataStreamingService; 24 | 25 | public class FXTradingBot { 26 | 27 | private static final Logger LOG = Logger.getLogger(FXTradingBot.class); 28 | 29 | @SuppressWarnings("resource") 30 | public static void main(String[] args) { 31 | if (args.length == 0) { 32 | LOG.fatal("Usage: FxTradingBot "); 33 | System.exit(1); 34 | } 35 | ApplicationContext appContext = new ClassPathXmlApplicationContext("tradingbot-app.xml", args[0]); 36 | 37 | MarketDataStreamingService marketDataStreamingService = appContext.getBean(MarketDataStreamingService.class); 38 | marketDataStreamingService.startMarketDataStreaming(); 39 | EventsStreamingService eventStreamingService = appContext.getBean(EventsStreamingService.class); 40 | eventStreamingService.startEventsStreaming(); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/java/com/precioustech/fxtrading/tradingbot/TradingConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.tradingbot; 17 | 18 | import com.precioustech.fxtrading.BaseTradingConfig; 19 | 20 | public class TradingConfig extends BaseTradingConfig { 21 | 22 | private String mailTo; 23 | private int fadeTheMoveJumpReqdToTrade; 24 | private int fadeTheMoveDistanceToTrade; 25 | private int fadeTheMovePipsDesired; 26 | private int fadeTheMovePriceExpiry; 27 | 28 | public int getFadeTheMovePriceExpiry() { 29 | return fadeTheMovePriceExpiry; 30 | } 31 | 32 | public void setFadeTheMovePriceExpiry(int fadeTheMovePriceExpiry) { 33 | this.fadeTheMovePriceExpiry = fadeTheMovePriceExpiry; 34 | } 35 | 36 | public String getMailTo() { 37 | return mailTo; 38 | } 39 | 40 | public void setMailTo(String mailTo) { 41 | this.mailTo = mailTo; 42 | } 43 | 44 | public int getFadeTheMoveJumpReqdToTrade() { 45 | return fadeTheMoveJumpReqdToTrade; 46 | } 47 | 48 | public void setFadeTheMoveJumpReqdToTrade(int fadeTheMoveJumpReqdToTrade) { 49 | this.fadeTheMoveJumpReqdToTrade = fadeTheMoveJumpReqdToTrade; 50 | } 51 | 52 | public int getFadeTheMoveDistanceToTrade() { 53 | return fadeTheMoveDistanceToTrade; 54 | } 55 | 56 | public void setFadeTheMoveDistanceToTrade(int fadeTheMoveDistanceToTrade) { 57 | this.fadeTheMoveDistanceToTrade = fadeTheMoveDistanceToTrade; 58 | } 59 | 60 | public int getFadeTheMovePipsDesired() { 61 | return fadeTheMovePipsDesired; 62 | } 63 | 64 | public void setFadeTheMovePipsDesired(int fadeTheMovePipsDesired) { 65 | this.fadeTheMovePipsDesired = fadeTheMovePipsDesired; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/java/com/precioustech/fxtrading/tradingbot/events/notification/email/EventEmailNotifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.tradingbot.events.notification.email; 17 | 18 | import java.util.Map; 19 | 20 | import javax.annotation.Resource; 21 | 22 | import org.apache.log4j.Logger; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.mail.SimpleMailMessage; 25 | import org.springframework.mail.javamail.JavaMailSender; 26 | 27 | import com.google.common.base.Preconditions; 28 | import com.google.common.eventbus.AllowConcurrentEvents; 29 | import com.google.common.eventbus.Subscribe; 30 | import com.precioustech.fxtrading.events.Event; 31 | import com.precioustech.fxtrading.events.EventPayLoad; 32 | import com.precioustech.fxtrading.events.notification.email.EmailContentGenerator; 33 | import com.precioustech.fxtrading.events.notification.email.EmailPayLoad; 34 | import com.precioustech.fxtrading.tradingbot.TradingConfig; 35 | 36 | public class EventEmailNotifier { 37 | 38 | private static final Logger LOG = Logger.getLogger(EventEmailNotifier.class); 39 | 40 | @Autowired 41 | JavaMailSender mailSender; 42 | @Resource 43 | Map> eventEmailContentGeneratorMap; 44 | @Autowired 45 | TradingConfig tradingConfig; 46 | 47 | @Subscribe 48 | @AllowConcurrentEvents 49 | public void notifyByEmail(EventPayLoad payLoad) { 50 | Preconditions.checkNotNull(payLoad); 51 | EmailContentGenerator emailContentGenerator = eventEmailContentGeneratorMap.get(payLoad.getEvent()); 52 | if (emailContentGenerator != null) { 53 | EmailPayLoad emailPayLoad = emailContentGenerator.generate(payLoad); 54 | SimpleMailMessage msg = new SimpleMailMessage(); 55 | msg.setSubject(emailPayLoad.getSubject()); 56 | msg.setTo(tradingConfig.getMailTo()); 57 | msg.setText(emailPayLoad.getBody()); 58 | this.mailSender.send(msg); 59 | } else { 60 | LOG.warn("No email content generator found for event:" + payLoad.getEvent().name()); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/java/com/precioustech/fxtrading/tradingbot/social/twitter/CloseFXTradeTweet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.tradingbot.social.twitter; 17 | 18 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 19 | 20 | public class CloseFXTradeTweet extends FXTradeTweet { 21 | private final double profit, price; 22 | 23 | public CloseFXTradeTweet(TradeableInstrument instrument, double profit, double price) { 24 | super(instrument, price); 25 | this.profit = profit; 26 | this.price = price; 27 | } 28 | 29 | public double getProfit() { 30 | return profit; 31 | } 32 | 33 | @Override 34 | public double getPrice() { 35 | return price; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/java/com/precioustech/fxtrading/tradingbot/social/twitter/FXTradeTweet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.tradingbot.social.twitter; 17 | 18 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 19 | 20 | public abstract class FXTradeTweet { 21 | private final TradeableInstrument instrument; 22 | private final double price; 23 | 24 | public FXTradeTweet(TradeableInstrument instrument, double price) { 25 | super(); 26 | this.instrument = instrument; 27 | this.price = price; 28 | } 29 | 30 | public TradeableInstrument getInstrument() { 31 | return instrument; 32 | } 33 | 34 | public double getPrice() { 35 | return price; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/java/com/precioustech/fxtrading/tradingbot/social/twitter/NewFXTradeTweet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.tradingbot.social.twitter; 17 | 18 | import com.precioustech.fxtrading.TradingSignal; 19 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 20 | 21 | public class NewFXTradeTweet extends FXTradeTweet { 22 | private final double stopLoss, takeProfit; 23 | private final TradingSignal action; 24 | private final String str; 25 | 26 | public NewFXTradeTweet(TradeableInstrument instrument, double price, double stopLoss, double takeProfit, 27 | TradingSignal action) { 28 | super(instrument, price); 29 | this.stopLoss = stopLoss; 30 | this.takeProfit = takeProfit; 31 | this.action = action; 32 | this.str = String.format("%s@%3.5f TP: %3.5f: SL: %3.5f %s", instrument.getInstrument(), price, takeProfit, 33 | stopLoss, action.name()); 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return str; 39 | } 40 | 41 | public TradingSignal getAction() { 42 | return this.action; 43 | } 44 | 45 | public double getStopLoss() { 46 | return stopLoss; 47 | } 48 | 49 | public double getTakeProfit() { 50 | return takeProfit; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/java/com/precioustech/fxtrading/tradingbot/social/twitter/tweethandler/FXTweetHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.tradingbot.social.twitter.tweethandler; 17 | 18 | import java.util.Collection; 19 | 20 | import org.springframework.social.twitter.api.Tweet; 21 | 22 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 23 | import com.precioustech.fxtrading.tradingbot.social.twitter.FXTradeTweet; 24 | 25 | 26 | public interface FXTweetHandler { 27 | 28 | FXTradeTweet handleTweet(Tweet tweet); 29 | 30 | String getUserId(); 31 | 32 | Collection findNewTweets(); 33 | 34 | Collection findHistoricPnlTweetsForInstrument(TradeableInstrument instrument); 35 | } 36 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/java/com/precioustech/fxtrading/tradingbot/social/twitter/tweethandler/TweetFXTradeService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.tradingbot.social.twitter.tweethandler; 17 | 18 | import java.util.Map; 19 | 20 | import javax.annotation.Resource; 21 | 22 | import org.apache.log4j.Logger; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.social.twitter.api.Twitter; 25 | 26 | import com.google.common.eventbus.AllowConcurrentEvents; 27 | import com.google.common.eventbus.Subscribe; 28 | import com.precioustech.fxtrading.events.Event; 29 | import com.precioustech.fxtrading.events.EventPayLoad; 30 | import com.precioustech.fxtrading.events.EventPayLoadToTweet; 31 | 32 | public class TweetFXTradeService> { 33 | 34 | private static final Logger LOG = Logger.getLogger(TweetFXTradeService.class); 35 | 36 | @Autowired 37 | Twitter twitter; 38 | 39 | @Resource 40 | Map> eventPayLoadToTweetMap; 41 | 42 | 43 | @Subscribe 44 | @AllowConcurrentEvents 45 | public void handleEvent(T payLoad) { 46 | EventPayLoadToTweet eventPayLoadToTweet = this.eventPayLoadToTweetMap.get(payLoad.getEvent()); 47 | if (eventPayLoadToTweet != null) { 48 | try { 49 | String tweet = eventPayLoadToTweet.toTweet(payLoad); 50 | if (tweet != null) { 51 | twitter.timelineOperations().updateStatus(tweet); 52 | } 53 | } catch (Exception ex) { 54 | LOG.error("error encountered whilst handling payload->" + payLoad.getPayLoad(), ex); 55 | } 56 | } 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/java/com/precioustech/fxtrading/tradingbot/social/twitter/tweethandler/TweetHarvester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.tradingbot.social.twitter.tweethandler; 17 | 18 | import java.util.Collection; 19 | 20 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 21 | import com.precioustech.fxtrading.tradingbot.social.twitter.CloseFXTradeTweet; 22 | import com.precioustech.fxtrading.tradingbot.social.twitter.NewFXTradeTweet; 23 | 24 | public interface TweetHarvester { 25 | 26 | Collection> harvestNewTradeTweets(String userId); 27 | 28 | Collection> harvestHistoricTradeTweets(String userId, TradeableInstrument instrument); 29 | } 30 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/java/com/precioustech/fxtrading/tradingbot/spring/FindEventBusSubscribers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.tradingbot.spring; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | import org.apache.log4j.Logger; 21 | import org.springframework.beans.BeansException; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.beans.factory.config.BeanPostProcessor; 24 | 25 | import com.google.common.eventbus.EventBus; 26 | import com.google.common.eventbus.Subscribe; 27 | 28 | public class FindEventBusSubscribers implements BeanPostProcessor { 29 | 30 | @Autowired 31 | private EventBus eventBus; 32 | private static final Logger LOG = Logger.getLogger(FindEventBusSubscribers.class); 33 | 34 | @Override 35 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 36 | return bean; 37 | } 38 | 39 | @Override 40 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 41 | Method[] beanMethods = bean.getClass().getMethods(); 42 | for (Method beanMethod : beanMethods) { 43 | if (beanMethod.isAnnotationPresent(Subscribe.class)) { 44 | eventBus.register(bean); 45 | LOG.info(String.format("Found event bus subscriber class %s. Subscriber method name=%s", bean 46 | .getClass().getSimpleName(), beanMethod.getName())); 47 | break; 48 | } 49 | } 50 | return bean; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | #Nike log4j log file 2 | 3 | log4j.rootLogger=INFO, stdout, file 4 | 5 | #stdout Log 6 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 7 | log4j.appender.stdout.Threshold=INFO 8 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] - %m%n 10 | 11 | #file Log 12 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 13 | log4j.appender.file.Threshold=INFO 14 | #log4j.appender.file.File=/home/a_nike/sv/logs/loader.log 15 | log4j.appender.file.File=/app/logs/trading.log 16 | log4j.appender.file.Append=true 17 | log4j.appender.file.ImmediateFlush=true 18 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 19 | log4j.appender.file.layout.ConversionPattern=%-5p %d [%t] %c(%M)\: %m%n -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/resources/tradingbot-oanda-test.properties: -------------------------------------------------------------------------------- 1 | oanda.url=https://api-fxpractice.oanda.com 2 | oanda.accessToken=49ad84f44e8d799d6cf4bd0509a7ead0-a234c6d0368a71a385cf2e4bfe82e302 3 | oanda.userName=svarshney 4 | oanda.accountId=3508556 5 | oanda.streaming.url=https://stream-fxpractice.oanda.com/ -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/resources/tradingbot-oanda.properties: -------------------------------------------------------------------------------- 1 | oanda.url=https://api-fxtrade.oanda.com 2 | oanda.accessToken=9d123c8312f25d9f5a094e53a123456b-2c9a7b12345678e177210af8e111c2f6 3 | oanda.userName=foobar 4 | oanda.accountId=123456 5 | oanda.streaming.url=https://stream-fxtrade.oanda.com -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/main/resources/tradingbot.properties: -------------------------------------------------------------------------------- 1 | mail.to=shekhar.varshney@gmail.com 2 | mail.host=smtp.gmail.com 3 | mail.port=465 4 | mail.user=lmaxtraderbot@gmail.com 5 | mail.password=lmaxtraderbot12 6 | twitter.consumerKey=fnV0TsPaWZhKUnNtn9NvHg 7 | twitter.consumerSecret=wd5bEegkcJtzYNJD34Mr9Pf0HMk6koynoluuwkmFPY 8 | twitter.accessToken=1318109634-nHkatlbQC7XmKTDt0ap7YCeLsBT2iwDfDARDspp 9 | twitter.accessTokenSecret=dSKwjSLRAhKANDrpIAs9cdkuRqV8XwAIPX9Y0Eo -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-app/src/test/java/com/precioustech/fxtrading/tradingbot/TradingAppTestConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.tradingbot; 17 | 18 | public class TradingAppTestConstants { 19 | 20 | public static double precision = 0.0001; 21 | } 22 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | tradingbot-core 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | 36 | 37 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | encoding//src/test/resources=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/BaseTradingConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading; 17 | 18 | public class BaseTradingConfig { 19 | private double minReserveRatio; 20 | private double minAmountRequired; 21 | 22 | private int maxAllowedQuantity; 23 | private int maxAllowedNetContracts; 24 | private double max10yrWmaOffset; 25 | 26 | public double getMinAmountRequired() { 27 | return minAmountRequired; 28 | } 29 | 30 | public void setMinAmountRequired(double minAmountRequired) { 31 | this.minAmountRequired = minAmountRequired; 32 | } 33 | 34 | public double getMax10yrWmaOffset() { 35 | return max10yrWmaOffset; 36 | } 37 | 38 | public void setMax10yrWmaOffset(double max10yrWmaOffset) { 39 | this.max10yrWmaOffset = max10yrWmaOffset; 40 | } 41 | 42 | public int getMaxAllowedNetContracts() { 43 | return maxAllowedNetContracts; 44 | } 45 | 46 | public void setMaxAllowedNetContracts(int maxAllowedNetContracts) { 47 | this.maxAllowedNetContracts = maxAllowedNetContracts; 48 | } 49 | 50 | public double getMinReserveRatio() { 51 | return minReserveRatio; 52 | } 53 | 54 | public void setMinReserveRatio(double minReserveRatio) { 55 | this.minReserveRatio = minReserveRatio; 56 | } 57 | 58 | public int getMaxAllowedQuantity() { 59 | return maxAllowedQuantity; 60 | } 61 | 62 | public void setMaxAllowedQuantity(int maxAllowedQuantity) { 63 | this.maxAllowedQuantity = maxAllowedQuantity; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/TradingConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading; 17 | 18 | public class TradingConstants { 19 | private TradingConstants() { 20 | } 21 | 22 | public static final String HASHTAG = "#"; 23 | public static final String COMMA = ","; 24 | public static final double PI_IN_DEGREES = 180.0; 25 | public static final String FWD_SLASH = "/"; 26 | public static final String ENCODED_COMMA = "%2C"; 27 | public static final String SPACE_RGX = "\\s+"; 28 | public static final String PIPE_CHR = "|"; 29 | public static final String CURRENCY_PAIR_SEP_UNDERSCORE = "_"; 30 | public static final String COLON = ":"; 31 | } 32 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/TradingSignal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading; 17 | 18 | public enum TradingSignal { 19 | LONG, SHORT, NONE; 20 | 21 | public TradingSignal flip() { 22 | switch (this) { 23 | case LONG: 24 | return SHORT; 25 | case SHORT: 26 | return LONG; 27 | default: 28 | return this; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/account/AccountDataProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.account; 17 | 18 | import java.util.Collection; 19 | 20 | /** 21 | * A provider of Account information. An account information might typically 22 | * include base currency, leverage, margin available, PNL information etc. Some 23 | * brokerages allow the creation of various sub accounts or currency wallets. 24 | * The idea is to give ability to fund these accounts from various currency 25 | * denominated bank accounts. So for e.g. a user in Switzerland might have a CHF 26 | * current account but also a EUR savings account. One can then open 2 currency 27 | * accounts or wallets on the brokerage, denominated in CHF and EUR and these 28 | * can then be funded by the real bank accounts. Alternatively, one can also 29 | * just create these multiple currency wallets even if they have just a single 30 | * source funding currency. When the primary account is funded, a transfer trade 31 | * can be executed to fund the other currency wallet. For e.g. a user in United 32 | * Kingdom who just has a GBP account, can open a USD wallet, fund the GBP 33 | * account and then execute a transfer of a given units of GBP into USD. 34 | * 35 | * @author Shekhar Varshney 36 | * 37 | * @param 38 | * The type of accountId 39 | * 40 | * @see Account 41 | */ 42 | public interface AccountDataProvider { 43 | 44 | /** 45 | * 46 | * @param accountId 47 | * @return Account information for the given accountId 48 | */ 49 | Account getLatestAccountInfo(T accountId); 50 | 51 | /** 52 | * 53 | * @return A collection of ALL accounts available 54 | */ 55 | Collection> getLatestAccountInfo(); 56 | } 57 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/account/transaction/TransactionDataProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.account.transaction; 17 | 18 | import java.util.List; 19 | 20 | public interface TransactionDataProvider { 21 | 22 | Transaction getTransaction(M transactionId, N accountId); 23 | 24 | List> getTransactionsGreaterThanId(M minTransactionId, N accountId); 25 | } 26 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/events/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.events; 17 | 18 | public interface Event { 19 | 20 | String name(); 21 | } 22 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/events/EventCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.events; 17 | 18 | public interface EventCallback { 19 | 20 | void onEvent(EventPayLoad eventPayLoad); 21 | } 22 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/events/EventCallbackImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.events; 17 | 18 | import com.google.common.eventbus.EventBus; 19 | 20 | public class EventCallbackImpl implements EventCallback { 21 | 22 | private final EventBus eventBus; 23 | 24 | public EventCallbackImpl(final EventBus eventBus) { 25 | this.eventBus = eventBus; 26 | } 27 | 28 | @Override 29 | public void onEvent(EventPayLoad eventPayLoad) { 30 | this.eventBus.post(eventPayLoad); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/events/EventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.events; 17 | 18 | public interface EventHandler> { 19 | 20 | void handleEvent(T payLoad); 21 | } 22 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/events/EventPayLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.events; 17 | 18 | public class EventPayLoad { 19 | 20 | private final Event event; 21 | private final T payLoad; 22 | 23 | public EventPayLoad(Event event, T payLoad) { 24 | this.event = event; 25 | this.payLoad = payLoad; 26 | } 27 | 28 | public Event getEvent() { 29 | return this.event; 30 | } 31 | 32 | public T getPayLoad() { 33 | return this.payLoad; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/events/EventPayLoadToTweet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.events; 17 | 18 | 19 | public interface EventPayLoadToTweet> { 20 | 21 | String toTweet(T payLoad); 22 | } 23 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/events/notification/email/EmailContentGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.events.notification.email; 17 | 18 | import com.precioustech.fxtrading.events.EventPayLoad; 19 | 20 | public interface EmailContentGenerator { 21 | 22 | EmailPayLoad generate(EventPayLoad payLoad); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/events/notification/email/EmailPayLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.events.notification.email; 17 | 18 | public class EmailPayLoad { 19 | private final String subject; 20 | private final String body; 21 | 22 | public EmailPayLoad(String subject, String body) { 23 | super(); 24 | this.subject = subject; 25 | this.body = body; 26 | } 27 | 28 | public String getSubject() { 29 | return subject; 30 | } 31 | 32 | public String getBody() { 33 | return body; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/heartbeats/DefaultHeartBeatService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.heartbeats; 17 | 18 | import java.util.Collection; 19 | 20 | import org.joda.time.DateTime; 21 | 22 | import com.precioustech.fxtrading.streaming.heartbeats.HeartBeatStreamingService; 23 | 24 | public class DefaultHeartBeatService extends AbstractHeartBeatService { 25 | 26 | public DefaultHeartBeatService(Collection heartBeatStreamingServices) { 27 | super(heartBeatStreamingServices); 28 | } 29 | 30 | @Override 31 | protected boolean isAlive(HeartBeatPayLoad payLoad) { 32 | return payLoad != null 33 | && (DateTime.now().getMillis() - payLoad.getHeartBeatPayLoad().getMillis()) < MAX_HEARTBEAT_DELAY; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/heartbeats/HeartBeatCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.heartbeats; 17 | 18 | public interface HeartBeatCallback { 19 | 20 | void onHeartBeat(HeartBeatPayLoad payLoad); 21 | } 22 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/heartbeats/HeartBeatCallbackImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.heartbeats; 17 | 18 | import com.google.common.eventbus.EventBus; 19 | 20 | public class HeartBeatCallbackImpl implements HeartBeatCallback { 21 | 22 | private final EventBus eventBus; 23 | 24 | public HeartBeatCallbackImpl(EventBus eventBus) { 25 | this.eventBus = eventBus; 26 | } 27 | 28 | @Override 29 | public void onHeartBeat(HeartBeatPayLoad payLoad) { 30 | this.eventBus.post(payLoad); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/heartbeats/HeartBeatPayLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.heartbeats; 17 | 18 | import org.apache.commons.lang3.StringUtils; 19 | 20 | public class HeartBeatPayLoad { 21 | 22 | private final T payLoad; 23 | private final String source; 24 | 25 | public HeartBeatPayLoad(T payLoad) { 26 | this(payLoad, StringUtils.EMPTY); 27 | } 28 | 29 | public HeartBeatPayLoad(T payLoad, String source) { 30 | this.payLoad = payLoad; 31 | this.source = source; 32 | } 33 | 34 | public T getHeartBeatPayLoad() { 35 | return this.payLoad; 36 | } 37 | 38 | public String getHeartBeatSource() { 39 | return this.source; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/helper/ProviderHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.helper; 17 | 18 | /** 19 | * 20 | * @param 21 | * The type of Long/Short notation 22 | */ 23 | public interface ProviderHelper { 24 | 25 | /** 26 | * 27 | * @param instrument 28 | * in ISO currency standard, such as GBPUSD 29 | * @return currency pair denoted in the platform specific format 30 | */ 31 | String fromIsoFormat(String instrument); 32 | 33 | /** 34 | * 35 | * @param instrument 36 | * in platform specific format such as GBP_USD 37 | * @return currency pair denoted in ISO format 38 | */ 39 | String toIsoFormat(String instrument); 40 | 41 | /** 42 | * 43 | * @param instrument 44 | * in a 7 character format, separated by an arbitrary separator 45 | * character like -,/,_ 46 | * @return currency pair denoted in the platform specific format 47 | */ 48 | String fromPairSeparatorFormat(String instrument); 49 | 50 | /** 51 | * 52 | * @param instrument 53 | * denoted as a hashtag, for e.g. #GBPUSD 54 | * @return currency pair denoted in the platform specific format 55 | */ 56 | String fromHashTagCurrency(String instrument); 57 | 58 | /** 59 | * 60 | * @return T that denotes the action of Buying the currency pair on the 61 | * platform 62 | */ 63 | T getLongNotation(); 64 | 65 | /** 66 | * 67 | * @return T that denotes the action of Selling the currency pair on the 68 | * platform 69 | */ 70 | T getShortNotation(); 71 | } 72 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/instrument/InstrumentDataProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.instrument; 17 | 18 | import java.util.Collection; 19 | 20 | /** 21 | * A provider of tradeable instrument data information. At the very minimum the 22 | * provider must provide the instrument name and pip value for each instrument. 23 | * Since the instrument data almost never changes during trading hours, it is 24 | * highly recommended that the data returned from this provider is cached in an 25 | * immutable collection. 26 | * 27 | * @author Shekhar Varshney 28 | * 29 | * @param The type of instrumentId in class TradeableInstrument 30 | * @see TradeableInstrument 31 | */ 32 | public interface InstrumentDataProvider { 33 | /** 34 | * 35 | * @return a collection of all TradeableInstrument available to trade on the 36 | * brokerage platform. 37 | */ 38 | Collection> getInstruments(); 39 | } 40 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/instrument/InstrumentPairInterestRate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.instrument; 17 | 18 | public class InstrumentPairInterestRate { 19 | 20 | private final Double baseCurrencyBidInterestRate; 21 | private final Double baseCurrencyAskInterestRate; 22 | private final Double quoteCurrencyBidInterestRate; 23 | private final Double quoteCurrencyAskInterestRate; 24 | 25 | public InstrumentPairInterestRate() { 26 | this(null, null, null, null); 27 | } 28 | 29 | public InstrumentPairInterestRate(Double baseCurrencyBidInterestRate, Double baseCurrencyAskInterestRate, 30 | Double quoteCurrencyBidInterestRate, Double quoteCurrencyAskInterestRate) { 31 | this.baseCurrencyBidInterestRate = baseCurrencyBidInterestRate; 32 | this.baseCurrencyAskInterestRate = baseCurrencyAskInterestRate; 33 | this.quoteCurrencyBidInterestRate = quoteCurrencyBidInterestRate; 34 | this.quoteCurrencyAskInterestRate = quoteCurrencyAskInterestRate; 35 | } 36 | 37 | public Double getBaseCurrencyBidInterestRate() { 38 | return baseCurrencyBidInterestRate; 39 | } 40 | 41 | public Double getBaseCurrencyAskInterestRate() { 42 | return baseCurrencyAskInterestRate; 43 | } 44 | 45 | public Double getQuoteCurrencyBidInterestRate() { 46 | return quoteCurrencyBidInterestRate; 47 | } 48 | 49 | public Double getQuoteCurrencyAskInterestRate() { 50 | return quoteCurrencyAskInterestRate; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "InstrumentPairInterestRate [baseCurrencyBidInterestRate=" + baseCurrencyBidInterestRate 56 | + ", baseCurrencyAskInterestRate=" + baseCurrencyAskInterestRate + ", quoteCurrencyBidInterestRate=" 57 | + quoteCurrencyBidInterestRate + ", quoteCurrencyAskInterestRate=" + quoteCurrencyAskInterestRate + "]"; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/instrument/economicevent/InstrumentEconomicEventImpact.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.instrument.economicevent; 2 | 3 | public enum InstrumentEconomicEventImpact { 4 | low, medium, high; 5 | } 6 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/marketdata/CurrentPriceInfoProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.marketdata; 17 | 18 | import java.util.Collection; 19 | import java.util.Map; 20 | 21 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 22 | 23 | public interface CurrentPriceInfoProvider { 24 | 25 | Map, Price> getCurrentPricesForInstruments(Collection> instruments); 26 | } 27 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/marketdata/MarketDataPayLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.marketdata; 17 | 18 | import org.joda.time.DateTime; 19 | 20 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 21 | 22 | public class MarketDataPayLoad { 23 | private final double bidPrice, askPrice; 24 | private final TradeableInstrument instrument; 25 | private final DateTime eventDate; 26 | 27 | public MarketDataPayLoad(TradeableInstrument instrument, double bidPrice, double askPrice, DateTime eventDate) { 28 | this.bidPrice = bidPrice; 29 | this.askPrice = askPrice; 30 | this.instrument = instrument; 31 | this.eventDate = eventDate; 32 | } 33 | 34 | public double getBidPrice() { 35 | return bidPrice; 36 | } 37 | 38 | public double getAskPrice() { 39 | return askPrice; 40 | } 41 | 42 | public TradeableInstrument getInstrument() { 43 | return instrument; 44 | } 45 | 46 | public DateTime getEventDate() { 47 | return eventDate; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/marketdata/MarketEventCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.marketdata; 17 | 18 | import org.joda.time.DateTime; 19 | 20 | import com.google.common.eventbus.EventBus; 21 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 22 | 23 | /** 24 | * A callback handler for a market data event. The separate streaming event 25 | * handler upstream, is responsible for handling and parsing the incoming event 26 | * from the market data source and invoke the onMarketEvent of this handler, 27 | * which in turn can disseminate the event if required, further downstream. 28 | * Ideally, the implementer of this interface, would drop the event on a queue 29 | * for asynchronous processing or use an event bus for synchronous processing. 30 | * 31 | * @author Shekhar Varshney 32 | * 33 | * @param 34 | * The type of instrumentId in class TradeableInstrument 35 | * @see TradeableInstrument 36 | * @see EventBus 37 | */ 38 | public interface MarketEventCallback { 39 | /** 40 | * A method, invoked by the upstream handler of streaming market data 41 | * events. This invocation of this method is synchronous, therefore the 42 | * method should return asap, to make sure that the upstream events do not 43 | * queue up. 44 | * 45 | * @param instrument 46 | * @param bid 47 | * @param ask 48 | * @param eventDate 49 | */ 50 | void onMarketEvent(TradeableInstrument instrument, double bid, double ask, DateTime eventDate); 51 | } 52 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/marketdata/MarketEventHandlerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.marketdata; 17 | 18 | import org.joda.time.DateTime; 19 | 20 | import com.google.common.eventbus.EventBus; 21 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 22 | 23 | public class MarketEventHandlerImpl implements MarketEventCallback { 24 | 25 | private final EventBus eventBus; 26 | 27 | public MarketEventHandlerImpl(EventBus eventBus) { 28 | this.eventBus = eventBus; 29 | } 30 | 31 | @Override 32 | public void onMarketEvent(TradeableInstrument instrument, double bid, double ask, DateTime eventDate) { 33 | MarketDataPayLoad payload = new MarketDataPayLoad(instrument, bid, ask, eventDate); 34 | eventBus.post(payload); 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/marketdata/PipJumpCutOffCalculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.marketdata; 17 | 18 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 19 | 20 | public interface PipJumpCutOffCalculator { 21 | 22 | Double calculatePipJumpCutOff(TradeableInstrument instrument); 23 | } 24 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/marketdata/Price.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.marketdata; 17 | 18 | import org.joda.time.DateTime; 19 | 20 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 21 | 22 | public class Price { 23 | private final TradeableInstrument instrument; 24 | private final double bidPrice, askPrice; 25 | private final DateTime pricePoint; 26 | 27 | public TradeableInstrument getInstrument() { 28 | return instrument; 29 | } 30 | 31 | public double getBidPrice() { 32 | return bidPrice; 33 | } 34 | 35 | public double getAskPrice() { 36 | return askPrice; 37 | } 38 | 39 | public DateTime getPricePoint() { 40 | return pricePoint; 41 | } 42 | 43 | public Price(TradeableInstrument instrument, double bidPrice, double askPrice, DateTime pricePoint) { 44 | this.instrument = instrument; 45 | this.bidPrice = bidPrice; 46 | this.askPrice = askPrice; 47 | this.pricePoint = pricePoint; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/marketdata/historic/CandleStickGranularity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.marketdata.historic; 17 | 18 | public enum CandleStickGranularity { 19 | 20 | S5(5, "5 seconds"), // 5s 21 | S10(10, "10 seconds"), // 10s 22 | S15(15, "15 seconds"), // 15s 23 | S30(30, "30 seconds"), // 30s 24 | M1(60 * 1, "1 minute"), // 1min 25 | M2(60 * 2, "2 minutes"), // 2mins 26 | M3(60 * 3, "3 minutes"), // 3mins 27 | M5(60 * 5, "5 minutes"), // 5mins 28 | M10(60 * 10, "10 minutes"), // 10mins 29 | M15(60 * 15, "15 minutes"), // 15mins 30 | M30(60 * 30, "30 minutes"), // 30mins 31 | H1(60 * 60, "1 hour"), // 1hr 32 | H2(60 * 60 * 2, "2 hours"), // 2hr 33 | H3(60 * 60 * 3, "3 hours"), // 3hr 34 | H4(60 * 60 * 4, "4 hours"), // 4hr 35 | H6(60 * 60 * 6, "6 hours"), // 6hr 36 | H8(60 * 60 * 8, "8 hours"), // 8hr 37 | H12(60 * 60 * 12, "12 hours"), // 12hr 38 | D(60 * 60 * 24, "1 day"), // 1day 39 | W(60 * 60 * 24 * 7, "1 week"), // 1wk 40 | M(60 * 60 * 24 * 30, "1 month");// 1mth 41 | 42 | private final long granularityInSeconds; 43 | private final String label; 44 | 45 | private CandleStickGranularity(long granularityInSeconds, String label) { 46 | this.granularityInSeconds = granularityInSeconds; 47 | this.label = label; 48 | } 49 | 50 | public long getGranularityInSeconds() { 51 | return granularityInSeconds; 52 | } 53 | 54 | public String getLabel() { 55 | return label; 56 | } 57 | 58 | public String getName() { 59 | return name(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/order/OrderInfoService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.order; 17 | 18 | import java.util.Collection; 19 | 20 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 21 | import com.precioustech.fxtrading.utils.TradingUtils; 22 | 23 | //TODO: introduce a cache like in TradeInfoService in order to avoid making expensive rest calls. 24 | public class OrderInfoService { 25 | 26 | private final OrderManagementProvider orderManagementProvider; 27 | 28 | public OrderInfoService(OrderManagementProvider orderManagementProvider) { 29 | this.orderManagementProvider = orderManagementProvider; 30 | } 31 | 32 | public Collection> allPendingOrders() { 33 | return this.orderManagementProvider.allPendingOrders(); 34 | } 35 | 36 | public Collection> pendingOrdersForAccount(K accountId) { 37 | return this.orderManagementProvider.pendingOrdersForAccount(accountId); 38 | } 39 | 40 | public Collection> pendingOrdersForInstrument(TradeableInstrument instrument) { 41 | return this.orderManagementProvider.pendingOrdersForInstrument(instrument); 42 | } 43 | 44 | public Order pendingOrderForAccount(M orderId, K accountId) { 45 | return this.orderManagementProvider.pendingOrderForAccount(orderId, accountId); 46 | } 47 | 48 | public int findNetPositionCountForCurrency(String currency) { 49 | Collection> allOrders = allPendingOrders(); 50 | int positionCount = 0; 51 | for (Order order : allOrders) { 52 | positionCount += TradingUtils.getSign(order.getInstrument().getInstrument(), order.getSide(), currency); 53 | } 54 | return positionCount; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/order/OrderType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.order; 17 | 18 | public enum OrderType { 19 | MARKET, LIMIT; 20 | } 21 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/position/Position.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.position; 17 | 18 | import com.precioustech.fxtrading.TradingSignal; 19 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 20 | 21 | public class Position { 22 | 23 | private final TradeableInstrument instrument; 24 | private final long units; 25 | private final TradingSignal side; 26 | private final double averagePrice; 27 | 28 | public Position(TradeableInstrument instrument, long units, TradingSignal side, double averagePrice) { 29 | this.instrument = instrument; 30 | this.units = units; 31 | this.side = side; 32 | this.averagePrice = averagePrice; 33 | } 34 | 35 | public TradeableInstrument getInstrument() { 36 | return instrument; 37 | } 38 | 39 | public long getUnits() { 40 | return units; 41 | } 42 | 43 | public TradingSignal getSide() { 44 | return side; 45 | } 46 | 47 | public double getAveragePrice() { 48 | return averagePrice; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/streaming/events/EventsStreamingService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.streaming.events; 17 | 18 | /** 19 | * A service that provides trade/order/account related events streaming. 20 | * Normally the implementation would create a dedicated connection to the 21 | * platform or register callback listener(s) to receive events. It is 22 | * recommended that the service delegate the handling of events to specific 23 | * handlers which can parse and make sense of the different plethora of events 24 | * received. 25 | * 26 | * @author Shekhar Varshney 27 | * 28 | */ 29 | public interface EventsStreamingService { 30 | 31 | /** 32 | * Start the streaming service which would ideally create a dedicated 33 | * connection to the platform or callback listener(s). Ideally multiple 34 | * connections requesting the same event types should not be created. 35 | */ 36 | void startEventsStreaming(); 37 | 38 | /** 39 | * Stop the events streaming services and dispose any resources/connections 40 | * in a suitable manner such that no resource leaks are created. 41 | */ 42 | void stopEventsStreaming(); 43 | } 44 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/streaming/heartbeats/HeartBeatStreamingService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.streaming.heartbeats; 17 | 18 | /** 19 | * A service that provides streaming heartbeats from the trading platform. The 20 | * service provided in the end by the platform may not be streaming at all but 21 | * some sort of regular callbacks in order to indicate that the connection is 22 | * alive. A loss of heartbeats may indicate a general failure to receive any 23 | * trade/order events and/or market data from the trading platform. Therefore 24 | * any monitoring of the application may involve directly interacting with this 25 | * service to raise alerts/notifications. 26 | * 27 | * @author Shekhar Varshney 28 | * 29 | */ 30 | public interface HeartBeatStreamingService { 31 | 32 | /** 33 | * Start the service in order to receive heartbeats from the trading 34 | * platform. Ideally the implementation would make sure that multiple 35 | * heartbeat connections/handlers are not created for the same kind of 36 | * service. Depending on the trading platform, there may be a single 37 | * heartbeat for all services or a dedicated one for services such as market 38 | * data, trade/order events etc. 39 | */ 40 | void startHeartBeatStreaming(); 41 | 42 | /** 43 | * Stop the service in order to stop receiving heartbeats. The 44 | * implementation must dispose any resources/connections in a suitable 45 | * manner so as not to cause any resource leaks. 46 | */ 47 | void stopHeartBeatStreaming(); 48 | 49 | /** 50 | * 51 | * @return heartBeat source id which identifies the source for which this 52 | * service is providing heartbeats. This is useful to keep track all 53 | * sources which are heartbeating and can be individually monitored 54 | * on a regular basis. On some platforms there may be a dedicated 55 | * single heartbeat service for ALL in which case this may not be as 56 | * useful. 57 | */ 58 | String getHeartBeatSourceId(); 59 | } 60 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/streaming/marketdata/MarketDataStreamingService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.streaming.marketdata; 17 | 18 | /** 19 | * A service that provides streaming market data. Normally the implementation 20 | * would create a dedicated connection to the trading platform and would receive 21 | * a stream of prices ideally through a REST service or a callback from the 22 | * platform. The implementation must handle broken connections and attempt to 23 | * reconnect in a suitable manner. The service is normally coupled with a 24 | * heartbeats from the platform which indicates whether the connection is alive 25 | * or not. 26 | * 27 | * Due to the volume of data expected, it is recommended that the service 28 | * delegate the handling of market data to another service in order to avoid 29 | * building up of queue of events, waiting to be processed. 30 | * 31 | * @author Shekhar Varshney 32 | * 33 | */ 34 | public interface MarketDataStreamingService { 35 | 36 | /** 37 | * Start the streaming service which would ideally create a dedicated 38 | * connection to the platform or a callback listener. Ideally multiple 39 | * connections requesting the same market data should not be created. 40 | */ 41 | void startMarketDataStreaming(); 42 | 43 | /** 44 | * Stop the streaming services and dispose any resources/connections in a 45 | * suitable manner such that no resource leaks are created. 46 | */ 47 | void stopMarketDataStreaming(); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/main/java/com/precioustech/fxtrading/trade/strategies/TradingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.trade.strategies; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | @Retention(RetentionPolicy.RUNTIME) 24 | @Target(ElementType.TYPE) 25 | public @interface TradingStrategy { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/test/java/com/precioustech/fxtrading/TradingTestConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading; 17 | 18 | public class TradingTestConstants { 19 | public static Long accountId = 123456L; 20 | public static Long accountId2 = 234567L; 21 | public static Long tradeId = 1800805337L; 22 | public static Long orderId = 1001L; 23 | public static double precision = 0.0001; 24 | } 25 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/test/java/com/precioustech/fxtrading/heartbeats/DefaultHeartBeatServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.heartbeats; 17 | 18 | import static org.mockito.Mockito.mock; 19 | import static org.mockito.Mockito.times; 20 | import static org.mockito.Mockito.verify; 21 | import static org.mockito.Mockito.when; 22 | 23 | import org.joda.time.DateTime; 24 | import org.junit.Test; 25 | 26 | import com.google.common.collect.Lists; 27 | import com.google.common.eventbus.EventBus; 28 | import com.precioustech.fxtrading.streaming.heartbeats.HeartBeatStreamingService; 29 | 30 | public class DefaultHeartBeatServiceTest { 31 | 32 | private final static String TESTSTREAM = "TESTSTREAM"; 33 | 34 | @Test 35 | public void heartBeatTest() throws Exception { 36 | HeartBeatStreamingService heartBeatStreamingService = mock(HeartBeatStreamingService.class); 37 | when(heartBeatStreamingService.getHeartBeatSourceId()).thenReturn(TESTSTREAM); 38 | DefaultHeartBeatService service = new DefaultHeartBeatService(Lists.newArrayList(heartBeatStreamingService)); 39 | service.warmUpTime = 1L; 40 | service.init(); 41 | EventBus eventBus = new EventBus(); 42 | eventBus.register(service); 43 | HeartBeatCallback heartBeatCallBack = new HeartBeatCallbackImpl(eventBus); 44 | DateTime now = DateTime.now(); 45 | HeartBeatPayLoad payload = new HeartBeatPayLoad(now.minusMinutes(2), TESTSTREAM); 46 | heartBeatCallBack.onHeartBeat(payload); 47 | verify(heartBeatStreamingService, times(1)).startHeartBeatStreaming(); 48 | heartBeatCallBack.onHeartBeat(new HeartBeatPayLoad(DateTime.now(), TESTSTREAM)); 49 | service.serviceUp = false; 50 | do { 51 | Thread.sleep(2L); 52 | } while (service.heartBeatsObserverThread.isAlive()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/test/java/com/precioustech/fxtrading/marketdata/MarketEventHandlerImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Shekhar Varshney 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.precioustech.fxtrading.marketdata; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import java.util.concurrent.CountDownLatch; 21 | import java.util.concurrent.Executors; 22 | 23 | import org.joda.time.DateTime; 24 | import org.junit.Test; 25 | 26 | import com.google.common.eventbus.AllowConcurrentEvents; 27 | import com.google.common.eventbus.AsyncEventBus; 28 | import com.google.common.eventbus.EventBus; 29 | import com.google.common.eventbus.Subscribe; 30 | import com.precioustech.fxtrading.TradingTestConstants; 31 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 32 | 33 | public class MarketEventHandlerImplTest { 34 | 35 | private final double bid = 1.55; 36 | private final double ask = 1.5502; 37 | private final String gbpusd = "GBP_USD"; 38 | private final int numSubscribers = 2; 39 | private final CountDownLatch done = new CountDownLatch(numSubscribers); 40 | 41 | @Test 42 | public void testRideEventBus() throws Exception { 43 | EventBus evtBus = new AsyncEventBus(Executors.newFixedThreadPool(numSubscribers)); 44 | for (int i = 1; i <= numSubscribers; i++) { 45 | evtBus.register(new MarketDataSubscriber()); 46 | } 47 | MarketEventCallback callback = new MarketEventHandlerImpl(evtBus); 48 | callback.onMarketEvent(new TradeableInstrument(gbpusd), bid, ask, DateTime.now()); 49 | done.await(); 50 | } 51 | 52 | private class MarketDataSubscriber { 53 | 54 | @Subscribe 55 | @AllowConcurrentEvents 56 | public void processPayLoad(MarketDataPayLoad payload) { 57 | assertEquals(gbpusd, payload.getInstrument().getInstrument()); 58 | assertEquals(bid, payload.getBidPrice(), TradingTestConstants.precision); 59 | assertEquals(ask, payload.getAskPrice(), TradingTestConstants.precision); 60 | done.countDown(); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/test/resources/foobar.txt: -------------------------------------------------------------------------------- 1 | hello world foo!! -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-core/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | #Nike log4j log file 2 | 3 | log4j.rootLogger=INFO, stdout 4 | 5 | #stdout Log 6 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 7 | log4j.appender.stdout.Threshold=INFO 8 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] - %m%n 10 | 11 | #file Log 12 | #log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 13 | #log4j.appender.file.Threshold=INFO 14 | #log4j.appender.file.File=/home/a_nike/sv/logs/loader.log 15 | #log4j.appender.file.File=/app/logs/trading.log 16 | #log4j.appender.file.Append=true 17 | #log4j.appender.file.ImmediateFlush=true 18 | #log4j.appender.file.layout=org.apache.log4j.PatternLayout 19 | #log4j.appender.file.layout.ConversionPattern=%-5p %d [%t] %c(%M)\: %m%n -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-demo-programs/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-demo-programs/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | tradingbot-demo-programs 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-demo-programs/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding//src/test/resources=UTF-8 6 | encoding/=UTF-8 7 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-demo-programs/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-demo-programs/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-demo-programs/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.precioustech 4 | tradingbot-demo-programs 5 | 1.0 6 | 7 | UTF-8 8 | 4.1.1.RELEASE 9 | 1.1.0.RELEASE 10 | 1.8 11 | 12 | 13 | 14 | com.precioustech 15 | tradingbot-core 16 | 1.0 17 | 18 | 19 | com.precioustech.fxtrading 20 | tradingbot-app 21 | 1.0 22 | 23 | 24 | com.precioustech 25 | oanda-restapi 26 | 1.0 27 | 28 | 29 | 30 | 31 | install 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-compiler-plugin 36 | 37 | ${jdk.version} 38 | ${jdk.version} 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-demo-programs/src/main/java/com/precioustech/fxtrading/instrument/InstrumentServiceDemo.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.instrument; 2 | 3 | import java.util.Collection; 4 | 5 | import org.apache.commons.lang3.StringUtils; 6 | import org.apache.log4j.Logger; 7 | 8 | import com.precioustech.fxtrading.oanda.restapi.instrument.OandaInstrumentDataProviderService; 9 | 10 | public class InstrumentServiceDemo { 11 | 12 | private static final Logger LOG = Logger.getLogger(InstrumentServiceDemo.class); 13 | 14 | private static void usageAndValidation(String[] args) { 15 | if (args.length != 3) { 16 | LOG.error("Usage: InstrumentServiceDemo "); 17 | System.exit(1); 18 | } else { 19 | if (!StringUtils.isNumeric(args[1])) { 20 | LOG.error("Argument 2 should be numeric"); 21 | System.exit(1); 22 | } 23 | } 24 | } 25 | 26 | public static void main(String[] args) { 27 | usageAndValidation(args); 28 | String url = args[0]; 29 | Long accountId = Long.parseLong(args[1]); 30 | String accessToken = args[2]; 31 | 32 | InstrumentDataProvider instrumentDataProvider = new OandaInstrumentDataProviderService(url, accountId, 33 | accessToken); 34 | 35 | InstrumentService instrumentService = new InstrumentService(instrumentDataProvider); 36 | 37 | Collection> gbpInstruments = instrumentService.getAllPairsWithCurrency("GBP"); 38 | 39 | LOG.info("+++++++++++++++++++++++++++++++ Dumping Instrument Info +++++++++++++++++++++++++++++"); 40 | for (TradeableInstrument instrument : gbpInstruments) { 41 | LOG.info(instrument); 42 | } 43 | LOG.info("+++++++++++++++++++++++Finished Dumping Instrument Info +++++++++++++++++++++++++++++"); 44 | TradeableInstrument euraud = new TradeableInstrument("EUR_AUD"); 45 | TradeableInstrument usdjpy = new TradeableInstrument("USD_JPY"); 46 | TradeableInstrument usdzar = new TradeableInstrument("USD_ZAR"); 47 | 48 | Double usdjpyPip = instrumentService.getPipForInstrument(usdjpy); 49 | Double euraudPip = instrumentService.getPipForInstrument(euraud); 50 | Double usdzarPip = instrumentService.getPipForInstrument(usdzar); 51 | 52 | LOG.info(String.format("Pip for instrument %s is %1.5f", euraud.getInstrument(), euraudPip)); 53 | LOG.info(String.format("Pip for instrument %s is %1.5f", usdjpy.getInstrument(), usdjpyPip)); 54 | LOG.info(String.format("Pip for instrument %s is %1.5f", usdzar.getInstrument(), usdzarPip)); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-demo-programs/src/main/java/com/precioustech/fxtrading/oanda/restapi/account/transaction/TransactionDataProviderDemo.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.oanda.restapi.account.transaction; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.log4j.Logger; 6 | 7 | import com.precioustech.fxtrading.account.transaction.Transaction; 8 | import com.precioustech.fxtrading.account.transaction.TransactionDataProvider; 9 | 10 | public class TransactionDataProviderDemo { 11 | 12 | private static final Logger LOG = Logger.getLogger(TransactionDataProviderDemo.class); 13 | 14 | private static void usage(String[] args) { 15 | if (args.length != 4) { 16 | LOG.error("Usage: TransactionDataProviderDemo "); 17 | System.exit(1); 18 | } 19 | } 20 | 21 | public static void main(String[] args) { 22 | usage(args); 23 | final String url = args[0]; 24 | final String accessToken = args[1]; 25 | final Long transactionId = Long.parseLong(args[2]); 26 | final Long accountId = Long.parseLong(args[3]); 27 | TransactionDataProvider transactionDataProvider = new OandaTransactionDataProviderService( 28 | url, accessToken); 29 | 30 | List> transactions = transactionDataProvider 31 | .getTransactionsGreaterThanId(transactionId, accountId); 32 | LOG.info(String.format("++++ Found %d historic transactions from id %d for acc id = %d", transactions.size(), 33 | transactionId, accountId)); 34 | for (Transaction transaction : transactions) { 35 | 36 | if (transaction != null) { 37 | LOG.info(transaction); 38 | } 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-demo-programs/src/main/java/com/precioustech/fxtrading/tradingbot/events/notification/email/EventEmailNotifierDemo.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.tradingbot.events.notification.email; 2 | 3 | import java.util.Map; 4 | 5 | import org.json.simple.JSONObject; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.support.ClassPathXmlApplicationContext; 8 | 9 | import com.google.common.collect.Maps; 10 | import com.google.common.eventbus.EventBus; 11 | import com.precioustech.fxtrading.events.EventPayLoad; 12 | import com.precioustech.fxtrading.oanda.restapi.OandaJsonKeys; 13 | import com.precioustech.fxtrading.oanda.restapi.events.TradeEvents; 14 | 15 | public class EventEmailNotifierDemo { 16 | 17 | @SuppressWarnings("unchecked") 18 | public static void main(String[] args) { 19 | ApplicationContext appContext = 20 | new ClassPathXmlApplicationContext("emailnotify-demo.xml"); 21 | EventEmailNotifier emailNotifier = 22 | appContext.getBean(EventEmailNotifier.class); 23 | EventBus eventBus = new EventBus(); 24 | eventBus.register(emailNotifier); 25 | 26 | Map payload = Maps.newHashMap(); 27 | payload.put(OandaJsonKeys.instrument, "GBP_USD"); 28 | payload.put(OandaJsonKeys.type, TradeEvents.TAKE_PROFIT_FILLED.name()); 29 | payload.put(OandaJsonKeys.accountId, 123456l); 30 | payload.put(OandaJsonKeys.accountBalance, 127.8); 31 | payload.put(OandaJsonKeys.tradeId, 234567l); 32 | payload.put(OandaJsonKeys.pl, 11.8); 33 | payload.put(OandaJsonKeys.interest, 0.27); 34 | payload.put(OandaJsonKeys.units, 2700l); 35 | 36 | JSONObject jsonObj = new JSONObject(payload); 37 | eventBus.post(new EventPayLoad(TradeEvents.TAKE_PROFIT_FILLED, jsonObj)); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-demo-programs/src/main/java/com/precioustech/fxtrading/tradingbot/social/twitter/tweethandler/TweetHarvesterDemo.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.tradingbot.social.twitter.tweethandler; 2 | 3 | import java.util.Collection; 4 | import java.util.Iterator; 5 | 6 | import org.apache.log4j.Logger; 7 | import org.springframework.context.ApplicationContext; 8 | import org.springframework.context.support.ClassPathXmlApplicationContext; 9 | 10 | import com.precioustech.fxtrading.instrument.TradeableInstrument; 11 | import com.precioustech.fxtrading.tradingbot.social.twitter.CloseFXTradeTweet; 12 | import com.precioustech.fxtrading.tradingbot.social.twitter.NewFXTradeTweet; 13 | 14 | public class TweetHarvesterDemo { 15 | private static final Logger LOG = Logger.getLogger(TweetHarvesterDemo.class); 16 | 17 | @SuppressWarnings("unchecked") 18 | public static void main(String[] args) { 19 | 20 | ApplicationContext appContext = new ClassPathXmlApplicationContext("tweetharvester-demo.xml"); 21 | TweetHarvester tweetHarvester = appContext.getBean(TweetHarvester.class); 22 | 23 | TradeableInstrument eurusd = new TradeableInstrument("EUR_USD"); 24 | String userId = "Forex_EA4U"; 25 | // String userId = "SignalFactory"; 26 | final int tweetsToDump = 10; 27 | int ctr = 0; 28 | 29 | Collection> newTradeTweets = tweetHarvester.harvestNewTradeTweets(userId); 30 | LOG.info(String.format("+++++++++ Dumping the first %d of %d new fx tweets for userid %s +++++++", 31 | tweetsToDump, newTradeTweets.size(), userId)); 32 | Iterator> newTweetItr = newTradeTweets.iterator(); 33 | while (newTweetItr.hasNext() && ctr < tweetsToDump) { 34 | NewFXTradeTweet newFxTweet = newTweetItr.next(); 35 | LOG.info(newFxTweet); 36 | ctr++; 37 | } 38 | 39 | Collection> closedTradeTweets = tweetHarvester.harvestHistoricTradeTweets(userId, 40 | eurusd); 41 | ctr = 0; 42 | Iterator> closedTweetItr = closedTradeTweets.iterator(); 43 | LOG.info(String.format("+++++++++ Dumping the first %d of %d closed fx tweets for userid %s +++++++", 44 | tweetsToDump, closedTradeTweets.size(), userId)); 45 | while (closedTweetItr.hasNext() && ctr < tweetsToDump) { 46 | CloseFXTradeTweet closeFxTweet = closedTweetItr.next(); 47 | LOG.info(String.format("Instrument %s, profit = %3.1f, price=%2.5f ", closeFxTweet.getInstrument() 48 | .getInstrument(), closeFxTweet.getProfit(), closeFxTweet.getPrice())); 49 | ctr++; 50 | } 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-demo-programs/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | #Nike log4j log file 2 | 3 | log4j.rootLogger=INFO, stdout, file 4 | 5 | #stdout Log 6 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 7 | log4j.appender.stdout.Threshold=INFO 8 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] - %m%n 10 | 11 | #file Log 12 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 13 | log4j.appender.file.Threshold=INFO 14 | #log4j.appender.file.File=/home/a_nike/sv/logs/loader.log 15 | log4j.appender.file.File=~/logs/trading.log 16 | log4j.appender.file.Append=true 17 | log4j.appender.file.ImmediateFlush=true 18 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 19 | log4j.appender.file.layout.ConversionPattern=%-5p %d [%t] %c(%M)\: %m%n -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | tradingbot-prediction-api 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.springframework.ide.eclipse.core.springbuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.wst.validation.validationbuilder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.springframework.ide.eclipse.core.springnature 38 | org.eclipse.jdt.core.javanature 39 | org.eclipse.m2e.core.maven2Nature 40 | org.eclipse.wst.common.project.facet.core.nature 41 | 42 | 43 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | encoding/=UTF-8 5 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/src/main/java/com/precioustech/fxtrading/prediction/DirectionEnum.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.prediction; 2 | 3 | public enum DirectionEnum { 4 | SHORT, 5 | LONG; 6 | } 7 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/src/main/java/com/precioustech/fxtrading/prediction/PredictionData.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.prediction; 2 | 3 | public class PredictionData { 4 | 5 | private final String instrument; 6 | private final TradingSessionEnum tradingSession; 7 | private final String badDecision; 8 | private final DirectionEnum directionEnum; 9 | private final int count; 10 | 11 | public PredictionData(String instrument, TradingSessionEnum tradingSession, String isBadDecision, 12 | DirectionEnum directionEnum, int count) { 13 | super(); 14 | this.instrument = instrument; 15 | this.tradingSession = tradingSession; 16 | this.badDecision = isBadDecision; 17 | this.directionEnum = directionEnum; 18 | this.count = count; 19 | } 20 | 21 | public String getInstrument() { 22 | return instrument; 23 | } 24 | 25 | public TradingSessionEnum getTradingSession() { 26 | return tradingSession; 27 | } 28 | 29 | public String getBadDecision() { 30 | return badDecision; 31 | } 32 | 33 | public DirectionEnum getDirectionEnum() { 34 | return directionEnum; 35 | } 36 | 37 | public int getCount() { 38 | return count; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/src/main/java/com/precioustech/fxtrading/prediction/TradingSessionEnum.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.prediction; 2 | 3 | public enum TradingSessionEnum { 4 | MORNING, 5 | EVENING, 6 | NIGHT 7 | } 8 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/src/main/java/com/precioustech/fxtrading/prediction/dao/PredictionDao.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.prediction.dao; 2 | 3 | import java.util.List; 4 | 5 | import com.precioustech.fxtrading.prediction.PredictionData; 6 | 7 | public interface PredictionDao { 8 | 9 | List getLearningDataSet(); 10 | } 11 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/src/main/java/com/precioustech/fxtrading/prediction/dao/PredictionDaoJdbcTemplImpl.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.prediction.dao; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.jdbc.core.JdbcTemplate; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | import com.google.common.collect.Lists; 11 | import com.precioustech.fxtrading.prediction.DirectionEnum; 12 | import com.precioustech.fxtrading.prediction.PredictionData; 13 | import com.precioustech.fxtrading.prediction.TradingSessionEnum; 14 | 15 | public class PredictionDaoJdbcTemplImpl implements PredictionDao { 16 | @Autowired 17 | private JdbcTemplate jdbcTemplate; 18 | 19 | @Transactional 20 | @Override 21 | public List getLearningDataSet() { 22 | List learningSet = Lists.newArrayList(); 23 | List> results = this.jdbcTemplate 24 | .queryForList("select instrument, session, direction, is_bad_decision," 25 | + "count(*) ct from trade_data t1 join oanda_transaction_result t2 " 26 | + "on t1.transaction_id=t2.transaction_id " 27 | + "group by instrument, is_bad_decision, session, direction"); 28 | for (Map row : results) { 29 | String strBadDecision = row.get("is_bad_decision").toString(); 30 | learningSet.add(new PredictionData(row.get("instrument").toString(), 31 | TradingSessionEnum.valueOf(row.get("session").toString()), strBadDecision, 32 | DirectionEnum.valueOf(row.get("direction").toString()), ((Long) row.get("ct")).intValue())); 33 | } 34 | return learningSet; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/src/main/java/com/precioustech/fxtrading/prediction/utils/PredictionUtils.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.prediction.utils; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | import com.google.common.base.Preconditions; 6 | import com.precioustech.fxtrading.prediction.TradingSessionEnum; 7 | 8 | public class PredictionUtils { 9 | private PredictionUtils() { 10 | 11 | } 12 | 13 | public static TradingSessionEnum deriveTradingSession(DateTime dt) { 14 | Preconditions.checkNotNull(dt); 15 | int hrOfDay = dt.getHourOfDay(); 16 | if (hrOfDay <= 6 || hrOfDay > 22) { 17 | return TradingSessionEnum.NIGHT; 18 | } else if (hrOfDay <= 14) { 19 | return TradingSessionEnum.MORNING; 20 | } else { 21 | return TradingSessionEnum.EVENING; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | #Nike log4j log file 2 | 3 | log4j.rootLogger=INFO, stdout, file 4 | 5 | #stdout Log 6 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 7 | log4j.appender.stdout.Threshold=INFO 8 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] - %m%n 10 | log4j.appender.stdout.org.hibernate.type=TRACE 11 | 12 | #file Log 13 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 14 | log4j.appender.file.Threshold=INFO 15 | log4j.appender.file.File=/app/logs/predictions.log 16 | log4j.appender.file.Append=false 17 | log4j.appender.file.ImmediateFlush=true 18 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 19 | log4j.appender.file.layout.ConversionPattern=%-5p %d [%t] %c(%M)\: %m%n -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/src/main/resources/tradingbot-prediction-app.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-prediction-api/src/main/resources/tradingbot-prediction.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName=com.mysql.jdbc.Driver 2 | jdbc.url=jdbc:mysql://localhost:3306/test 3 | jdbc.username=test 4 | jdbc.password=test -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | tradingbot-web 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.springframework.ide.eclipse.core.springbuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.jsdt.core.javascriptValidator 25 | 26 | 27 | 28 | 29 | org.eclipse.wst.validation.validationbuilder 30 | 31 | 32 | 33 | 34 | org.eclipse.m2e.core.maven2Builder 35 | 36 | 37 | 38 | 39 | 40 | org.springframework.ide.eclipse.core.springnature 41 | org.eclipse.jdt.core.javanature 42 | org.eclipse.m2e.core.maven2Nature 43 | org.eclipse.wst.common.project.facet.core.nature 44 | org.eclipse.wst.common.modulecore.ModuleCoreNature 45 | org.eclipse.wst.jsdt.core.jsNature 46 | 47 | 48 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 12 | org.eclipse.jdt.core.compiler.source=1.8 13 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | uses 9 | 10 | 11 | uses 12 | 13 | 14 | uses 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | DELEGATES_PREFERENCE=delegateValidatorListorg.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator\=org.eclipse.wst.wsdl.validation.internal.eclipse.Validator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator\=org.eclipse.wst.xsd.core.internal.validation.eclipse.Validator; 2 | USER_BUILD_PREFERENCE=enabledBuildValidatorListorg.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator;org.eclipse.jst.jsf.validation.internal.JSPSemanticsValidator;org.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;org.eclipse.wst.common.componentcore.internal.ModuleCoreValidator;org.eclipse.jst.jsf.validation.internal.appconfig.AppConfigValidator;org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator;org.eclipse.wst.html.internal.validation.HTMLValidator;org.eclipse.jst.jsp.core.internal.validation.JSPContentValidator;org.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator;org.eclipse.wst.wsi.ui.internal.WSIMessageValidator; 3 | USER_MANUAL_PREFERENCE=enabledManualValidatorListorg.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator;org.eclipse.jst.jsf.validation.internal.JSPSemanticsValidator;org.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;org.eclipse.wst.common.componentcore.internal.ModuleCoreValidator;org.eclipse.jst.jsf.validation.internal.appconfig.AppConfigValidator;org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator;org.eclipse.wst.html.internal.validation.HTMLValidator;org.eclipse.jst.jsp.core.internal.validation.JSPContentValidator;org.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator;org.eclipse.wst.wsi.ui.internal.WSIMessageValidator; 4 | USER_PREFERENCE=overrideGlobalPreferencesfalse 5 | disabled=06target 6 | eclipse.preferences.version=1 7 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/java/com/precioustech/fxtrading/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.precioustech.fxtrading.web; 2 | 3 | import java.text.DateFormat; 4 | import java.util.Date; 5 | import java.util.Locale; 6 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.Model; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RequestMethod; 13 | 14 | /** 15 | * Handles requests for the application home page. 16 | */ 17 | @Controller 18 | public class HomeController { 19 | 20 | private static final Logger logger = LoggerFactory.getLogger(HomeController.class); 21 | 22 | /** 23 | * Simply selects the home view to render by returning its name. 24 | */ 25 | @RequestMapping(value = "/", method = RequestMethod.GET) 26 | public String home(Locale locale, Model model) { 27 | logger.info("Welcome home! The client locale is {}.", locale); 28 | 29 | Date date = new Date(); 30 | DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); 31 | 32 | String formattedDate = dateFormat.format(date); 33 | 34 | model.addAttribute("serverTime", formattedDate ); 35 | 36 | return "home"; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/WEB-INF/spring/root-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/WEB-INF/views/home.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page session="false" %> 3 | 4 | 5 | Home 6 | 7 | 8 |

9 | Hello world! 10 |

11 | 12 |

The time on the server is ${serverTime}.

13 | 14 | 15 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | contextConfigLocation 9 | /WEB-INF/spring/root-context.xml 10 | 11 | 12 | 13 | 14 | org.springframework.web.context.ContextLoaderListener 15 | 16 | 17 | 18 | 19 | appServlet 20 | org.springframework.web.servlet.DispatcherServlet 21 | 22 | contextConfigLocation 23 | /WEB-INF/spring/appServlet/servlet-context.xml 24 | 25 | 1 26 | 27 | 28 | 29 | appServlet 30 | / 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/Sorting icons.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/Sorting icons.psd -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/favicon.ico -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/sort_asc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/sort_asc.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/sort_asc_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/sort_asc_disabled.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/sort_both.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/sort_both.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/sort_desc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/sort_desc.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/sort_desc_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/css/images/sort_desc_disabled.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/css/jquery/jquery-ui-timepicker-addon.css: -------------------------------------------------------------------------------- 1 | .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; } 2 | .ui-timepicker-div dl { text-align: left; } 3 | .ui-timepicker-div dl dt { float: left; clear:left; padding: 0 0 0 5px; } 4 | .ui-timepicker-div dl dd { margin: 0 10px 10px 40%; } 5 | .ui-timepicker-div td { font-size: 90%; } 6 | .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; } 7 | .ui-timepicker-div .ui_tpicker_unit_hide{ display: none; } 8 | 9 | .ui-timepicker-div .ui_tpicker_time .ui_tpicker_time_input { background: none; color: inherit; border: none; outline: none; border-bottom: solid 1px #555; width: 95%; } 10 | .ui-timepicker-div .ui_tpicker_time .ui_tpicker_time_input:focus { border-bottom-color: #aaa; } 11 | 12 | .ui-timepicker-rtl{ direction: rtl; } 13 | .ui-timepicker-rtl dl { text-align: right; padding: 0 5px 0 0; } 14 | .ui-timepicker-rtl dl dt{ float: right; clear: right; } 15 | .ui-timepicker-rtl dl dd { margin: 0 40% 10px 10px; } 16 | 17 | /* Shortened version style */ 18 | .ui-timepicker-div.ui-timepicker-oneLine { padding-right: 2px; } 19 | .ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_time, 20 | .ui-timepicker-div.ui-timepicker-oneLine dt { display: none; } 21 | .ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_time_label { display: block; padding-top: 2px; } 22 | .ui-timepicker-div.ui-timepicker-oneLine dl { text-align: right; } 23 | .ui-timepicker-div.ui-timepicker-oneLine dl dd, 24 | .ui-timepicker-div.ui-timepicker-oneLine dl dd > div { display:inline-block; margin:0; } 25 | .ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_minute:before, 26 | .ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_second:before { content:':'; display:inline-block; } 27 | .ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_millisec:before, 28 | .ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_microsec:before { content:'.'; display:inline-block; } 29 | .ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_unit_hide, 30 | .ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_unit_hide:before{ display: none; } -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_diagonals-thick_90_eeeeee_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_diagonals-thick_90_eeeeee_40x40.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_glass_100_e4f1fb_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_glass_100_e4f1fb_1x400.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_glass_50_3baae3_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_glass_50_3baae3_1x400.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_glass_80_d7ebf9_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_glass_80_d7ebf9_1x400.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_highlight-hard_100_f2f5f7_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_highlight-hard_100_f2f5f7_1x100.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_highlight-hard_70_000000_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_highlight-hard_70_000000_1x100.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_highlight-soft_100_deedf7_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_highlight-soft_100_deedf7_1x100.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_highlight-soft_25_ffef8f_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-bg_highlight-soft_25_ffef8f_1x100.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-icons_2694e8_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-icons_2694e8_256x240.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-icons_2e83ff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-icons_2e83ff_256x240.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-icons_3d80b3_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-icons_3d80b3_256x240.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-icons_72a7cf_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-icons_72a7cf_256x240.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-icons_ffffff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/building-trading-bots-java/c9f0788ebc0b7ce1899025b0d7da758ca0e5a456/book-code-master/java/tradingbot-web/src/main/webapp/resources/js/jquery/images/ui-icons_ffffff_256x240.png -------------------------------------------------------------------------------- /book-code-master/java/tradingbot-web/src/test/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Apress Source Code 2 | 3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. 4 | 5 | ## How to Contribute 6 | 7 | 1. Make sure you have a GitHub account. 8 | 2. Fork the repository for the relevant book. 9 | 3. Create a new branch on which to make your change, e.g. 10 | `git checkout -b my_code_contribution` 11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. 12 | 5. Submit a pull request. 13 | 14 | Thank you for your contribution! --------------------------------------------------------------------------------