-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add history candlesticks api for java
- Loading branch information
Showing
4 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.github.longportapp</groupId> | ||
<artifactId>history_candlesticks</artifactId> | ||
<version>0.0.1</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.longportapp</groupId> | ||
<artifactId>openapi-sdk</artifactId> | ||
<version>LATEST</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.10.1</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>3.0.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>exec</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<executable>java</executable> | ||
<arguments> | ||
<argument>-classpath</argument> | ||
<classpath /> | ||
<argument>Main</argument> | ||
</arguments> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<properties> | ||
<java.version>1.11</java.version> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding> | ||
</properties> | ||
</project> |
30 changes: 30 additions & 0 deletions
30
examples/java/history_candlesticks/src/main/java/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import java.time.LocalDateTime; | ||
import java.time.LocalDate; | ||
import java.util.Arrays; | ||
|
||
import com.longport.*; | ||
import com.longport.quote.*; | ||
|
||
class Main { | ||
public static void main(String[] args) throws Exception { | ||
try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { | ||
System.out.println("get candlesticks by offset"); | ||
System.out.println("===================="); | ||
|
||
Candlestick[] candlesticks = ctx | ||
.getHistoryCandlesticksByOffset("700.HK", Period.Day, AdjustType.NoAdjust, false, | ||
LocalDateTime.of(2023, 8, 18, 0, 0, 0, 0), 10) | ||
.get(); | ||
System.out.println(Arrays.toString(candlesticks)); | ||
|
||
System.out.println("get candlesticks by date"); | ||
System.out.println("===================="); | ||
|
||
Candlestick[] candlesticks2 = ctx | ||
.getHistoryCandlesticksByDate("700.HK", Period.Day, AdjustType.NoAdjust, | ||
LocalDate.of(2022, 5, 5), LocalDate.of(2022, 6, 23)) | ||
.get(); | ||
System.out.println(Arrays.toString(candlesticks2)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,30 @@ | ||
import java.time.LocalDateTime; | ||
import java.time.LocalDate; | ||
import java.util.Arrays; | ||
|
||
import com.longport.*; | ||
import com.longport.trade.*; | ||
import com.longport.quote.*; | ||
import java.math.BigDecimal; | ||
import java.util.Arrays; | ||
|
||
class Main { | ||
public static void main(String[] args) throws Exception { | ||
try (Config config = Config.fromEnv(); QuoteContext ctx = QuoteContext.create(config).get()) { | ||
SecurityStaticInfo[] resp = ctx.getStaticInfo(new String[] { "700.HK", "AAPL.US", "TSLA.US", "NFLX.US" }) | ||
System.out.println("get candlesticks by offset"); | ||
System.out.println("===================="); | ||
|
||
Candlestick[] candlesticks = ctx | ||
.getHistoryCandlesticksByOffset("700.HK", Period.Day, AdjustType.NoAdjust, false, | ||
LocalDateTime.of(2023, 8, 18, 0, 0, 0, 0), 10) | ||
.get(); | ||
System.out.println(Arrays.toString(candlesticks)); | ||
|
||
System.out.println("get candlesticks by date"); | ||
System.out.println("===================="); | ||
|
||
Candlestick[] candlesticks2 = ctx | ||
.getHistoryCandlesticksByDate("700.HK", Period.Day, AdjustType.NoAdjust, | ||
LocalDate.of(2022, 5, 5), LocalDate.of(2022, 6, 23)) | ||
.get(); | ||
System.out.println(Arrays.toString(resp)); | ||
System.out.println(Arrays.toString(candlesticks2)); | ||
} | ||
} | ||
} |