Skip to content

Commit 23baad1

Browse files
committed
[paribu] marketdata (ticker only) implementation. Other methods are not supported with the exchange's API
1 parent 8feabb9 commit 23baad1

20 files changed

Lines changed: 558 additions & 0 deletions

File tree

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<module>xchange-vircurex</module>
131131
<module>xchange-yobit</module>
132132
<module>xchange-btcturk</module>
133+
<module>xchange-paribu</module>
133134
</modules>
134135

135136
<repositories>

xchange-examples/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@
347347
<artifactId>xchange-btcturk</artifactId>
348348
<version>${project.version}</version>
349349
</dependency>
350+
<dependency>
351+
<groupId>${project.groupId}</groupId>
352+
<artifactId>xchange-paribu</artifactId>
353+
<version>${project.version}</version>
354+
</dependency>
350355
</dependencies>
351356

352357
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.knowm.xchange.examples.paribu;
2+
3+
import org.knowm.xchange.Exchange;
4+
import org.knowm.xchange.ExchangeFactory;
5+
import org.knowm.xchange.ExchangeSpecification;
6+
import org.knowm.xchange.paribu.ParibuExchange;
7+
8+
/**
9+
* @author semihunaldi
10+
*/
11+
public class ParibuDemoUtils {
12+
public static Exchange createExchange() {
13+
ExchangeSpecification exSpec = new ParibuExchange().getDefaultExchangeSpecification();
14+
return ExchangeFactory.INSTANCE.createExchange(exSpec);
15+
}
16+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.knowm.xchange.examples.paribu.marketdata;
2+
3+
import java.io.IOException;
4+
5+
import org.knowm.xchange.Exchange;
6+
import org.knowm.xchange.currency.CurrencyPair;
7+
import org.knowm.xchange.dto.marketdata.Ticker;
8+
import org.knowm.xchange.examples.paribu.ParibuDemoUtils;
9+
import org.knowm.xchange.paribu.dto.marketdata.ParibuTicker;
10+
import org.knowm.xchange.paribu.service.ParibuMarketDataService;
11+
import org.knowm.xchange.service.marketdata.MarketDataService;
12+
13+
/**
14+
* @author semihunaldi
15+
* Demonstrate requesting Ticker at Paribu. You can access both the raw data from Paribu or the XChange generic DTO data format.
16+
*/
17+
public class ParibuTickerDemo {
18+
19+
public static void main(String[] args) throws IOException {
20+
21+
// Use the factory to get BTCTurk exchange API using default settings
22+
Exchange btcTurk = ParibuDemoUtils.createExchange();
23+
24+
// Interested in the public market data feed (no authentication)
25+
MarketDataService marketDataService = btcTurk.getMarketDataService();
26+
27+
generic(marketDataService);
28+
raw((ParibuMarketDataService) marketDataService);
29+
}
30+
31+
private static void generic(MarketDataService marketDataService) throws IOException {
32+
Ticker ticker = marketDataService.getTicker(CurrencyPair.BTC_TRY);
33+
System.out.println(ticker.toString());
34+
}
35+
36+
private static void raw(ParibuMarketDataService marketDataService) throws IOException {
37+
ParibuTicker btcTurkTicker = marketDataService.getParibuTicker();
38+
System.out.println(btcTurkTicker.toString());
39+
}
40+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
The documentation for Paribu exchange platform
2+
================================
3+
4+
Public API
5+
6+
7+
Documentation
8+
-------------
9+
No documentation
10+
11+
12+
Ticker
13+
------
14+
https://www.paribu.com/ticker

xchange-paribu/pom.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>xchange-parent</artifactId>
7+
<groupId>org.knowm.xchange</groupId>
8+
<version>4.3.1-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>xchange-paribu</artifactId>
13+
14+
<name>XChange Paribu</name>
15+
<description>XChange implementation for the Paribu Exchange</description>
16+
<url>http://knowm.org/open-source/xchange/</url>
17+
<inceptionYear>2012</inceptionYear>
18+
19+
<organization>
20+
<name>Knowm Inc.</name>
21+
<url>http://knowm.org/open-source/xchange/</url>
22+
</organization>
23+
24+
<developers>
25+
<developer>
26+
<name>Semih Unaldi</name>
27+
<email>semihunaldi@gmail.com</email>
28+
</developer>
29+
</developers>
30+
31+
<!-- Parent provides default configuration for dependencies -->
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.knowm.xchange</groupId>
35+
<artifactId>xchange-core</artifactId>
36+
<version>4.3.1-SNAPSHOT</version>
37+
</dependency>
38+
</dependencies>
39+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.knowm.xchange.paribu;
2+
3+
import java.io.IOException;
4+
5+
import javax.ws.rs.GET;
6+
import javax.ws.rs.Path;
7+
import javax.ws.rs.Produces;
8+
import javax.ws.rs.core.MediaType;
9+
10+
import org.knowm.xchange.paribu.dto.marketdata.ParibuTicker;
11+
12+
/**
13+
* @author semihunaldi
14+
*/
15+
16+
@Path("/")
17+
@Produces(MediaType.APPLICATION_JSON)
18+
public interface Paribu {
19+
20+
@GET
21+
@Path("ticker")
22+
ParibuTicker getTicker() throws IOException;
23+
24+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.knowm.xchange.paribu;
2+
3+
import static org.knowm.xchange.currency.Currency.BTC;
4+
import static org.knowm.xchange.currency.Currency.TRY;
5+
6+
import java.math.BigDecimal;
7+
8+
import org.knowm.xchange.currency.Currency;
9+
import org.knowm.xchange.currency.CurrencyPair;
10+
import org.knowm.xchange.dto.marketdata.Ticker;
11+
import org.knowm.xchange.exceptions.NotAvailableFromExchangeException;
12+
import org.knowm.xchange.paribu.dto.marketdata.BTC_TL;
13+
import org.knowm.xchange.paribu.dto.marketdata.ParibuTicker;
14+
15+
/**
16+
* @author semihunaldi
17+
* Various adapters for converting from Paribu DTOs to XChange DTOs
18+
*/
19+
public final class ParibuAdapters {
20+
21+
private ParibuAdapters() {
22+
}
23+
24+
/**
25+
* Adapts a ParibuTicker to a Ticker Object
26+
*
27+
* @param paribuTicker The exchange specific ticker
28+
* @param currencyPair
29+
* @return The ticker
30+
*/
31+
public static Ticker adaptTicker(ParibuTicker paribuTicker, CurrencyPair currencyPair) {
32+
if (!currencyPair.equals(new CurrencyPair(BTC, TRY))) {
33+
throw new NotAvailableFromExchangeException();
34+
}
35+
BTC_TL btcTL = paribuTicker.getBtcTL();
36+
if (btcTL != null) {
37+
BigDecimal last = btcTL.getLast();
38+
BigDecimal lowestAsk = btcTL.getLowestAsk();
39+
BigDecimal highestBid = btcTL.getHighestBid();
40+
BigDecimal volume = btcTL.getVolume();
41+
BigDecimal high24hr = btcTL.getHigh24hr();
42+
BigDecimal low24hr = btcTL.getLow24hr();
43+
return new Ticker.Builder()
44+
.currencyPair(new CurrencyPair(BTC, Currency.TRY))
45+
.last(last)
46+
.bid(highestBid)
47+
.ask(lowestAsk)
48+
.high(high24hr)
49+
.low(low24hr)
50+
.volume(volume).build();
51+
}
52+
return null;
53+
}
54+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.knowm.xchange.paribu;
2+
3+
import org.knowm.xchange.BaseExchange;
4+
import org.knowm.xchange.Exchange;
5+
import org.knowm.xchange.ExchangeSpecification;
6+
import org.knowm.xchange.paribu.service.ParibuMarketDataService;
7+
import org.knowm.xchange.utils.nonce.CurrentTimeNonceFactory;
8+
9+
import si.mazi.rescu.SynchronizedValueFactory;
10+
11+
/**
12+
* @author semihunaldi
13+
*/
14+
public class ParibuExchange extends BaseExchange implements Exchange {
15+
16+
private SynchronizedValueFactory<Long> nonceFactory = new CurrentTimeNonceFactory();
17+
18+
@Override
19+
protected void initServices() {
20+
21+
this.marketDataService = new ParibuMarketDataService(this);
22+
}
23+
24+
@Override
25+
public ExchangeSpecification getDefaultExchangeSpecification() {
26+
27+
ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass().getCanonicalName());
28+
exchangeSpecification.setSslUri("https://www.paribu.com");
29+
exchangeSpecification.setHost("www.paribu.com");
30+
exchangeSpecification.setPort(80);
31+
exchangeSpecification.setExchangeName("Paribu");
32+
exchangeSpecification.setExchangeDescription("Paribu is a Bitcoin exchange registered in Turkey.");
33+
return exchangeSpecification;
34+
}
35+
36+
@Override
37+
public SynchronizedValueFactory<Long> getNonceFactory() {
38+
return nonceFactory;
39+
}
40+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.knowm.xchange.paribu.dto.marketdata;
2+
3+
import java.math.BigDecimal;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
/**
8+
* @author semihunaldi
9+
*/
10+
public final class BTC_TL {
11+
12+
private final BigDecimal last;
13+
private final BigDecimal lowestAsk;
14+
private final BigDecimal highestBid;
15+
private final BigDecimal percentChange;
16+
private final BigDecimal volume;
17+
private final BigDecimal high24hr;
18+
private final BigDecimal low24hr;
19+
20+
public BTC_TL(@JsonProperty("last") BigDecimal last, @JsonProperty("lowestAsk") BigDecimal lowestAsk,
21+
@JsonProperty("highestBid") BigDecimal highestBid, @JsonProperty("percentChange") BigDecimal percentChange,
22+
@JsonProperty("volume") BigDecimal volume, @JsonProperty("high24hr") BigDecimal high24hr, @JsonProperty("low24hr") BigDecimal low24hr) {
23+
this.last = last;
24+
this.lowestAsk = lowestAsk;
25+
this.highestBid = highestBid;
26+
this.percentChange = percentChange;
27+
this.volume = volume;
28+
this.high24hr = high24hr;
29+
this.low24hr = low24hr;
30+
}
31+
32+
public BigDecimal getLast() {
33+
return last;
34+
}
35+
36+
public BigDecimal getLowestAsk() {
37+
return lowestAsk;
38+
}
39+
40+
public BigDecimal getHighestBid() {
41+
return highestBid;
42+
}
43+
44+
public BigDecimal getPercentChange() {
45+
return percentChange;
46+
}
47+
48+
public BigDecimal getVolume() {
49+
return volume;
50+
}
51+
52+
public BigDecimal getHigh24hr() {
53+
return high24hr;
54+
}
55+
56+
public BigDecimal getLow24hr() {
57+
return low24hr;
58+
}
59+
60+
@Override
61+
public String toString() {
62+
return "ParibuTicker {" +
63+
"last=" + last +
64+
", lowestAsk=" + lowestAsk +
65+
", highestBid=" + highestBid +
66+
", percentChange=" + percentChange +
67+
", volume=" + volume +
68+
", high24hr=" + high24hr +
69+
", low24hr=" + low24hr +
70+
'}';
71+
}
72+
}

0 commit comments

Comments
 (0)