node-ib icon indicating copy to clipboard operation
node-ib copied to clipboard

Use named parameters for ib.contract.XXX

Open tredondo opened this issue 7 years ago • 4 comments

The long list of parameters for various contract types is unwieldy, and also inconsistent in the parameter order:

future: symbol, expiry, currency, exchange, multiplier fop: symbol, expiry, strike, right, multiplier, exchange, currency

Using destructured parameters would make calls consistent, and much less error-prone:

ib.contract.future({
  symbol: 'YM',
  expiry: '...',
  multiplier: 5,
  exchange: 'GLOBEX',  // for some reason the default exchange for futures is ONE
});

I'm writing a function that parses strings into contract and it's a long switch statement right now because of the variable parameter order.

tredondo avatar Dec 07 '18 04:12 tredondo

@meteorpublish I agree this change will make writing contracts more flexible and easier to read, however it'll be a breaking change. Any suggestion for introducing this without touching existing API?

pilwon avatar Jun 22 '19 09:06 pilwon

Well, since the package is at v0.x, its API is not really guaranteed per semver anyway. One suggestion would be to release v1, rewritten using ES Modules, and with named parameters.

For v0.3, could ib.contract be overridden to take named parameters, e.g.

ib.contract({ type: 'stock', symbol: 'AAPL' })

Otherwise, methods with an O (for "object") suffix could be used:

ib.contract.fopO({ symbol: 'ES', expiry: '20190920', strike: ..., })

tredondo avatar Jul 05 '19 07:07 tredondo

@meteorpublish Yes, you're right about v0.x. I however still wish to maintain this library that doesn't surprise existing users unless it's absolutely necessary. I prefer the cleaner ib.contract({ ... }) option.

pilwon avatar Jul 12 '19 13:07 pilwon

@pilwon: do you still have time to maintain this library? I've submitted a PR announcing that it needs maintainers.

tredondo avatar Mar 04 '20 12:03 tredondo