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.86k stars 1.94k forks source link

Support for Futures markets #3171

Open andre77 opened 5 years ago

andre77 commented 5 years ago

Currently the central key point of the XChange API is the CurrencyPair, which is passed as parameter for almost all methods. This works fine so far for spot markets. But if we want to support futures markets the CurrencyPair is not enough, for example see Deribit Instruments, there we have three "products" with the same pair BTC/USD. To support this we would need to replace the CurrencyPair by Product class, which could look like this:

public class Product {
  private String base;
  private String counter;
  private String symbol;    // this can be null, ie for spot products
  private ProductType productType;
}

public enum ProductType {
  spot, perpetual, future;
}

To stay with the deribit example, we would have three instances for products:

{base: BTC, counter: USD, symbol: BTC-27SEP19, productType: future}
{base: BTC, counter: USD, symbol: BTC-27DEC19, productType: future}
{base: BTC, counter: USD, symbol: BTC-PERPETUAL, productType: perpetual}

So like already said, inside the interface methods we could replace the CurrencyPair by Product (or Instrument or what ever name). The old methods could actually stay for a while and be marked as deprecated. This way we would be still compatible with older versions.

if the majority thinks it could make sense, i will create a PR

douggie commented 4 years ago

Sounds good. Will make it backwardly compatible as I can there we still a few bits that needed changing like the serializer in the rock. Exchange

walec51 commented 4 years ago

please make a separate PR and just focus on applying the Instrument class to Order in the way I described, try to keep the changes outside of xchange-core to a minimum

douggie commented 4 years ago

Hi Adam,

Think it will be a bit more than just the order class as I feel at a minimum we should be able to do the following.

But rather than refactoring the exchange implentations I will leave them unchanged and just update xchange-core.

On Sun, 22 Mar 2020, 13:36 Adam Walczak, notifications@github.com wrote:

please make a separate PR and just focus on applying the Instrument class to Order in the way I described, try to keep the changes outside of xchange-core to a minimum

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/knowm/XChange/issues/3171#issuecomment-602201991, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBUO2SRFLXNRYYL3KSNGULRIYH67ANCNFSM4ILH5FDA .

mdvx commented 4 years ago

One other thing on positions: Derivatives contracts tend to have and expiry or end date (not perpetuals), which reset the position when it is hit.

Buy +10 June -> positions June(10) Sell -5 June -> positions June(5) Sell -3 September -> positions June(5), September(-3) // June 20th (3rd friday+1 day) -> positions June(0), September(-3) Buy +4 September -> positions September(1)

walec51 commented 4 years ago

@douggie

please focus only on: Place orders

in the first step - it is the most crucial one

we will hit a wall again if you bring +100 file pull request

this:

we can do in other subsequent PRs after we have ironed out the place orders PR

douggie commented 4 years ago

No problem. Will do them one by one.

On Sun, 22 Mar 2020, 20:10 Adam Walczak, notifications@github.com wrote:

@douggie https://github.com/douggie

please focus only on: Place orders

in the first step - it is the most crucial one

we will hit a wall again if you bring +100 file pull request

this:

  • Collect trade and depth data (changes to market data services)
  • cancel orders

we can do in other subsequent PRs after we have ironed out the place orders PR

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/knowm/XChange/issues/3171#issuecomment-602265099, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBUO2V3KEWL4T2U5R3E2YDRIZWEPANCNFSM4ILH5FDA .

conspyrosy commented 4 years ago

Just come across this while trying to integrate a futures exchange. What work remains on this issue? Looks like we've now introduced the Instrument class which can be extended to support Options/Futures.

Can we change the Services in core to take Instrument instead of CurrencyPair or does some further work need to be done before this happens. It looks like we will have to go back and ensure existing implementations aren't referencing the base/counter fields of CurrencyPair. Or is there something else which should be done as the next step.

douggie commented 4 years ago

Hi Spyros,

I did not have time to finish it, if you take a look at the PR https://github.com/knowm/XChange/pull/3473 it has an example in it for okex, if you implement inline with the comments, you should be good to go. Or feel free to update the PR.

On Sat, Jun 13, 2020 at 2:03 PM Spyros-Stylianou notifications@github.com wrote:

Just come across this while trying to integrate a futures exchange. What work remains on this issue? Looks like we've now introduced the Instrument class which can be extended to support Options/Futures.

Can we change the Services in core to take Instrument instead of CurrencyPair or does some further work need to be done before this happens. It looks like we will have to go back and ensure existing implementations aren't referencing the base/counter fields of CurrencyPair. Or is there something else which should be done as the next step.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/knowm/XChange/issues/3171#issuecomment-643620871, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBUO2WAC6QL62XXREWDJC3RWN2IPANCNFSM4ILH5FDA .

Viserius commented 3 years ago

Any news on futures support?