knowm / XChange

XChange is a Java library providing a streamlined API for interacting with 60+ Bitcoin and Altcoin exchanges providing a consistent interface for trading and accessing market data.
http://knowm.org/open-source/xchange/
MIT License
3.87k stars 1.94k forks source link

BitMex Symbol Adapters #2063

Closed douggie closed 6 years ago

douggie commented 6 years ago

Bitmex support the following prompts for the derivatives contracts (https://www.bitmex.com/api/v1/instrument/activeIntervals)

monthly quarterly biquarterly perpetual weekly

Any objections to using a base.quote.prompt format that would be adapted into the local bitmex symbol as per the following:

XMR.BTC.MONTHLY -> XMRZ17 XMR.BTC.QUARTERLY ->  XMRH18 DASH.BTC.MONTHLY ->  DASHZ17 DASH.BTC.QUARTERLY ->  DASHH18 XRP.BTC.MONTHLY ->  XRPZ17 XRP.BTC.QUARTERLY ->  XRPH18 BCH.BTC.MONTHLY ->  BCHF18 ZEC.BTC.MONTHLY ->  ZECZ17 ZEC.BTC.QUARTERLY ->  ZECH18 XTZ.BTC.MONTHLY ->  XTZZ17 XTZ.BTC.BIQUARTERLY ->  XTZZ17 BTC. XXX.MONTHLY ->  B_BLOCKSZ17 XBT.USD.MONTHLY ->  XBTZ17 XBT.USD.QUARTERLY ->  XBTH18 XBT.USD.PERPETUAL ->  XBTUSD XBT.JPY.MONTHLY ->  XBJZ17 XBT.JPY.QUARTERLY ->  XBJZ17 ETH.BTC.MONTHLY ->  ETHZ17 ETH.BTC.QUARTERLY ->  ETHH18 ETC.BTC.WEEKLY ->  ETC7D LTC.BTC.MONTHLY ->  LTCZ17 LTC.BTC.QUARTERLY ->  LTCH18

Would make sense to create the above as a BiMap (https://google.github.io/guava/releases/19.0/api/docs/com/google/common/collect/BiMap.html) create by parsing the response from https://www.bitmex.com/api/v1/instrument/active and https://www.bitmex.com/api/v1/instrument/activeIntervals,

douggie commented 6 years ago

The main issue with this approach, is that if xchange is connected when the contracts expire and the monthly moved from ETH.BTC.MONTHLY -> ETHZ17 to ETH.BTC.MONTHLY -> ETHF18, when it tries to place a ETH.BTC.MONTHLY it will try to place the ETHZ17 which is now expired, hopefully we will get an exception from the exchange, prompting the programme to re initialise the xchange interface which will then call remoteInit and pull down the latest contract code (ETH.BTC.MONTHLY -> ETHF18). Even if we used the raw symbols at start up xchange would only know about ETHZ17 as ETHF18 did not exist when it connect in. it was only once it was connected and ETHZ17 expired and ETHF18 was created did the ETHZ17 become invaild prompting a remoteInit being called for the bitmex xchange instance.

douggie commented 6 years ago

also bug reported and acknowledged (#38251) by bitmex, that https://www.bitmex.com/api/v1/instrument/activeIntervals does not return the bi-quaterly contracts. they have committed to fixing this, but until they do the bi-quaterly contracts will not be tradable.

traviscollins commented 6 years ago

This merge pulled in a super old version of google guava-collections (r03 from 2010). This broke our downstream code (we simply excluded the include). But it needs to be removed.

The include is in xchange-core/pom.xml at the very bottom.

douggie commented 6 years ago

hi Tim,

i was worried it might cause issues.

I thought it would be helpful to have the bimap as quite a lot of places we maintain two maps for conversion.

can either add full guava libs or i can reactor with two maps.

On Tue, 30 Jan 2018, 14:53 Travis Collins, notifications@github.com wrote:

This merge pulled in a super old version of google guava-collections (r03 from 2010). This broke our downstream code (we simply excluded the include). But it needs to be removed.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/timmolter/XChange/issues/2063#issuecomment-361617340, or mute the thread https://github.com/notifications/unsubscribe-auth/AENHaufxvdqf9jYdkpzzwgiS4QryTYiiks5tPy0BgaJpZM4ROp-s .

timmolter commented 6 years ago

Yes, please remove guava. Sorry I missed it beforehand.

Von meinem iPhone gesendet

Am 30.01.2018 um 20:48 schrieb douggie notifications@github.com:

hi Tim,

i was worried it might cause issues.

I thought it would be helpful to have the bimap as quite a lot of places we maintain two maps for conversion.

can either add full guava libs or i can reactor with two maps.

On Tue, 30 Jan 2018, 14:53 Travis Collins, notifications@github.com wrote:

This merge pulled in a super old version of google guava-collections (r03 from 2010). This broke our downstream code (we simply excluded the include). But it needs to be removed.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/timmolter/XChange/issues/2063#issuecomment-361617340, or mute the thread https://github.com/notifications/unsubscribe-auth/AENHaufxvdqf9jYdkpzzwgiS4QryTYiiks5tPy0BgaJpZM4ROp-s .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

douggie commented 6 years ago

once travis changes are merged i will remove it and use two maps for the mapping.

On Tue, 30 Jan 2018, 22:47 Tim Molter, notifications@github.com wrote:

Yes, please remove guava. Sorry I missed it beforehand.

Von meinem iPhone gesendet

Am 30.01.2018 um 20:48 schrieb douggie notifications@github.com:

hi Tim,

i was worried it might cause issues.

I thought it would be helpful to have the bimap as quite a lot of places we maintain two maps for conversion.

can either add full guava libs or i can reactor with two maps.

On Tue, 30 Jan 2018, 14:53 Travis Collins, notifications@github.com wrote:

This merge pulled in a super old version of google guava-collections (r03 from 2010). This broke our downstream code (we simply excluded the include). But it needs to be removed.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub < https://github.com/timmolter/XChange/issues/2063#issuecomment-361617340>, or mute the thread < https://github.com/notifications/unsubscribe-auth/AENHaufxvdqf9jYdkpzzwgiS4QryTYiiks5tPy0BgaJpZM4ROp-s

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/timmolter/XChange/issues/2063#issuecomment-361760906, or mute the thread https://github.com/notifications/unsubscribe-auth/AENHao6tOC7nPpwoy4Tkfiw9fhRBYnJqks5tP5v-gaJpZM4ROp-s .

timmolter commented 6 years ago

@douggie Go ahead.