initial checkin
This commit is contained in:
commit
206e48c13e
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Maven
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
target
|
||||||
|
|
||||||
|
# Eclipse
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
.settings
|
||||||
|
|
||||||
|
# Visual Studio Code
|
||||||
|
.factorypath
|
||||||
|
|
64
polygon-public-rest-api/pom.xml
Normal file
64
polygon-public-rest-api/pom.xml
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.inteligr8.polygon</groupId>
|
||||||
|
<artifactId>polygon-public-rest-api</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>Polygon.IO ReST API for Java</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.ws.rs</groupId>
|
||||||
|
<artifactId>jakarta.ws.rs-api</artifactId>
|
||||||
|
<version>2.1.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.module</groupId>
|
||||||
|
<artifactId>jackson-module-jaxb-annotations</artifactId>
|
||||||
|
<version>2.12.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>javadoc</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals><goal>jar</goal></goals>
|
||||||
|
<configuration>
|
||||||
|
<show>public</show>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>inteligr8-public</id>
|
||||||
|
<url>https://repos.inteligr8.com/nexus/repository/inteligr8-public</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>inteligr8-releases</id>
|
||||||
|
<url>https://repos.inteligr8.com/nexus/repository/inteligr8-public</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>inteligr8-snapshots</id>
|
||||||
|
<url>https://repos.inteligr8.com/nexus/repository/inteligr8-snapshots</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
</project>
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.inteligr8.polygon;
|
||||||
|
|
||||||
|
import com.inteligr8.polygon.api.StocksApiV1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface consolidates the JAX-RS APIs available in the Polygon.IO
|
||||||
|
* Public ReST API.
|
||||||
|
*
|
||||||
|
* @author brian@inteligr8.com
|
||||||
|
*/
|
||||||
|
public interface PolygonPublicRestApi {
|
||||||
|
|
||||||
|
StocksApiV1 getStocksApi();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.inteligr8.polygon.api;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.inteligr8.polygon.model.StockDateSummary;
|
||||||
|
|
||||||
|
@Path("/v1")
|
||||||
|
public interface StocksApiV1 {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/open-close/{stocksTicker}/{date}")
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
public StockDateSummary getStockSummaryOnDate(
|
||||||
|
@PathParam("stocksTicker") String stockTicker,
|
||||||
|
@PathParam("date") @JsonFormat(pattern = "yyyy-MM-dd") LocalDate date);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/open-close/{stocksTicker}/{date}")
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
public StockDateSummary getStockSummaryOnDate(
|
||||||
|
@PathParam("stocksTicker") String stockTicker,
|
||||||
|
@PathParam("date") @JsonFormat(pattern = "yyyy-MM-dd") LocalDate date,
|
||||||
|
@QueryParam("adjusted") boolean adjusted);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.inteligr8.polygon.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
public class BaseResponse {
|
||||||
|
|
||||||
|
public enum Status {
|
||||||
|
@JsonProperty("OK")
|
||||||
|
Ok
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private Status status;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Status getStatus() {
|
||||||
|
return this.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Status status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,117 @@
|
|||||||
|
package com.inteligr8.polygon.model;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author brian@inteligr8.com
|
||||||
|
*/
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class StockDateSummary extends BaseResponse {
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private String symbol;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private Double preMarket;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private Double open;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private Double high;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private Double low;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private Double close;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private Long volume;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private Double afterHours;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
|
private LocalDate from;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getSymbol() {
|
||||||
|
return this.symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSymbol(String symbol) {
|
||||||
|
this.symbol = symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getPreMarket() {
|
||||||
|
return this.preMarket;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreMarket(Double preMarket) {
|
||||||
|
this.preMarket = preMarket;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getOpen() {
|
||||||
|
return this.open;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpen(Double open) {
|
||||||
|
this.open = open;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getHigh() {
|
||||||
|
return this.high;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHigh(Double high) {
|
||||||
|
this.high = high;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getLow() {
|
||||||
|
return this.low;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLow(Double low) {
|
||||||
|
this.low = low;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getClose() {
|
||||||
|
return this.close;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClose(Double close) {
|
||||||
|
this.close = close;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getVolume() {
|
||||||
|
return this.volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVolume(Long volume) {
|
||||||
|
this.volume = volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getAfterHours() {
|
||||||
|
return this.afterHours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAfterHours(Double afterHours) {
|
||||||
|
this.afterHours = afterHours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getFrom() {
|
||||||
|
return this.from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFrom(LocalDate from) {
|
||||||
|
this.from = from;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
3
polygon-public-rest-client/.gitignore
vendored
Normal file
3
polygon-public-rest-client/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Personal
|
||||||
|
polygon-personal.properties
|
||||||
|
|
205
polygon-public-rest-client/pom.xml
Normal file
205
polygon-public-rest-client/pom.xml
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.inteligr8.polygon</groupId>
|
||||||
|
<artifactId>polygon-public-rest-client</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>Polygon.IO ReST Client for Java</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
|
||||||
|
<jaxrs.impl>jersey</jaxrs.impl>
|
||||||
|
|
||||||
|
<junit.version>5.7.2</junit.version>
|
||||||
|
<spring.version>5.2.14.RELEASE</spring.version>
|
||||||
|
|
||||||
|
<api.model.disabled>false</api.model.disabled>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.inteligr8</groupId>
|
||||||
|
<artifactId>common-rest-api</artifactId>
|
||||||
|
<version>1.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.inteligr8.polygon</groupId>
|
||||||
|
<artifactId>polygon-public-rest-api</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
<version>2.12.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
<version>${spring.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>4.5.9</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>build-helper-maven-plugin</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>add-jaxrs-src</id>
|
||||||
|
<goals><goal>add-source</goal></goals>
|
||||||
|
<configuration>
|
||||||
|
<sources>
|
||||||
|
<source>src/main/${jaxrs.impl}</source>
|
||||||
|
</sources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>add-test-src</id>
|
||||||
|
<goals><goal>add-test-source</goal></goals>
|
||||||
|
<configuration>
|
||||||
|
<sources>
|
||||||
|
<source>src/test/${jaxrs.impl}</source>
|
||||||
|
</sources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<classifier>${jaxrs.impl}</classifier>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.0.0-M5</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-failsafe-plugin</artifactId>
|
||||||
|
<version>3.0.0-M5</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>jersey-impl</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
<property>
|
||||||
|
<name>jaxrs.impl</name>
|
||||||
|
<value>jersey</value>
|
||||||
|
</property>
|
||||||
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<jaxrs.impl>jersey</jaxrs.impl>
|
||||||
|
<jersey.version>2.34</jersey.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.core</groupId>
|
||||||
|
<artifactId>jersey-client</artifactId>
|
||||||
|
<version>${jersey.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.ext</groupId>
|
||||||
|
<artifactId>jersey-proxy-client</artifactId>
|
||||||
|
<version>${jersey.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.inject</groupId>
|
||||||
|
<artifactId>jersey-hk2</artifactId>
|
||||||
|
<version>${jersey.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.media</groupId>
|
||||||
|
<artifactId>jersey-media-json-jackson</artifactId>
|
||||||
|
<version>${jersey.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>cxf-impl</id>
|
||||||
|
<activation>
|
||||||
|
<property>
|
||||||
|
<name>jaxrs.impl</name>
|
||||||
|
<value>cxf</value>
|
||||||
|
</property>
|
||||||
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<jaxrs.impl>cxf</jaxrs.impl>
|
||||||
|
<cxf.version>3.3.2</cxf.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.cxf</groupId>
|
||||||
|
<artifactId>cxf-rt-rs-client</artifactId>
|
||||||
|
<version>${cxf.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>inteligr8-public</id>
|
||||||
|
<url>https://repos.inteligr8.com/nexus/repository/inteligr8-public</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>inteligr8-public</id>
|
||||||
|
<url>https://repos.inteligr8.com/nexus/repository/inteligr8-public</url>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>inteligr8-releases</id>
|
||||||
|
<url>https://repos.inteligr8.com/nexus/repository/inteligr8-public</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>inteligr8-snapshots</id>
|
||||||
|
<url>https://repos.inteligr8.com/nexus/repository/inteligr8-snapshots</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
</project>
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.inteligr8.polygon;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.inteligr8.rs.ClientCxfConfiguration;
|
||||||
|
import com.inteligr8.rs.ClientCxfImpl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides a POJO & Spring-based implementation of the Apache
|
||||||
|
* CXF client. You can use it outside of the Spring context, but you will need
|
||||||
|
* the spring-context and spring-beans libraries in your non-Spring
|
||||||
|
* application.
|
||||||
|
*
|
||||||
|
* @author brian@inteligr8.com
|
||||||
|
*/
|
||||||
|
@Component("polygon.client")
|
||||||
|
@Lazy
|
||||||
|
public class PolygonClientCxfImpl extends ClientCxfImpl {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PolygonClientConfiguration config;
|
||||||
|
|
||||||
|
private final PolygonPublicRestApi api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructor is for Spring use.
|
||||||
|
*/
|
||||||
|
protected PolygonClientCxfImpl() {
|
||||||
|
this.api = new PolygonPublicRestApiImpl(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructor is for POJO use.
|
||||||
|
* @param config
|
||||||
|
*/
|
||||||
|
public PolygonClientCxfImpl(PolygonClientConfiguration config) {
|
||||||
|
this.config = config;
|
||||||
|
this.api = new PolygonPublicRestApiImpl(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ClientCxfConfiguration getConfig() {
|
||||||
|
return this.config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PolygonPublicRestApi getApi() {
|
||||||
|
return this.api;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.inteligr8.polygon;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.ws.rs.client.ClientRequestContext;
|
||||||
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
import javax.ws.rs.core.UriBuilder;
|
||||||
|
|
||||||
|
import com.inteligr8.rs.AuthorizationFilter;
|
||||||
|
|
||||||
|
public class PolygonAuthorizationFilter implements AuthorizationFilter {
|
||||||
|
|
||||||
|
private String apiKey;
|
||||||
|
|
||||||
|
public PolygonAuthorizationFilter(String apiKey) {
|
||||||
|
this.apiKey = apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void filter(ClientRequestContext requestContext) throws IOException {
|
||||||
|
this.authWithHeader(requestContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void authWithHeader(ClientRequestContext requestContext) {
|
||||||
|
requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION, "Bearer " + this.apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void authWithQueryParam(ClientRequestContext requestContext) {
|
||||||
|
requestContext.setUri(
|
||||||
|
UriBuilder.fromUri(requestContext.getUri())
|
||||||
|
.queryParam("apiKey", this.apiKey)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package com.inteligr8.polygon;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import com.inteligr8.rs.AuthorizationFilter;
|
||||||
|
import com.inteligr8.rs.ClientCxfConfiguration;
|
||||||
|
import com.inteligr8.rs.ClientJerseyConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides a POJO & Spring-based implementation of the
|
||||||
|
* ClientConfiguration interface. You can use it outside of the Spring
|
||||||
|
* context, but you will need the spring-context and spring-beans libraries in
|
||||||
|
* your non-Spring application.
|
||||||
|
*
|
||||||
|
* @author brian@inteligr8.com
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan
|
||||||
|
public class PolygonClientConfiguration implements ClientCxfConfiguration, ClientJerseyConfiguration {
|
||||||
|
|
||||||
|
@Value("${polygon.service.baseUrl:https://api.polygon.io}")
|
||||||
|
private String baseUrl;
|
||||||
|
|
||||||
|
@Value("${polygon.service.security.auth.apiKey}")
|
||||||
|
private String apiKey;
|
||||||
|
|
||||||
|
@Value("${polygon.service.cxf.defaultBusEnabled:true}")
|
||||||
|
private boolean defaultBusEnabled;
|
||||||
|
|
||||||
|
@Value("${polygon.service.jersey.putBodyRequired:true}")
|
||||||
|
private boolean putBodyRequired;
|
||||||
|
|
||||||
|
public String getBaseUrl() {
|
||||||
|
return this.baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBaseUrl(String baseUrl) {
|
||||||
|
this.baseUrl = baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getApiKey() {
|
||||||
|
return this.apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApiKey(String apiKey) {
|
||||||
|
this.apiKey = apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDefaultBusEnabled() {
|
||||||
|
return this.defaultBusEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultBusEnabled(boolean defaultBusEnabled) {
|
||||||
|
this.defaultBusEnabled = defaultBusEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPutBodyRequired() {
|
||||||
|
return this.putBodyRequired;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPutBodyRequired(boolean putBodyRequired) {
|
||||||
|
this.putBodyRequired = putBodyRequired;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthorizationFilter createAuthorizationFilter() {
|
||||||
|
return new PolygonAuthorizationFilter(this.getApiKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.inteligr8.polygon;
|
||||||
|
|
||||||
|
import com.inteligr8.polygon.api.StocksApiV1;
|
||||||
|
import com.inteligr8.rs.Client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class serves as the entrypoint to the JAX-RS API for the Polygon.IO
|
||||||
|
* Public ReST API.
|
||||||
|
*
|
||||||
|
* @author brian@inteligr8.com
|
||||||
|
*/
|
||||||
|
public class PolygonPublicRestApiImpl implements PolygonPublicRestApi {
|
||||||
|
|
||||||
|
private final Client client;
|
||||||
|
|
||||||
|
public PolygonPublicRestApiImpl(Client client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final <T> T getApi(Class<T> apiClass) {
|
||||||
|
return this.client.getApi(apiClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StocksApiV1 getStocksApi() {
|
||||||
|
return this.getApi(StocksApiV1.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.inteligr8.polygon;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.inteligr8.rs.ClientJerseyConfiguration;
|
||||||
|
import com.inteligr8.rs.ClientJerseyImpl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides a POJO & Spring-based implementation of the Jersey
|
||||||
|
* client. You can use it outside of the Spring context, but you will need the
|
||||||
|
* spring-context and spring-beans libraries in your non-Spring application.
|
||||||
|
*
|
||||||
|
* @author brian@inteligr8.com
|
||||||
|
*/
|
||||||
|
@Component("polygon.client")
|
||||||
|
@Lazy
|
||||||
|
public class PolygonClientJerseyImpl extends ClientJerseyImpl {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PolygonClientConfiguration config;
|
||||||
|
|
||||||
|
private final PolygonPublicRestApi api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructor is for Spring use.
|
||||||
|
*/
|
||||||
|
protected PolygonClientJerseyImpl() {
|
||||||
|
this.api = new PolygonPublicRestApiImpl(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructor is for POJO use.
|
||||||
|
* @param config
|
||||||
|
*/
|
||||||
|
public PolygonClientJerseyImpl(PolygonClientConfiguration config) {
|
||||||
|
this.config = config;
|
||||||
|
this.api = new PolygonPublicRestApiImpl(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ClientJerseyConfiguration getConfig() {
|
||||||
|
return this.config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PolygonPublicRestApi getApi() {
|
||||||
|
return this.api;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.inteligr8.polygon;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.TestPropertySource;
|
||||||
|
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||||
|
|
||||||
|
import com.inteligr8.rs.ClientConfiguration;
|
||||||
|
|
||||||
|
@TestPropertySource(locations = {"/polygon-personal.properties"})
|
||||||
|
@SpringJUnitConfig(classes = {PolygonClientConfiguration.class, PolygonClientCxfImpl.class})
|
||||||
|
public class ConnectionCxfClientIT extends ConnectionClientIT {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PolygonClientCxfImpl client;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PolygonPublicRestApi getClient() {
|
||||||
|
return this.client.getApi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClientConfiguration getConfiguration() {
|
||||||
|
return this.client.getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.inteligr8.polygon;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpUriRequest;
|
||||||
|
import org.apache.http.client.methods.RequestBuilder;
|
||||||
|
import org.apache.http.impl.client.DefaultRedirectStrategy;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
|
||||||
|
import com.inteligr8.rs.ClientConfiguration;
|
||||||
|
|
||||||
|
public abstract class ConditionalIT {
|
||||||
|
|
||||||
|
public abstract ClientConfiguration getConfiguration();
|
||||||
|
|
||||||
|
public boolean hostExists() {
|
||||||
|
String uri = this.getConfiguration().getBaseUrl();
|
||||||
|
|
||||||
|
HttpUriRequest request = RequestBuilder.get()
|
||||||
|
.setUri(uri)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpClient client = HttpClientBuilder.create()
|
||||||
|
.setRedirectStrategy(DefaultRedirectStrategy.INSTANCE)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpResponse response = client.execute(request);
|
||||||
|
return response.getStatusLine().getStatusCode() < 300 ||
|
||||||
|
response.getStatusLine().getStatusCode() == Status.NOT_FOUND.getStatusCode();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
package com.inteligr8.polygon;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import javax.ws.rs.BadRequestException;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
|
import org.junit.jupiter.api.function.Executable;
|
||||||
|
|
||||||
|
import com.inteligr8.polygon.api.StocksApiV1;
|
||||||
|
import com.inteligr8.polygon.model.StockDateSummary;
|
||||||
|
|
||||||
|
public abstract class ConnectionClientIT extends ConditionalIT {
|
||||||
|
|
||||||
|
public abstract PolygonPublicRestApi getClient();
|
||||||
|
|
||||||
|
private StocksApiV1 api;
|
||||||
|
|
||||||
|
public boolean fullTest() {
|
||||||
|
return false;
|
||||||
|
//return this.hostExists();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void getApi() {
|
||||||
|
this.api = this.getClient().getStocksApi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledIf("fullTest")
|
||||||
|
public void testValidTickerToday() {
|
||||||
|
Assertions.assertThrows(BadRequestException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
api.getStockSummaryOnDate("AAPL", LocalDate.now());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledIf("fullText")
|
||||||
|
public void testValidTicketTomorrow() {
|
||||||
|
Assertions.assertThrows(BadRequestException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
api.getStockSummaryOnDate("AAPL", LocalDate.now().plusDays(1L));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledIf("fullTest")
|
||||||
|
public void testValidTickerYesterday() {
|
||||||
|
StockDateSummary summary = this.api.getStockSummaryOnDate("AAPL", LocalDate.now().minusDays(1L));
|
||||||
|
this.assertStockDateSummary(summary);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnabledIf("fullTest")
|
||||||
|
public void testInvalidTicker() {
|
||||||
|
Assertions.assertThrows(BadRequestException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
api.getStockSummaryOnDate("NOT-A-TICKER", LocalDate.now().plusDays(1L));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertStockDateSummary(StockDateSummary summary) {
|
||||||
|
Assertions.assertNotNull(summary);
|
||||||
|
Assertions.assertEquals("AAPL", summary.getSymbol());
|
||||||
|
Assertions.assertNotNull(summary.getOpen());
|
||||||
|
Assertions.assertNotNull(summary.getHigh());
|
||||||
|
Assertions.assertNotNull(summary.getLow());
|
||||||
|
Assertions.assertNotNull(summary.getClose());
|
||||||
|
Assertions.assertTrue(summary.getLow() <= summary.getHigh());
|
||||||
|
Assertions.assertTrue(summary.getLow() <= summary.getClose());
|
||||||
|
Assertions.assertTrue(summary.getLow() <= summary.getOpen());
|
||||||
|
Assertions.assertTrue(summary.getClose() <= summary.getHigh());
|
||||||
|
Assertions.assertTrue(summary.getOpen() <= summary.getHigh());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.inteligr8.polygon;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.TestPropertySource;
|
||||||
|
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||||
|
|
||||||
|
import com.inteligr8.rs.ClientConfiguration;
|
||||||
|
|
||||||
|
@TestPropertySource(locations = {"/polygon-personal.properties"})
|
||||||
|
@SpringJUnitConfig(classes = {PolygonClientConfiguration.class, PolygonClientJerseyImpl.class})
|
||||||
|
public class ConnectionJerseyClientIT extends ConnectionClientIT {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PolygonClientJerseyImpl client;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PolygonPublicRestApi getClient() {
|
||||||
|
return this.client.getApi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClientConfiguration getConfiguration() {
|
||||||
|
return this.client.getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user