com.anrisoftware.simplerest.oanda.rest.OandaRestPrices Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simplerest-oanda-rest Show documentation
Show all versions of simplerest-oanda-rest Show documentation
Access Forex trading via the Oanda REST API.
/*
* Copyright 2016 Erwin Müller
*
* This file is part of simplerest-oanda-rest.
*
* simplerest-oanda-rest is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* simplerest-oanda-rest is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with simplerest-oanda-rest. If not, see .
*/
package com.anrisoftware.simplerest.oanda.rest;
import static org.apache.commons.lang3.StringUtils.join;
import static org.apache.commons.lang3.Validate.isTrue;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import com.anrisoftware.simplerest.core.SimpleRestException;
import com.anrisoftware.simplerest.oanda.api.Instrument;
import com.anrisoftware.simplerest.oanda.api.OandaAccount;
import com.anrisoftware.simplerest.oanda.api.OandaErrorException;
import com.anrisoftware.simplerest.oanda.api.Price;
import com.anrisoftware.simplerest.oanda.api.Prices;
import com.anrisoftware.simplerest.oanda.core.DefaultPrice;
import com.anrisoftware.simplerest.oanda.rest.NamedListParseResponse.NamedListParseResponseFactory;
import com.anrisoftware.simplerest.oanda.rest.SimpleRequestWorker.SimpleRequestWorkerFactory;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
/**
* Retrieves the instruments prices via the REST API.
*
* @author Erwin Müller, [email protected]
* @since 0.3
*/
public class OandaRestPrices implements Prices {
/**
* Factory to create the retrieving of prices for tradeable instruments via
* the REST API.
*
* @author Erwin Müller, [email protected]
* @since 0.3
*/
public interface OandaRestPricesFactory {
/**
* Creates the retrieving of prices for tradeable instruments via the
* REST API.
*
* @param account
* the OANDA {@link OandaAccount} account.
*
* @param instruments
* the {@link Set} of the {@link Instrument} instruments.
*
* @return the {@link OandaRestPrices}.
*/
OandaRestPrices create(@Assisted OandaAccount account,
@Assisted Set instruments);
/**
* Creates the retrieving of prices for tradeable instruments via the
* REST API.
*
* @param account
* the OANDA {@link OandaAccount} account.
*
* @param instruments
* the {@link Set} of the {@link Instrument} instruments.
*
* @return the {@link OandaRestPrices}.
*/
OandaRestPrices create(@Assisted OandaAccount account,
@Assisted Set instruments,
@Assisted CloseableHttpClient httpClient);
}
private static final String INSTRUMENTS_MESSAGE = "Instruments";
private static final String COMMA = ",";
private static final String INSTRUMENTS_PARAM = "instruments";
private static final String ACCOUNT_ID_PARAM = "accountId";
private static final String ACCOUNT_FIELD = "account";
private static final String PRICES_NAME = "prices";
private final OandaAccount account;
private final TypeReference