question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Futures markets

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:59 (47 by maintainers)

github_iconTop GitHub Comments

2reactions
mdvxcommented, Mar 5, 2020

If we think to the definition of a Future contract, it is an obligation to Buy/Sell and asset at a future date (BTC). Sometimes these contracts are settled in the quoted fiat (USD), other times these contracts are settled for ‘physical’ delivery, which would mean in actual BTC. In which case, the USD part is just a reference, and this very same contract could be quoted in JPY, EUR, or even ETH.

As such a futures contract is not a currency pair, but depends on a single underlying asset.

1reaction
timmoltercommented, Mar 4, 2020

There are so many ways this could be done, which makes it hard to decide. We could add new DTOs, Services and methods. We could add new DTOs and methods to existing services. We could add new and/or extended DTOs to existing Services and existing methods.

I always tried to lean towards making it easy for the end user (a programmer using the library, not the developers of the library) to understand the API so if we continue with this goal in mind, adding new DTOs and methods would make the most sense. Otherwise newbies will have to deal with complex “wrapper” classes for method arguments and return values. If someone comes and just want to place a limit order for a plain old “spot”, they can easily find it by searching the methods and it is relatively easy then to understand what arguments are required and what is returned. As a compromise we could forgo adding new service classes but add more methods within the existing ones. By default the new methods will just throw a NotImplementedYetException as it always has worked.

I think this would warrant a version bump to 4.5.0.

As far as extending Order or CurrencyPair or not I’d say yes if there is significant overlap of class members, but I’d say no if the members were completely or mostly orthogonal. Just take it by a case to case basis.

@mdvx If you think extending the Order class is not ideal, in which way do you think things could be improved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Futures Trading | TD Ameritrade
TD Ameritrade offers a broad array of futures trading tools and resources. ... immersive education, futures trading support, and paperMoney® to practice ...
Read more >
CME Group: Futures & Options Trading for Risk Management
CME Group is the world's leading and most diverse derivatives marketplace offering the widest range of futures and options products for risk management....
Read more >
7 Tips Every Futures Trader Should Know | Charles Schwab
7 Tips Every Futures Trader Should Know · 1. Establish a trade plan · 2. Protect your positions · 3. Narrow your focus,...
Read more >
Futures and Commodities | FINRA.org
Commodities can help diversify an investment portfolio but might not be suitable for all investors. It's important to understand the products and markets...
Read more >
Invest in Futures | Online Futures Trading - E*TRADE
Available in brokerage and eligible IRAs; Trade futures listed on CME, ICE US, and CFE; Micro and E-mini contracts now available; Support from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found