-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gazbert
committed
Nov 15, 2024
1 parent
c708f26
commit c0fb860
Showing
3 changed files
with
192 additions
and
1 deletion.
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
110 changes: 110 additions & 0 deletions
110
...-exchanges/src/main/java/com/gazbert/bxbot/exchanges/CoinbaseAdvancedExchangeAdapter.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,110 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 gazbert, davidhuertas | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.gazbert.bxbot.exchanges; | ||
|
||
import com.gazbert.bxbot.exchange.api.ExchangeAdapter; | ||
import com.gazbert.bxbot.exchange.api.ExchangeConfig; | ||
import com.gazbert.bxbot.trading.api.BalanceInfo; | ||
import com.gazbert.bxbot.trading.api.ExchangeNetworkException; | ||
import com.gazbert.bxbot.trading.api.MarketOrderBook; | ||
import com.gazbert.bxbot.trading.api.OpenOrder; | ||
import com.gazbert.bxbot.trading.api.OrderType; | ||
import com.gazbert.bxbot.trading.api.TradingApiException; | ||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
/** | ||
* Exchange Adapter for integrating with the Coinbase Advanced Trade exchange. The Coinbase API is | ||
* documented <a href="https://docs.cdp.coinbase.com/advanced-trade/docs/welcome">here</a>. | ||
* | ||
* <p>This adapter only supports the Coinbase Advanced Trade <a | ||
* href="https://docs.cdp.coinbase.com/advanced-trade/docs/api-overview">REST API</a>. The design of | ||
* the API and documentation is excellent. | ||
* | ||
* @author gazbert, davidhuertas | ||
* @since 1.0 | ||
*/ | ||
public class CoinbaseAdvancedExchangeAdapter extends AbstractExchangeAdapter | ||
implements ExchangeAdapter { | ||
|
||
private static final String EXCHANGE_ADAPTER_NAME = "Coinbase Advanced Trade REST API v3"; | ||
|
||
@Override | ||
public void init(ExchangeConfig config) { | ||
// no impl yet | ||
} | ||
|
||
@Override | ||
public String getImplName() { | ||
return EXCHANGE_ADAPTER_NAME; | ||
} | ||
|
||
@Override | ||
public MarketOrderBook getMarketOrders(String marketId) | ||
throws ExchangeNetworkException, TradingApiException { | ||
throw new UnsupportedOperationException("TODO: This method not developed yet!"); | ||
} | ||
|
||
@Override | ||
public List<OpenOrder> getYourOpenOrders(String marketId) | ||
throws ExchangeNetworkException, TradingApiException { | ||
throw new UnsupportedOperationException("TODO: This method not developed yet!"); | ||
} | ||
|
||
@Override | ||
public String createOrder( | ||
String marketId, OrderType orderType, BigDecimal quantity, BigDecimal price) | ||
throws ExchangeNetworkException, TradingApiException { | ||
throw new UnsupportedOperationException("TODO: This method not developed yet!"); | ||
} | ||
|
||
@Override | ||
public boolean cancelOrder(String orderId, String marketId) | ||
throws ExchangeNetworkException, TradingApiException { | ||
throw new UnsupportedOperationException("TODO: This method not developed yet!"); | ||
} | ||
|
||
@Override | ||
public BigDecimal getLatestMarketPrice(String marketId) | ||
throws ExchangeNetworkException, TradingApiException { | ||
throw new UnsupportedOperationException("TODO: This method not developed yet!"); | ||
} | ||
|
||
@Override | ||
public BalanceInfo getBalanceInfo() throws ExchangeNetworkException, TradingApiException { | ||
throw new UnsupportedOperationException("TODO: This method not developed yet!"); | ||
} | ||
|
||
@Override | ||
public BigDecimal getPercentageOfBuyOrderTakenForExchangeFee(String marketId) | ||
throws TradingApiException, ExchangeNetworkException { | ||
throw new UnsupportedOperationException("TODO: This method not developed yet!"); | ||
} | ||
|
||
@Override | ||
public BigDecimal getPercentageOfSellOrderTakenForExchangeFee(String marketId) | ||
throws TradingApiException, ExchangeNetworkException { | ||
throw new UnsupportedOperationException("TODO: This method not developed yet!"); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...hanges/src/test/java/com/gazbert/bxbot/exchanges/TestCoinbaseAdvancedExchangeAdapter.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,81 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2024 gazbert, davidhuertas | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.gazbert.bxbot.exchanges; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import com.gazbert.bxbot.exchange.api.AuthenticationConfig; | ||
import com.gazbert.bxbot.exchange.api.ExchangeConfig; | ||
import com.gazbert.bxbot.exchange.api.NetworkConfig; | ||
import com.gazbert.bxbot.exchange.api.OtherConfig; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.api.easymock.PowerMock; | ||
import org.powermock.core.classloader.annotations.PowerMockIgnore; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
/** | ||
* Tests the behaviour of the Coinbase Advanced Trade Exchange Adapter. | ||
* | ||
* @author gazbert, davidhuertas | ||
*/ | ||
@RunWith(PowerMockRunner.class) | ||
@PowerMockIgnore({ | ||
"javax.crypto.*", | ||
"javax.management.*", | ||
"com.sun.org.apache.xerces.*", | ||
"javax.xml.parsers.*", | ||
"org.xml.sax.*", | ||
"org.w3c.dom.*", | ||
"javax.xml.datatype.*" | ||
}) | ||
@PrepareForTest(CoinbaseAdvancedExchangeAdapter.class) | ||
public class TestCoinbaseAdvancedExchangeAdapter extends AbstractExchangeAdapterTest { | ||
|
||
private ExchangeConfig exchangeConfig; | ||
private AuthenticationConfig authenticationConfig; | ||
private NetworkConfig networkConfig; | ||
private OtherConfig otherConfig; | ||
|
||
/** Create some exchange config - the TradingEngine would normally do this. */ | ||
@Before | ||
public void setupForEachTest() { | ||
authenticationConfig = PowerMock.createMock(AuthenticationConfig.class); | ||
networkConfig = PowerMock.createMock(NetworkConfig.class); | ||
otherConfig = PowerMock.createMock(OtherConfig.class); | ||
exchangeConfig = PowerMock.createMock(ExchangeConfig.class); | ||
} | ||
|
||
@Test | ||
public void testGettingImplNameIsAsExpected() { | ||
PowerMock.replayAll(); | ||
final CoinbaseAdvancedExchangeAdapter exchangeAdapter = new CoinbaseAdvancedExchangeAdapter(); | ||
exchangeAdapter.init(exchangeConfig); | ||
|
||
assertEquals("Coinbase Advanced Trade REST API v3", exchangeAdapter.getImplName()); | ||
PowerMock.verifyAll(); | ||
} | ||
} |