Skip to content

Commit

Permalink
feat: Genesis (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
gazbert committed Nov 15, 2024
1 parent c708f26 commit c0fb860
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
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!");
}
}
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();
}
}

0 comments on commit c0fb860

Please sign in to comment.