Skip to content
This repository has been archived by the owner on Jun 8, 2020. It is now read-only.

Bitmex misc merge #329

Merged
merged 110 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
2ba28da
add interface support for trade service
declan94 May 13, 2018
9cdcba4
Misspell fix
declan94 May 13, 2018
131d662
bug fix
declan94 May 13, 2018
7269bd8
add support for okex futrues trading
declan94 May 14, 2018
0d21b9d
code formatting
declan94 May 14, 2018
cd7cca8
bitmex authenticate
declan94 May 17, 2018
4e05dd1
order update subscription bug fix
declan94 May 17, 2018
625e3cd
temp
declan94 May 17, 2018
18bf3c3
support bitmex futures contract
declan94 May 19, 2018
043c573
notification of reconnect failure
declan94 May 20, 2018
01c7a4a
to hetang repo
declan94 May 20, 2018
045bf27
Merge branch 'reconn-fail-hook' into hetang
declan94 May 20, 2018
6947c3c
exchange interface support
declan94 May 20, 2018
6f264d1
end
declan94 May 20, 2018
6753f6e
Merge branch 'reconn-fail-hook' into hetang
declan94 May 20, 2018
4910dcb
bitmex trade service support
declan94 May 21, 2018
3d8e6af
merge trade service implemention for bitmex
declan94 May 21, 2018
df8b75d
Merge branch 'okex-futures' into hetang
declan94 May 23, 2018
d93eb22
send ping message to server every 15 sec
declan94 May 24, 2018
3dcc8fc
Merge branch 'okcoin_pingpong' into hetang
declan94 May 24, 2018
c561404
handle unexpected channel error
declan94 May 24, 2018
52bafda
Merge branch 'okcoin_robust' into hetang
declan94 May 24, 2018
05a540e
try to fix kill bug
declan94 May 25, 2018
1493d0f
okcoin handle result message
declan94 May 26, 2018
54c8a13
Merge branch 'okcoin_handle_result_message' into hetang
declan94 May 26, 2018
afc2ff1
Nomsg support
declan94 May 28, 2018
3adddf4
add observable for message delay
declan94 May 28, 2018
e5e4b7e
merge delay
declan94 May 28, 2018
60b2e0a
bitmex okex streamingservice protected
declan94 May 28, 2018
44d36ad
marketstreamingservice protected streaming service
declan94 May 28, 2018
8a533f0
resubscribe channels
declan94 May 28, 2018
b2aba30
eventloop leap fix
declan94 May 28, 2018
d1b29d8
sleep before reconnect
declan94 May 28, 2018
33d8a1f
observable of disconnect
declan94 May 28, 2018
4e9ffa4
not reconnect if observe disconnect
declan94 May 28, 2018
497538e
bug fix
declan94 May 29, 2018
a61aa85
bug fix
declan94 May 29, 2018
89c6276
bug fix
declan94 May 29, 2018
c972bf4
bug fix
declan94 May 29, 2018
d87f4a0
try catch
declan94 May 29, 2018
8009a86
add maven release plugin
declan94 May 30, 2018
a6f3dd1
change scm
declan94 May 30, 2018
6180c93
[maven-release-plugin] rollback the release of xchange-stream-parent-…
declan94 May 30, 2018
2276b4f
scm
declan94 May 30, 2018
5074025
[maven-release-plugin] prepare release xchange-stream-parent-4.3.2.1
declan94 May 30, 2018
fc827a4
[maven-release-plugin] prepare for next development iteration
declan94 May 30, 2018
5e87fb2
do not send pingpong when disconnected
declan94 Jun 1, 2018
dd03c80
translate bitmex contract
declan94 Jun 1, 2018
f3d29d6
okcoin orderbook bug fix
declan94 Jun 2, 2018
dbd3486
maven repo address using domain name
declan94 Jun 4, 2018
f4aa587
maven-release auto version submodules
declan94 Jun 5, 2018
4b913de
Merge branch 'develop' into okcoin_pingpong
dozd Jun 8, 2018
01529df
pom snapshot version
declan94 Jun 9, 2018
19c0f72
okcoin pingpong using reactiveX
declan94 Jun 9, 2018
bf00ae8
merge okcoin pingpong
declan94 Jun 9, 2018
40b3fdb
log unsubscribed error
declan94 Jun 14, 2018
223aadf
[maven-release-plugin] prepare release xchange-stream-parent-4.3.2.2
declan94 Jun 15, 2018
7a63920
[maven-release-plugin] prepare for next development iteration
declan94 Jun 15, 2018
464e9ff
log
declan94 Jun 15, 2018
5b7bc4b
[maven-release-plugin] prepare release xchange-stream-parent-4.3.2.3
declan94 Jun 15, 2018
cc497ab
[maven-release-plugin] prepare for next development iteration
declan94 Jun 15, 2018
a54bce4
fcoin get orderbook
declan94 Jun 22, 2018
96d7dde
resubscribe with no message problem
declan94 Jul 5, 2018
41d56cb
[maven-release-plugin] prepare release xchange-stream-parent-4.3.2.4
declan94 Jul 5, 2018
21cb997
[maven-release-plugin] prepare for next development iteration
declan94 Jul 5, 2018
4e3395e
[maven-release-plugin] prepare release xchange-stream-parent-4.3.2.4
declan94 Jul 5, 2018
8e30939
Revert "resubscribe with no message problem"
declan94 Jul 5, 2018
bb7397e
to snapshot
declan94 Jul 5, 2018
e9b6706
[maven-release-plugin] prepare release xchange-stream-parent-4.3.2.4
declan94 Jul 5, 2018
16270a4
[maven-release-plugin] prepare for next development iteration
declan94 Jul 5, 2018
f89c35b
resubscribe with no message problem fix
declan94 Jul 21, 2018
4bdb55b
[maven-release-plugin] prepare release xchange-stream-parent-4.3.2.5
declan94 Jul 21, 2018
6410cd5
[maven-release-plugin] prepare for next development iteration
declan94 Jul 21, 2018
b3121d6
okex error handle bug
declan94 Jul 30, 2018
e631d4d
[maven-release-plugin] prepare release xchange-stream-parent-4.3.2.6
declan94 Jul 30, 2018
1caa9e8
[maven-release-plugin] prepare for next development iteration
declan94 Jul 30, 2018
5e963c1
bitmex ticker to ticker
Sep 3, 2018
f6337cd
okex compressed message
Oct 17, 2018
5673b49
log more precise
Oct 17, 2018
78dc4b7
[maven-release-plugin] prepare release xchange-stream-parent-4.3.2.7
Oct 18, 2018
c05a25b
[maven-release-plugin] prepare for next development iteration
Oct 18, 2018
04b3d10
Restore the Bitmex Execution reports code which was cut out of #191.
Foat Oct 25, 2018
72828ca
bitmex add index subscription
declan94 Nov 9, 2018
0d5bf75
Revert "bitmex add index subscription"
declan94 Nov 9, 2018
bec0866
okex v3 get orderbook, bitmex adapt to new version XChange
declan94 May 21, 2019
2ce7f93
pom repo
declan94 May 21, 2019
72e2102
okex bug fix
declan94 May 21, 2019
2bb4a99
okex bug fix
declan94 May 21, 2019
491f3e5
okex bug fix
declan94 May 21, 2019
844da97
okex npe bug
declan94 May 21, 2019
b59683b
bitmex login and get order property
declan94 May 21, 2019
d226cee
bitmex funding
declan94 May 21, 2019
56557c1
okex v3 authenticate
declan94 May 21, 2019
0979201
default get passphrase
declan94 May 22, 2019
da15167
inherent XChange okex-v3
declan94 May 22, 2019
5c5fb40
bug fix
declan94 May 22, 2019
206ad2a
login waiting done
declan94 May 22, 2019
6c49111
bug fix
declan94 May 22, 2019
a2ea2b8
login fix, need heartbeat now
declan94 May 22, 2019
39aa686
okex pingpong, bitmex perpetual null
declan94 May 22, 2019
9e57ff1
okex pingpong without apikey set
declan94 May 23, 2019
8b8953b
okex streaming service bug fix
declan94 May 23, 2019
32a7b6f
catch price==null
declan94 May 27, 2019
307d79a
not catch npe
declan94 May 27, 2019
7d95637
Merge remote-tracking branch 'remotes/badgerwithagun/bitmex-execution…
henryxwong Jun 8, 2019
fd4ca1a
Merge remote-tracking branch 'remotes/declan94/hetang' into bitmex-merge
henryxwong Jun 8, 2019
7bd3c0a
Bugfix and fix all the test cases
henryxwong Jun 8, 2019
ab8dd9a
Merge branch 'develop' of github.com:bitrich-info/xchange-stream into…
henryxwong Jun 17, 2019
6345188
Update based on code review
henryxwong Jun 17, 2019
b180f1b
Delete submit order
henryxwong Jun 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper;
import io.reactivex.Observable;
import org.knowm.xchange.bitmex.BitmexExchange;
import org.knowm.xchange.bitmex.BitmexPrompt;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.marketdata.OrderBook;
import org.knowm.xchange.dto.marketdata.Ticker;
Expand Down Expand Up @@ -41,17 +40,13 @@ public BitmexStreamingMarketDataService(BitmexStreamingService streamingService,
this.bitmexExchange = bitmexExchange;
}

