Browse Source

First OSSRH config (#6)

master
Taylor Bockman 6 years ago committed by GitHub
parent
commit
f105c25012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      CONTRIBUTING.md
  2. 21
      README.md
  3. 88
      build.gradle
  4. 11
      src/main/java/com/sigmaflare/binancej/BaseBinanceApi.java
  5. 4
      src/main/java/com/sigmaflare/binancej/HttpRequests.java

3
CONTRIBUTING.md

@ -44,8 +44,6 @@ maintain, and track please use the format `<name-id>-<ticket-or-feature-name>`.
* `<name-id>`: I could use either `ag` (for "angrygoats") or `tb` (for "Taylor Bockman"). Both allow someone to quickly know who owns the branch.
* `<ticket-or-feature-name>`: If the ticket/feature has an associated issue/ticket number please include it in the branch name. Otherwise an accurate description of the feature is sufficient.
## Testing
We operate a strict TDD shop here. As a result, any PR submitted without tests for anything but _the most trivial_ of
@ -62,7 +60,6 @@ gradle test
from the root of the project.
## Code Standards
Clean Java is good Java. As all of us know Java can get unnecessarily verbose at times, and in order to keep readability

21
README.md

@ -5,6 +5,22 @@
A Java 8 implementation of the [Binance API Specification](https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md).
## Getting BinanceJ
### Maven
```
<dependency>
<groupId>com.sigmaflare</groupId>
<artifactId>binancej</artifactId>
<version>1.0.2</version>
</dependency>
```
### Gradle
`compile group: 'com.sigmaflare', name: 'binancej', version: '1.0.2'`
## Licensing
BinanceJ is released under the MIT license.
@ -50,6 +66,11 @@ component so you can check the specifics against the [Binance Error Documentatio
In the event an unknown error occurs, the code will throw an `UnexpectedErrorException`. These are generally complete showstoppers.
## Notes
Be sure to call `close` on the API container class (`GeneralUtilities`, `MarketData`, etc) in order to close the
`CloseableHttpClient` resource.
## Examples
### Server alive check with ping

88
build.gradle

@ -1,13 +1,46 @@
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'com.github.ethankhall.semantic-versioning' version "1.1.0" apply true
id 'maven'
id 'signing'
}
group = "com.sigmaflare"
archivesBaseName = "binancej"
version = '1.0.2-SNAPSHOT'
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
// Add default values for OSSRH
if (!project.hasProperty("ossrhUsername")) {
ext.ossrhUsername = ""
}
if(!project.hasProperty("ossrhPassword")) {
ext.ossrhPassword = ""
}
project.version.with { major = 1; minor= 0; patch = 1 }
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives javadocJar, sourcesJar
}
dependencies {
compile group: 'org.projectlombok', name: 'lombok', version: '1.16.20'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.5'
@ -25,7 +58,54 @@ dependencies {
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.18.3'
}
repositories {
mavenCentral()
signing {
sign configurations.archives
}
tasks.withType(Sign) {
onlyIf { isReleaseVersion }
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'BinanceJ'
packaging 'jar'
// optionally artifactId can be defined here
description 'A java implementation of the Binance API Specification'
url 'https://github.com/angrygoats/binancej'
scm {
url 'https://github.com/angrygoats/binancej'
}
licenses {
license {
name 'MIT License'
url 'https://opensource.org/licenses/MIT'
}
}
developers {
developer {
id 'angrygoats'
name 'Taylor Bockman'
email 'tbockman@xchg.sh'
}
}
}
}
}
}

11
src/main/java/com/sigmaflare/binancej/BaseBinanceApi.java

@ -7,6 +7,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
import java.io.IOException;
public abstract class BaseBinanceApi {
protected final String apiKey;
protected final String secretKey;
@ -26,13 +27,11 @@ public abstract class BaseBinanceApi {
this.closeableHttpClient = closeableHttpClient;
}
/**
* Closes the CloseableHttpClient instance.
* @throws IOException If closing fails
*/
public void close() throws IOException {
closeableHttpClient.close();
}
@Override
protected void finalize() throws IOException {
close();
}
}

4
src/main/java/com/sigmaflare/binancej/HttpRequests.java

@ -90,6 +90,10 @@ public final class HttpRequests {
/**
* A simple function to consolidate the creation of common HTTP exceptions
* @param statusCode The status code to build the exception for
* @param error The ServiceError object returned from Binance to use to build the exception
* @return A BinanceServiceException based on the provided statusCode argument
* @throws IllegalArgumentException If the statusCode is below 400
*/
public static BinanceServiceException buildHttpException(int statusCode, ServiceError error) {
if(statusCode < 400) {

Loading…
Cancel
Save