diff --git a/README.md b/README.md index c682e848..c41050a5 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ except for the trading strategies - you'll need to write those yourself! A simpl is included to get you started with the Trading API - see [Ta4j](https://github.com/ta4j/ta4j) for more ideas. Exchange Adapters for using [Bitstamp](https://www.bitstamp.net), [Bitfinex](https://www.bitfinex.com), -[Kraken](https://www.kraken.com), and [Gemini](https://gemini.com/) are included. +[Kraken](https://www.kraken.com), [Gemini](https://gemini.com/), and [Coinbase](https://www.coinbase.com/en-gb/advanced-trade) are included. Feel free to improve these or contribute new adapters to the project; that would be [shiny!](https://en.wikipedia.org/wiki/Firefly_(TV_series)) diff --git a/bxbot-exchanges/src/main/java/com/gazbert/bxbot/exchanges/CoinbaseAdvancedExchangeAdapter.java b/bxbot-exchanges/src/main/java/com/gazbert/bxbot/exchanges/CoinbaseAdvancedExchangeAdapter.java new file mode 100644 index 00000000..df8f50e9 --- /dev/null +++ b/bxbot-exchanges/src/main/java/com/gazbert/bxbot/exchanges/CoinbaseAdvancedExchangeAdapter.java @@ -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 here. + * + *

This adapter only supports the Coinbase Advanced Trade REST API. 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 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!"); + } +} diff --git a/bxbot-exchanges/src/test/java/com/gazbert/bxbot/exchanges/TestCoinbaseAdvancedExchangeAdapter.java b/bxbot-exchanges/src/test/java/com/gazbert/bxbot/exchanges/TestCoinbaseAdvancedExchangeAdapter.java new file mode 100644 index 00000000..e38c999d --- /dev/null +++ b/bxbot-exchanges/src/test/java/com/gazbert/bxbot/exchanges/TestCoinbaseAdvancedExchangeAdapter.java @@ -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(); + } +}