private String getBitmexSymbol(CurrencyPair currencyPair, Object... args) {
if (args.length > 0 && args[0] != null) {
BitmexPrompt prompt = (BitmexPrompt) args[0];
currencyPair = bitmexExchange.determineActiveContract(currencyPair.base.toString(), currencyPair.counter.toString(), prompt);
}
private String getBitmexSymbol(CurrencyPair currencyPair) {
return currencyPair.base.toString() + currencyPair.counter.toString();
}

@Override
public Observable<OrderBook> getOrderBook(CurrencyPair currencyPair, Object... args) {
String instrument = getBitmexSymbol(currencyPair, args);
String instrument = getBitmexSymbol(currencyPair);
String channelName = String.format("orderBookL2:%s", instrument);

return streamingService.subscribeBitmexChannel(channelName).map(s -> {
Expand All @@ -74,16 +69,16 @@ public Observable<OrderBook> getOrderBook(CurrencyPair currencyPair, Object... a
});
}

public Observable<BitmexTicker> getRawTicker(CurrencyPair currencyPair, Object... args) {
String instrument = getBitmexSymbol(currencyPair, args);
public Observable<BitmexTicker> getRawTicker(CurrencyPair currencyPair) {
String instrument = getBitmexSymbol(currencyPair);
String channelName = String.format("quote:%s", instrument);

return streamingService.subscribeBitmexChannel(channelName).map(s -> s.toBitmexTicker());
}

@Override
public Observable<Ticker> getTicker(CurrencyPair currencyPair, Object... args) {
String instrument = getBitmexSymbol(currencyPair, args);
String instrument = getBitmexSymbol(currencyPair);
String channelName = String.format("quote:%s", instrument);

return streamingService.subscribeBitmexChannel(channelName).map(s -> {
Expand All @@ -94,7 +89,7 @@ public Observable<Ticker> getTicker(CurrencyPair currencyPair, Object... args) {

@Override
public Observable<Trade> getTrades(CurrencyPair currencyPair, Object... args) {
String instrument = getBitmexSymbol(currencyPair, args);
String instrument = getBitmexSymbol(currencyPair);
String channelName = String.format("trade:%s", instrument);

return streamingService.subscribeBitmexChannel(channelName).flatMapIterable(s -> {
Expand All @@ -108,7 +103,7 @@ public Observable<Trade> getTrades(CurrencyPair currencyPair, Object... args) {
}


public Observable<BitmexExecution> getExecutions(String symbol) {
public Observable<BitmexExecution> getRawExecutions(String symbol) {
return streamingService.subscribeBitmexChannel("execution:" + symbol).flatMapIterable(s -> {
JsonNode executions = s.getData();
List<BitmexExecution> bitmexExecutions = new ArrayList<>(executions.size());
Expand Down Expand Up @@ -139,7 +134,7 @@ public void disableDeadMansSwitch() throws IOException {
streamingService.disableDeadMansSwitch();
}

public Observable<BitmexFunding> getFunding() {
public Observable<BitmexFunding> getRawFunding() {
String channelName = "funding";
return streamingService.subscribeBitmexChannel(channelName).map(BitmexWebSocketTransaction::toBitmexFunding);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import info.bitrich.xchangestream.bitmex.dto.BitmexOrder;
import info.bitrich.xchangestream.core.StreamingTradeService;
import io.reactivex.Observable;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.Order;
Expand All @@ -15,15 +14,14 @@
/**
* Created by Declan
*/
public class BitmexStreamingTradeService implements StreamingTradeService {
public class BitmexStreamingTradeService {

private final BitmexStreamingService streamingService;

public BitmexStreamingTradeService(BitmexStreamingService streamingService) {
this.streamingService = streamingService;
}

@Override
public Observable<Order> getOrders(CurrencyPair currencyPair, Object... args) {
String channelName = "order";
String instrument = currencyPair.base.toString() + currencyPair.counter.toString();
Expand All @@ -35,9 +33,4 @@ public Observable<Order> getOrders(CurrencyPair currencyPair, Object... args) {
.map(BitmexOrder::toOrder).collect(Collectors.toList());
});
}

@Override
public void submitOrder(Order order, CurrencyPair var1, Object... var2) {
throw new NotYetImplementedForExchangeException();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package info.bitrich.xchangestream.bitmex;

import info.bitrich.xchangestream.bitmex.dto.BitmexExecution;
import info.bitrich.xchangestream.core.StreamingExchange;
import info.bitrich.xchangestream.core.StreamingExchangeFactory;
import io.reactivex.Observable;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.utils.CertHelper;
Expand Down Expand Up @@ -55,7 +53,7 @@ public static void main(String[] args) throws Exception {
/* streamingMarketDataService.getTrades(xbtUsd)
.subscribe(trade -> LOG.info("TRADE: {}", trade),
throwable -> LOG.error("ERROR in getting trades: ", throwable));*/
streamingMarketDataService.getExecutions("XBTUSD").subscribe(bitmexExecution -> {
streamingMarketDataService.getRawExecutions("XBTUSD").subscribe(bitmexExecution -> {
LOG.info("bitmexExecution = {}", bitmexExecution);
});
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package info.bitrich.xchangestream.bitmex;

import info.bitrich.xchangestream.bitmex.dto.BitmexLimitOrder;
import info.bitrich.xchangestream.core.StreamingExchange;
import org.junit.Ignore;
import org.junit.Test;
import org.knowm.xchange.ExchangeFactory;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.bitmex.dto.marketdata.BitmexPrivateOrder;
import org.knowm.xchange.bitmex.dto.trade.BitmexSide;
import org.knowm.xchange.bitmex.service.BitmexMarketDataService;
import org.knowm.xchange.bitmex.service.BitmexTradeService;
import org.knowm.xchange.currency.CurrencyPair;
Expand All @@ -19,7 +16,6 @@
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.List;

import static org.knowm.xchange.bitmex.BitmexPrompt.PERPETUAL;

Expand Down Expand Up @@ -62,13 +58,13 @@ public void testDeadmanSwitch() throws Exception {

final BitmexStreamingMarketDataService streamingMarketDataService = (BitmexStreamingMarketDataService) exchange.getStreamingMarketDataService();
// streamingMarketDataService.authenticate();
CurrencyPair xbtUsd = CurrencyPair.XBT_USD;
CurrencyPair xbtUsd = exchange.determineActiveContract(CurrencyPair.XBT_USD.base.toString(), CurrencyPair.XBT_USD.counter.toString(), PERPETUAL);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

determineActiveContract takes "BTC" rather than "XBT" I think (or should do)...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah no, works with either. Cool.


streamingMarketDataService.getExecutions("XBTUSD").subscribe(bitmexExecution -> {
streamingMarketDataService.getRawExecutions("XBTUSD").subscribe(bitmexExecution -> {
logger.info("!!!!EXECUTION!!!! = {}", bitmexExecution);
});

OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.XBT_USD, PERPETUAL);
OrderBook orderBook = marketDataService.getOrderBook(xbtUsd);
// OrderBook orderBook = marketDataService.getOrderBook(new CurrencyPair(Currency.ADA,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should call using the result of BitmexExchange.determineActiveContract

// Currency.BTC), BitmexPrompt.QUARTERLY);
// OrderBook orderBook = marketDataService.getOrderBook(new CurrencyPair(Currency.BTC,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should call using the result of BitmexExchange.determineActiveContract

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class BitmexManualExample {
private static final Logger LOG = LoggerFactory.getLogger(BitmexManualExample.class);

public static void main(String[] args) {
StreamingExchange exchange = StreamingExchangeFactory.INSTANCE.createExchange(BitmexStreamingExchange.class.getName());
BitmexStreamingExchange exchange = (BitmexStreamingExchange) StreamingExchangeFactory.INSTANCE.createExchange(BitmexStreamingExchange.class.getName());
exchange.connect().blockingAwait();

exchange.messageDelay().subscribe(delay -> LOG.info("Message delay: " + delay));
Expand Down Expand Up @@ -45,16 +45,17 @@ public static void main(String[] args) {
throwable -> LOG.error("ERROR in getting trades: ", throwable));

// BIQUARTERLY Contract
streamingMarketDataService.getOrderBook(xbtUsd, BitmexPrompt.BIQUARTERLY).subscribe(orderBook -> {
CurrencyPair xbtUsdBiquarterly = exchange.determineActiveContract(CurrencyPair.XBT_USD.base.toString(), CurrencyPair.XBT_USD.counter.toString(), BitmexPrompt.BIQUARTERLY);
streamingMarketDataService.getOrderBook(xbtUsdBiquarterly).subscribe(orderBook -> {
LOG.info("BIQUARTERLY Contract First ask: {}", orderBook.getAsks().get(0));
LOG.info("BIQUARTERLY Contract First bid: {}", orderBook.getBids().get(0));
}, throwable -> LOG.error("ERROR in getting BIQUARTERLY Contract order book: ", throwable));

streamingMarketDataService.getTicker(xbtUsd, BitmexPrompt.BIQUARTERLY).subscribe(ticker -> {
streamingMarketDataService.getTicker(xbtUsdBiquarterly).subscribe(ticker -> {
LOG.info("BIQUARTERLY Contract TICKER: {}", ticker);
}, throwable -> LOG.error("ERROR in getting BIQUARTERLY Contract ticker: ", throwable));

exchange.getStreamingMarketDataService().getTrades(xbtUsd, BitmexPrompt.BIQUARTERLY)
exchange.getStreamingMarketDataService().getTrades(xbtUsdBiquarterly)
.subscribe(trade -> LOG.info("BIQUARTERLY Contract TRADE: {}", trade),
throwable -> LOG.error("ERROR in getting BIQUARTERLY Contract trades: ", throwable));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @author Nikita Belenkiy on 18/05/2018.
*/
public class BitmexOrderIT {
private static final CurrencyPair xbtUsd = CurrencyPair.XBT_USD;
private CurrencyPair xbtUsd = CurrencyPair.XBT_USD;
private static final Logger LOG = LoggerFactory.getLogger(BitmexTest.class);

private static final BigDecimal priceShift = new BigDecimal("50");
Expand All @@ -46,22 +46,24 @@ public class BitmexOrderIT {
private BigDecimal testBidPrice;

private BitmexTradeService tradeService;
private StreamingExchange exchange;
private BitmexStreamingExchange exchange;

@Before
public void setup() throws IOException {
LocalExchangeConfig localConfig = PropsLoader.loadKeys(
"bitmex.secret.keys", "bitmex.secret.keys.origin", "bitmex");
exchange = StreamingExchangeFactory.INSTANCE.createExchange(BitmexStreamingExchange.class.getName());
exchange = (BitmexStreamingExchange) StreamingExchangeFactory.INSTANCE.createExchange(BitmexStreamingExchange.class.getName());

exchange.applySpecification(BitmexTestsCommons.getExchangeSpecification(localConfig,
exchange.getDefaultExchangeSpecification()));
exchange.connect().blockingAwait();

xbtUsd = exchange.determineActiveContract(CurrencyPair.XBT_USD.base.toString(), CurrencyPair.XBT_USD.counter.toString(), PERPETUAL);

BitmexMarketDataService marketDataService =
(BitmexMarketDataService) exchange.getMarketDataService();

OrderBook orderBook = marketDataService.getOrderBook(xbtUsd, PERPETUAL);
OrderBook orderBook = marketDataService.getOrderBook(xbtUsd);
List<LimitOrder> asks = orderBook.getAsks();
// todo : for the streaming service best ask is at 0 pos
BigDecimal topPriceAsk = getPrice(asks, asks.size() - 1);
Expand Down Expand Up @@ -206,7 +208,7 @@ public void shouldGetExecutionOnFill() {
}, 1, TimeUnit.SECONDS);

Observable<BitmexExecution> executionObservable = ((BitmexStreamingMarketDataService)
exchange.getStreamingMarketDataService()).getExecutions("XBTUSD");
exchange.getStreamingMarketDataService()).getRawExecutions("XBTUSD");
executionObservable.test()
.awaitCount(5)
.assertNever(execution -> Objects.equals(execution.getClOrdID(), clOrdId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public void testOrderReplace() throws Exception {

final BitmexStreamingMarketDataService streamingMarketDataService = (BitmexStreamingMarketDataService) exchange.getStreamingMarketDataService();
// streamingMarketDataService.authenticate();
CurrencyPair xbtUsd = CurrencyPair.XBT_USD;
CurrencyPair xbtUsd = exchange.determineActiveContract(CurrencyPair.XBT_USD.base.toString(), CurrencyPair.XBT_USD.counter.toString(), PERPETUAL);

streamingMarketDataService.getExecutions("XBTUSD").subscribe(bitmexExecution -> {
streamingMarketDataService.getRawExecutions("XBTUSD").subscribe(bitmexExecution -> {
logger.info("!!!!EXECUTION!!!! = {}", bitmexExecution);
});
OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.XBT_USD, PERPETUAL);
OrderBook orderBook = marketDataService.getOrderBook(xbtUsd);
// OrderBook orderBook = marketDataService.getOrderBook(new CurrencyPair(Currency.ADA,
// Currency.BTC), BitmexPrompt.QUARTERLY);
henryxwong marked this conversation as resolved.
Show resolved Hide resolved
// OrderBook orderBook = marketDataService.getOrderBook(new CurrencyPair(Currency.BTC,
Expand Down

This file was deleted.