Skip to content

Commit

Permalink
#32 : Quick cleanup of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
gazbert committed Jun 1, 2019
1 parent 2ae7b51 commit eef0123
Show file tree
Hide file tree
Showing 19 changed files with 21 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1;

import org.apache.logging.log4j.LogManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.config;

import com.gazbert.bxbot.rest.api.v1.AbstractController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.config;

import com.gazbert.bxbot.domain.emailalerts.EmailAlertsConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.config;

import com.gazbert.bxbot.domain.engine.EngineConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.config;

import com.gazbert.bxbot.domain.exchange.ExchangeConfig;
Expand Down Expand Up @@ -65,7 +64,7 @@ public ExchangeConfigController(ExchangeConfigService exchangeConfigService) {
* Returns the Exchange configuration for the bot.
* <p>
* The AuthenticationConfig is stripped out and not exposed for remote consumption.
* The API keys/credentials should not leave the bot's local machine via the REST API.
* The API keys/credentials will not leave the bot's local machine via the REST API.
*
* @param user the authenticated user making the request.
* @return the Exchange configuration.
Expand All @@ -76,7 +75,7 @@ public ExchangeConfig getExchange(@AuthenticationPrincipal User user) {
LOG.info("GET " + EXCHANGE_RESOURCE_PATH + " - getExchange() - caller: " + user.getUsername());

final ExchangeConfig exchangeConfig = exchangeConfigService.getExchangeConfig();
exchangeConfig.setAuthenticationConfig(null);
exchangeConfig.setAuthenticationConfig(null); // authentication config removed by design

LOG.info("Response: " + exchangeConfig);
return exchangeConfig;
Expand All @@ -86,7 +85,7 @@ public ExchangeConfig getExchange(@AuthenticationPrincipal User user) {
* Updates the Exchange configuration for the bot.
* <p>
* Any AuthenticationConfig is stripped out and not updated.
* The API keys/credentials should not enter the bot's local machine via the REST API.
* The API keys/credentials will not land on the bot's local machine via the REST API.
*
* @param user the authenticated user making the request.
* @param config the Exchange config to update.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.config;

import com.gazbert.bxbot.domain.market.MarketConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.config;

import com.gazbert.bxbot.domain.strategy.StrategyConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.runtime;

import com.gazbert.bxbot.rest.api.v1.AbstractController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.runtime;

import com.gazbert.bxbot.domain.bot.BotStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.security;

import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1;

import org.junit.Assert;
Expand All @@ -36,6 +35,7 @@

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
Expand Down Expand Up @@ -98,9 +98,9 @@ protected void setConverters(HttpMessageConverter<?>[] converters) {
// Shared utils
// ------------------------------------------------------------------------------------------------

protected String buildAuthorizationHeaderValue(String username, String password) throws Exception {
protected String buildAuthorizationHeaderValue(String username, String password) {
return "Basic " + new String(Base64Utils.encode(
(username + ":" + password).getBytes("UTF-8")), Charset.forName("UTF-8"));
(username + ":" + password).getBytes(StandardCharsets.UTF_8)), Charset.forName("UTF-8"));
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.config;

import com.gazbert.bxbot.rest.api.v1.AbstractControllerTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.config;

import com.gazbert.bxbot.core.engine.TradingEngine;
Expand Down Expand Up @@ -68,7 +67,7 @@ public class TestEmailAlertsConfigController extends AbstractConfigControllerTes
private static final String TO_ADDRESS = "[email protected]";

@MockBean
EmailAlertsConfigService emailAlertsConfigService;
private EmailAlertsConfigService emailAlertsConfigService;

// Need this even though not used in the test directly because Spring loads it on startup...
@MockBean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.config;

import com.gazbert.bxbot.core.engine.TradingEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.config;

import com.gazbert.bxbot.core.engine.TradingEngine;
Expand Down Expand Up @@ -86,8 +85,7 @@ public class TestExchangeConfigController extends AbstractConfigControllerTest {
private static final String SELL_FEE_CONFIG_ITEM_KEY = "sell-fee";
private static final String SELL_FEE_CONFIG_ITEM_VALUE = "0.25";

@MockBean
ExchangeConfigService exchangeConfigService;
@MockBean private ExchangeConfigService exchangeConfigService;

// Need this even though not used in the test directly because Spring loads it on startup...
@MockBean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.config;

import com.gazbert.bxbot.core.engine.TradingEngine;
Expand Down Expand Up @@ -80,7 +79,7 @@ public class TestMarketConfigController extends AbstractConfigControllerTest {
private static final String MARKET_2_STRATEGY_ID = "macd-strategy";

@MockBean
MarketConfigService marketConfigService;
private MarketConfigService marketConfigService;

// Need this even though not used in the test directly because Spring loads it on startup...
@MockBean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.gazbert.bxbot.rest.api.v1.config;

import com.gazbert.bxbot.core.engine.TradingEngine;
Expand Down Expand Up @@ -71,21 +70,19 @@ public class TestStrategyConfigController extends AbstractConfigControllerTest {
private static final String STRAT_1_NAME = "MACD Strat Algo";
private static final String STRAT_1_DESCRIPTION = "Uses MACD as indicator and takes long position in base currency.";
private static final String STRAT_1_CLASSNAME = "com.gazbert.nova.algos.MacdLongBase";
private static final String STRAT_1_BEANNAME = "macdLongBase";

private static final String STRAT_2_ID = "long-scalper";
private static final String STRAT_2_NAME = "Long Position Scalper Algo";
private static final String STRAT_2_DESCRIPTION = "Scalps and goes long...";
private static final String STRAT_2_CLASSNAME = "com.gazbert.nova.algos.LongScalper";
private static final String STRAT_2_BEANNAME = "longScalper";
private static final String STRAT_2_BEAN_NAME = "longScalper";

private static final String BUY_PRICE_CONFIG_ITEM_KEY = "buy-price";
private static final String BUY_PRICE_CONFIG_ITEM_VALUE = "671.15";
private static final String AMOUNT_TO_BUY_CONFIG_ITEM_KEY = "buy-amount";
private static final String AMOUNT_TO_BUY_CONFIG_ITEM_VALUE = "0.5";

@MockBean
StrategyConfigService strategyConfigService;
private StrategyConfigService strategyConfigService;

// Need this even though not used in the test directly because Spring loads it on startup...
@MockBean
Expand Down Expand Up @@ -114,13 +111,15 @@ public void testGetAllStrategyConfig() throws Exception {
.andExpect(jsonPath("$.[0].name").value(STRAT_1_NAME))
.andExpect(jsonPath("$.[0].description").value(STRAT_1_DESCRIPTION))
.andExpect(jsonPath("$.[0].className").value(STRAT_1_CLASSNAME))
.andExpect(jsonPath("$.[0].beanName").isEmpty())
.andExpect(jsonPath("$.[0].configItems.buy-price").value(BUY_PRICE_CONFIG_ITEM_VALUE))
.andExpect(jsonPath("$.[0].configItems.buy-amount").value(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE))

.andExpect(jsonPath("$.[1].id").value(STRAT_2_ID))
.andExpect(jsonPath("$.[1].name").value(STRAT_2_NAME))
.andExpect(jsonPath("$.[1].description").value(STRAT_2_DESCRIPTION))
.andExpect(jsonPath("$.[1].className").value(STRAT_2_CLASSNAME))
.andExpect(jsonPath("$.[1].className").isEmpty())
.andExpect(jsonPath("$.[1].beanName").value(STRAT_2_BEAN_NAME))
.andExpect(jsonPath("$.[1].configItems.buy-price").value(BUY_PRICE_CONFIG_ITEM_VALUE))
.andExpect(jsonPath("$.[1].configItems.buy-amount").value(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE));

Expand Down Expand Up @@ -158,6 +157,7 @@ public void testGetStrategyConfig() throws Exception {
.andExpect(jsonPath("$.name").value(STRAT_1_NAME))
.andExpect(jsonPath("$.description").value(STRAT_1_DESCRIPTION))
.andExpect(jsonPath("$.className").value(STRAT_1_CLASSNAME))
.andExpect(jsonPath("$.beanName").isEmpty())
.andExpect(jsonPath("$.configItems.buy-price").value(BUY_PRICE_CONFIG_ITEM_VALUE))
.andExpect(jsonPath("$.configItems.buy-amount").value(AMOUNT_TO_BUY_CONFIG_ITEM_VALUE));

Expand Down Expand Up @@ -343,8 +343,8 @@ private static List<StrategyConfig> allTheStrategiesConfig() {
configItems.put(BUY_PRICE_CONFIG_ITEM_KEY, BUY_PRICE_CONFIG_ITEM_VALUE);
configItems.put(AMOUNT_TO_BUY_CONFIG_ITEM_KEY, AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);

final StrategyConfig strategyConfig1 = new StrategyConfig(STRAT_1_ID, STRAT_1_NAME, STRAT_1_DESCRIPTION, STRAT_1_CLASSNAME, STRAT_1_BEANNAME, configItems);
final StrategyConfig strategyConfig2 = new StrategyConfig(STRAT_2_ID, STRAT_2_NAME, STRAT_2_DESCRIPTION, STRAT_2_CLASSNAME, STRAT_2_BEANNAME, configItems);
final StrategyConfig strategyConfig1 = new StrategyConfig(STRAT_1_ID, STRAT_1_NAME, STRAT_1_DESCRIPTION, STRAT_1_CLASSNAME, null, configItems);
final StrategyConfig strategyConfig2 = new StrategyConfig(STRAT_2_ID, STRAT_2_NAME, STRAT_2_DESCRIPTION, null, STRAT_2_BEAN_NAME, configItems);

final List<StrategyConfig> allStrategies = new ArrayList<>();
allStrategies.add(strategyConfig1);
Expand All @@ -356,20 +356,20 @@ private static StrategyConfig someStrategyConfig() {
final Map<String, String> configItems = new HashMap<>();
configItems.put(BUY_PRICE_CONFIG_ITEM_KEY, BUY_PRICE_CONFIG_ITEM_VALUE);
configItems.put(AMOUNT_TO_BUY_CONFIG_ITEM_KEY, AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);
return new StrategyConfig(STRAT_1_ID, STRAT_1_NAME, STRAT_1_DESCRIPTION, STRAT_1_CLASSNAME, STRAT_1_BEANNAME, configItems);
return new StrategyConfig(STRAT_1_ID, STRAT_1_NAME, STRAT_1_DESCRIPTION, STRAT_1_CLASSNAME, null, configItems);
}

private static StrategyConfig someStrategyConfigWithMissingId() {
final Map<String, String> configItems = new HashMap<>();
configItems.put(BUY_PRICE_CONFIG_ITEM_KEY, BUY_PRICE_CONFIG_ITEM_VALUE);
configItems.put(AMOUNT_TO_BUY_CONFIG_ITEM_KEY, AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);
return new StrategyConfig(null, STRAT_1_NAME, STRAT_1_DESCRIPTION, STRAT_1_CLASSNAME, STRAT_1_BEANNAME, configItems);
return new StrategyConfig(null, STRAT_1_NAME, STRAT_1_DESCRIPTION, STRAT_1_CLASSNAME, null, configItems);
}

private static StrategyConfig unrecognizedStrategyConfig() {
final Map<String, String> configItems = new HashMap<>();
configItems.put(BUY_PRICE_CONFIG_ITEM_KEY, BUY_PRICE_CONFIG_ITEM_VALUE);
configItems.put(AMOUNT_TO_BUY_CONFIG_ITEM_KEY, AMOUNT_TO_BUY_CONFIG_ITEM_VALUE);
return new StrategyConfig(UNKNOWN_STRAT_ID, STRAT_1_NAME, STRAT_1_DESCRIPTION, STRAT_1_CLASSNAME, STRAT_1_BEANNAME, configItems);
return new StrategyConfig(UNKNOWN_STRAT_ID, STRAT_1_NAME, STRAT_1_DESCRIPTION, STRAT_1_CLASSNAME, null, configItems);
}
}
5 changes: 1 addition & 4 deletions bxbot-rest-api/src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
#
# BX-bot's Spring Boot application config.
#
# WARNING: Not safe for production!
# NOTE: Configuration below is set for unit tests.
#
###############################################################################

# The port the Spring Boot container will listen on for incoming HTTP requests.
# Defaults to 8080 if not set. Setting it to -1 disables the port.
# REST API not ready for production yet, so port is disabled.
server.port=8090

# The Spring Boot management port.
Expand All @@ -31,5 +30,3 @@ spring.security.user.name=unit-test-user
spring.security.user.password=unit-test-password
spring.security.user.roles=USER



2 changes: 0 additions & 2 deletions config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#
# BX-bot's Spring Boot application config.
#
# WARNING: Not safe for production!
#
###############################################################################

# The port the Spring Boot container will listen on for incoming HTTP requests.
Expand Down

0 comments on commit eef0123

Please sign in to comment.