forked from coinbase/coinbase-pro-trading-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* GDAXFeed#mapMessage: do not set the 'extra' property. The 'origin' property is already set by handleMessage() and UnknownMessage's documentation says that Any context-rich information can be extracted into the `extra` field, and the original message should be attached to the `origin` field as usual. * GDAXMessage: switch to discriminated unions types. Add a new GDAXMessage that is a union type and rename the old GDAXMessage to OptionalUserId, dropping the 'GDAX' and the 'Message' because the 'type property was removed since all sub-interfaces define it exactly and the since the OptionalUserId super-interface isn't meant to be publically used now. Add GDAXHeartbeatMessage and GDAXReceivedMessage which is required to avoid compiler errors with the current code. * GDAXMatchMessage: add maker_user_id and taker_user_id properties. * Move error handling out GDAXFeed#mapMessage. This is so the GDAXErrorMessage type is consistently handled between mapMessage and mapAuthMessage, useful for discriminated union. * GDAXFeed#mapFullFeed: simplify. * GDAXFeed#mapUnknown: new method to consistently handle messages. * GDAXFeed#handleMessage: use isGDAXMessage. Add attachSequence() to attach the incoming sequence number to an StreamMessage that the Writables will receive. * GDAXFeed: remove many type assertions. http://www.typescriptlang.org/docs/handbook/advanced-types.html This is made possible by TypeScript's discriminated unions. For example, handleMessage() calls isGDAXMessage(feedMessage) which means that tsc knows that feedMessage is a GDAXMessage after the if block. So switching on its type property means that the compiler knows exactly the sub-interface in the case clause. So no downcasts needd. Now that GDAXMessage is a union type, in a switch statement, the TypeScript compiler knows the GDAXMessage specific type so no type assertions are needed. * GDAXFeed#mapMessage: remove duplicate variable. * GDAXFeed#map*: tighten the input argument type. Do this for mapFullFeed(), mapMessage() and mapAuthMessage(). * GDAXFeed#mapMessage: statically assert that all types are handled. If one were to comment out a case statement in mapMessage() then tsc would generate a compile error. See https://www.typescriptlang.org/docs/handbook/advanced-types.html * GDAXFeed#mapAuthMessage: explicitly handle all message types. This is to generate a compile error if any new message types show up in the future, tsc will tell the developer that the new type needs to be handled. * GDAXFeed#mapAuthMessage: remove a type assertion to any. This is possible because of the stronger types, no need to check for a property if the compiler tells you it exists. * GDAXFeed#mapTicker: do not type assert the return object. See https://palantir.github.io/tslint/rules/no-object-literal-type-assertion/ . This showed that TickerMessage was missing a sequence property so add it, however, make it optional since it appears only the GDAX exchange has sequence numbers in ticker messages. * GDAXFeed#mapUnknown: set the origin property. This adds the origin property to the returned object. This fixes a bug where handleMessage() would receive a non-GDAXMessage and the UnknownMessage instance it pushes wouldn't have the origin property set.
- Loading branch information
Showing
4 changed files
with
198 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.