Skip to content

Commit

Permalink
BPUB-204 poloniex exchange integration
Browse files Browse the repository at this point in the history
  • Loading branch information
kubacech committed Jan 25, 2021
1 parent a04adfb commit 76e4ea7
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 8 deletions.
1 change: 1 addition & 0 deletions dependencyChecksums.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ verifyModule 'org.knowm.xchange:xchange-dvchain:4.4.2:3cbe4f9863f1922edcddffffb2
verifyModule 'org.knowm.xchange:xchange-enigma:4.4.2:603cb05e4d852eafcf75832ba3d01e32faf0b57f10f6e607521edbe523af9491'
verifyModule 'org.knowm.xchange:xchange-hitbtc:4.4.2:2dfb6912eab2fe50032ca292cc3c6eae89b4fd7d6b489b3095cc986ce5ef28d7'
verifyModule 'org.knowm.xchange:xchange-itbit:4.4.2:a79a5982f047a1432b278715978f3804a4be901f5966a4c0491b8ce049d167c0'
verifyModule 'org.knowm.xchange:xchange-poloniex:4.4.2:19fc5d520c25b509f8a3deed54dc5294e33ed8db7026e90552267d567b8c1ecf'
verifyModule 'org.litecoinj:core:0.15.1.20190418:1eee20226aa76269601f1aa1f22d3980d1833c01b93112504e3c7ed4b972bbbe'
verifyModule 'org.ow2.asm:asm-analysis:5.0.3:e8fa2a63462c96557dcd36c25525e1264b77366ff851cf0b94eb7592b290849d'
verifyModule 'org.ow2.asm:asm-commons:5.0.3:18c1e092230233c9d29e46f21943d769bdb48130cc279e4b0e663f423948c2da'
Expand Down
2 changes: 1 addition & 1 deletion dependencySubstitutions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ substitute module: 'com.google.protobuf:protobuf-java', versions: ['2.6.1'], toV
substitute module: 'com.madgag.spongycastle:core', versions: ['1.51.0.0'], toVersion: '1.52.0.0'
substitute module: 'com.squareup.okhttp3:okhttp', versions: ['3.8.1', '3.12.1'], toVersion: '3.14.2'
substitute module: 'com.squareup.okio:okio', versions: ['1.6.0'], toVersion: '1.17.2'
substitute module: 'commons-codec:commons-codec', versions: ['1.3', '1.9', '1.10'], toVersion: '1.11'
substitute module: 'commons-codec:commons-codec', versions: ['1.3', '1.9'], toVersion: '1.11'
substitute module: 'commons-io:commons-io', versions: ['2.5'], toVersion: '2.6'
substitute module: 'org.apache.commons:commons-lang3', versions: ['3.5'], toVersion: '3.9'
substitute module: 'org.bouncycastle:bcprov-jdk15on', versions: ['1.54', '1.60'], toVersion: '1.63'
Expand Down
1 change: 1 addition & 0 deletions server_extensions_extra/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies {
compile(group: 'org.knowm.xchange', name: 'xchange-coinbasepro', version: '4.4.2')
compile(group: 'org.knowm.xchange', name: 'xchange-coingi', version: '4.4.2')
compile(group: 'org.knowm.xchange', name: 'xchange-enigma', version: '4.4.2')
compile(group: 'org.knowm.xchange', name: 'xchange-poloniex', version: '4.4.2')
compile(group: 'org.web3j', name: 'core', version: '3.6.0')
compile(group: 'org.web3j', name: 'crypto', version: '3.6.0')
compile(group: 'org.web3j', name: 'utils', version: '3.6.0')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges.hitbtc.HitbtcExchange;
import com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges.itbit.ItBitExchange;
import com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges.enigma.EnigmaExchange;
import com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges.poloniex.PoloniexExchange;
import com.generalbytes.batm.server.extensions.extra.bitcoin.paymentprocessors.bitcoinpay.BitcoinPayPP;
import com.generalbytes.batm.server.extensions.extra.bitcoin.paymentprocessors.coinofsale.CoinOfSalePP;
import com.generalbytes.batm.server.extensions.extra.bitcoin.sources.bitkub.BitKubRateSource;
Expand Down Expand Up @@ -196,6 +197,14 @@ public IExchange createExchange(String paramString) // (Bitstamp is in built-in
preferredFiatCurrency = paramTokenizer.nextToken().toUpperCase();
}
return BitpandaProExchange.asExchange(apikey, preferredFiatCurrency);
} else if ("poloniex".equalsIgnoreCase(prefix)) {
String preferredFiatCurrency = FiatCurrency.USD.getCode();
String key = paramTokenizer.nextToken();
String secret = paramTokenizer.nextToken();
if (paramTokenizer.hasMoreTokens()) {
preferredFiatCurrency = paramTokenizer.nextToken().toUpperCase();
}
return new PoloniexExchange(key, secret, preferredFiatCurrency);
}
}
return null;
Expand Down Expand Up @@ -490,6 +499,12 @@ public IRateSource createRateSource(String sourceLogin) {
preferredFiatCurrency = st.nextToken().toUpperCase();
}
return BitpandaProExchange.asRateSource(preferredFiatCurrency);
} else if ("poloniex".equals(rsType)) {
String preferredFiatCurrency = FiatCurrency.USD.getCode();
if (st.hasMoreTokens()) {
preferredFiatCurrency = st.nextToken().toUpperCase();
}
return new PoloniexExchange(preferredFiatCurrency);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ public BigDecimal call() throws Exception {

try {
return getExchange().getMarketDataService()
.getTicker(new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrency))
.getTicker(new CurrencyPair(
translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency),
translateFiatCurrencySymbolToExchangeSpecificSymbol(fiatCurrency)))
.getLast();
} catch (ExchangeException e) {
log.error("Error", e);
Expand Down Expand Up @@ -259,7 +261,10 @@ public String purchaseCoins(BigDecimal amount, String cryptoCurrency, String fia
try {
log.debug("AccountInfo as String: {}", accountService.getAccountInfo());

CurrencyPair currencyPair = new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrencyToUse);
CurrencyPair currencyPair = new CurrencyPair(
translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency),
translateFiatCurrencySymbolToExchangeSpecificSymbol(fiatCurrencyToUse)
);

OrderBook orderBook = marketDataService.getOrderBook(currencyPair);
List<LimitOrder> asks = orderBook.getAsks();
Expand Down Expand Up @@ -397,7 +402,10 @@ public String sellCoins(BigDecimal cryptoAmount, String cryptoCurrency, String f
try {
log.debug("AccountInfo as String: {}", accountService.getAccountInfo());

CurrencyPair currencyPair = new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrencyToUse);
CurrencyPair currencyPair = new CurrencyPair(
translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency),
translateFiatCurrencySymbolToExchangeSpecificSymbol(fiatCurrencyToUse)
);

OrderBook orderBook = marketDataService.getOrderBook(currencyPair);
List<LimitOrder> bids = orderBook.getBids();
Expand Down Expand Up @@ -507,7 +515,10 @@ public BigDecimal calculateBuyPrice(String cryptoCurrency, String fiatCurrency,
rateLimiter.acquire();
MarketDataService marketDataService = getExchange().getMarketDataService();
try {
CurrencyPair currencyPair = new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrency);
CurrencyPair currencyPair = new CurrencyPair(
translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency),
translateFiatCurrencySymbolToExchangeSpecificSymbol(fiatCurrency)
);
OrderBook orderBook = marketDataService.getOrderBook(currencyPair);
List<LimitOrder> asks = orderBook.getAsks();
BigDecimal targetAmount = cryptoAmount;
Expand Down Expand Up @@ -555,7 +566,9 @@ public BigDecimal calculateSellPrice(String cryptoCurrency, String fiatCurrency,
rateLimiter.acquire();
MarketDataService marketDataService = getExchange().getMarketDataService();
try {
CurrencyPair currencyPair = new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrency);
CurrencyPair currencyPair = new CurrencyPair(
translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency),
translateFiatCurrencySymbolToExchangeSpecificSymbol(fiatCurrency));

OrderBook orderBook = marketDataService.getOrderBook(currencyPair);
List<LimitOrder> bids = orderBook.getBids();
Expand Down Expand Up @@ -619,7 +632,10 @@ public boolean onCreate() {
try {
log.debug("AccountInfo as String: {}", accountService.getAccountInfo());

CurrencyPair currencyPair = new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrencyToUse);
CurrencyPair currencyPair = new CurrencyPair(
translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency),
translateFiatCurrencySymbolToExchangeSpecificSymbol(fiatCurrencyToUse)
);

OrderBook orderBook = marketDataService.getOrderBook(currencyPair);
List<LimitOrder> asks = orderBook.getAsks();
Expand Down Expand Up @@ -748,7 +764,10 @@ public boolean onCreate() {
try {
log.debug("AccountInfo as String: {}", accountService.getAccountInfo());

CurrencyPair currencyPair = new CurrencyPair(translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency), fiatCurrencyToUse);
CurrencyPair currencyPair = new CurrencyPair(
translateCryptoCurrencySymbolToExchangeSpecificSymbol(cryptoCurrency),
translateFiatCurrencySymbolToExchangeSpecificSymbol(fiatCurrencyToUse)
);

OrderBook orderBook = marketDataService.getOrderBook(currencyPair);
List<LimitOrder> bids = orderBook.getBids();
Expand Down Expand Up @@ -869,4 +888,8 @@ public String getPreferredFiatCurrency() {
protected String translateCryptoCurrencySymbolToExchangeSpecificSymbol(String from) {
return from;
}

protected String translateFiatCurrencySymbolToExchangeSpecificSymbol(String currency) {
return currency;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*************************************************************************************
* Copyright (C) 2014-2021 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
* Foundation and appearing in the file GPL2.TXT included in the packaging of
* this file. Please note that GPL2 Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL2 ("Copyleft").
*
* Contact information
* -------------------
*
* GENERAL BYTES s.r.o.
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges.poloniex;

import com.generalbytes.batm.common.currencies.CryptoCurrency;
import com.generalbytes.batm.common.currencies.FiatCurrency;
import com.generalbytes.batm.server.extensions.extra.bitcoin.exchanges.XChangeExchange;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.dto.account.AccountInfo;
import org.knowm.xchange.dto.account.Wallet;

import java.util.HashSet;
import java.util.Set;

public class PoloniexExchange extends XChangeExchange {

public PoloniexExchange(String preferredFiatCurrency) {
super(getDefaultSpecification(), preferredFiatCurrency);
}

public PoloniexExchange(String key, String secret, String preferredFiatCurrency) {
super(getSpecification(key, secret), preferredFiatCurrency);
}

private static ExchangeSpecification getDefaultSpecification() {
return new org.knowm.xchange.poloniex.PoloniexExchange().getDefaultExchangeSpecification();
}

private static ExchangeSpecification getSpecification(String key, String secret) {
ExchangeSpecification spec = getDefaultSpecification();
spec.setApiKey(key);
spec.setSecretKey(secret);
return spec;
}

@Override
public Set<String> getCryptoCurrencies() {
Set<String> cryptoCurrencies = new HashSet<>();
cryptoCurrencies.add(CryptoCurrency.BCH.getCode());
cryptoCurrencies.add(CryptoCurrency.BTC.getCode());
cryptoCurrencies.add(CryptoCurrency.BURST.getCode());
cryptoCurrencies.add(CryptoCurrency.ETH.getCode());
cryptoCurrencies.add(CryptoCurrency.LTC.getCode());
cryptoCurrencies.add(CryptoCurrency.DASH.getCode());
cryptoCurrencies.add(CryptoCurrency.DAI.getCode());
cryptoCurrencies.add(CryptoCurrency.DGB.getCode());
cryptoCurrencies.add(CryptoCurrency.DOGE.getCode());
cryptoCurrencies.add(CryptoCurrency.LSK.getCode());
cryptoCurrencies.add(CryptoCurrency.NXT.getCode());
cryptoCurrencies.add(CryptoCurrency.POT.getCode());
cryptoCurrencies.add(CryptoCurrency.REP.getCode());
cryptoCurrencies.add(CryptoCurrency.SYS.getCode());
cryptoCurrencies.add(CryptoCurrency.VIA.getCode());
cryptoCurrencies.add(CryptoCurrency.XMR.getCode());
cryptoCurrencies.add(CryptoCurrency.XRP.getCode());
cryptoCurrencies.add(CryptoCurrency.XPM.getCode());
return cryptoCurrencies;
}

@Override
public Set<String> getFiatCurrencies() {
Set<String> fiatCurrencies = new HashSet<>();
fiatCurrencies.add(FiatCurrency.USD.getCode());
return fiatCurrencies;
}

@Override
protected boolean isWithdrawSuccessful(String result) {
return true;
}

@Override
protected double getAllowedCallsPerSecond() {
return 10;
}

@Override
public Wallet getWallet(AccountInfo accountInfo, String currency) {
return accountInfo.getWallet();
}

@Override
protected String translateFiatCurrencySymbolToExchangeSpecificSymbol(String currency) {
if (FiatCurrency.USD.getCode().equalsIgnoreCase(currency)) {
return "USDT";
}
return currency;
}
}
44 changes: 44 additions & 0 deletions server_extensions_extra/src/main/resources/batm-extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,29 @@
<cryptocurrency>ETH</cryptocurrency>
<cryptocurrency>LTC</cryptocurrency>
</exchange>
<exchange prefix="poloniex" name="Poloniex">
<param name="key"/>
<param name="secret"/>
<param name="fiatcurrency" />
<cryptocurrency>BCH</cryptocurrency>
<cryptocurrency>BTC</cryptocurrency>
<cryptocurrency>BURST</cryptocurrency>
<cryptocurrency>ETH</cryptocurrency>
<cryptocurrency>LTC</cryptocurrency>
<cryptocurrency>DASH</cryptocurrency>
<cryptocurrency>DAI</cryptocurrency>
<cryptocurrency>DGB</cryptocurrency>
<cryptocurrency>DOGE</cryptocurrency>
<cryptocurrency>LSK</cryptocurrency>
<cryptocurrency>NXT</cryptocurrency>
<cryptocurrency>POT</cryptocurrency>
<cryptocurrency>REP</cryptocurrency>
<cryptocurrency>SYS</cryptocurrency>
<cryptocurrency>VIA</cryptocurrency>
<cryptocurrency>XMR</cryptocurrency>
<cryptocurrency>XRP</cryptocurrency>
<cryptocurrency>XPM</cryptocurrency>
</exchange>
<ratesource prefix="coinbasepro" name="Coinbase Pro">
<param name="fiatcurrency" />
<cryptocurrency>BCH</cryptocurrency>
Expand All @@ -399,6 +422,27 @@
<cryptocurrency>LTC</cryptocurrency>
<cryptocurrency>XRP</cryptocurrency>
</ratesource>
<ratesource prefix="poloniex" name="Poloniex">
<param name="fiatcurrency" />
<cryptocurrency>BCH</cryptocurrency>
<cryptocurrency>BTC</cryptocurrency>
<cryptocurrency>BURST</cryptocurrency>
<cryptocurrency>ETH</cryptocurrency>
<cryptocurrency>LTC</cryptocurrency>
<cryptocurrency>DASH</cryptocurrency>
<cryptocurrency>DAI</cryptocurrency>
<cryptocurrency>DGB</cryptocurrency>
<cryptocurrency>DOGE</cryptocurrency>
<cryptocurrency>LSK</cryptocurrency>
<cryptocurrency>NXT</cryptocurrency>
<cryptocurrency>POT</cryptocurrency>
<cryptocurrency>REP</cryptocurrency>
<cryptocurrency>SYS</cryptocurrency>
<cryptocurrency>VIA</cryptocurrency>
<cryptocurrency>XMR</cryptocurrency>
<cryptocurrency>XRP</cryptocurrency>
<cryptocurrency>XPM</cryptocurrency>
</ratesource>
<exchange prefix="coingi" name="Coingi.com">
<param name="key"/>
<param name="privatekey"/>
Expand Down

0 comments on commit 76e4ea7

Please sign in to comment.