Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT - mimic bfx websocket api #141

Closed

Conversation

tarcisiozf
Copy link
Contributor

@tarcisiozf tarcisiozf commented May 12, 2021

Description

The idea is to have a realistic bfx ws api mock for integration testing.

Design Spec

Real WS behavior:

With some handy components like the WsMock abstraction, we can create real ws servers and compose its message communication patterns.
Providing us realistic network communication testing, enforce async and connection handling.

Pseudo-random data generation:

This allows generating data to simulate market moves without the necessity to store it.
Also, by reusing the same seed as input, we can replay events to generate the output in a deterministic manner.

Extensible components:

The idea is to expand the BitfinexApiMock using event emitters and adapters easily as we are aiming to have low-coupling
(eg. data generators for channel subscriptions)

How to test

I've used the real example provided in examples/ao_host.js to create a base API mock that actually works, so basically you can set the environment variable pointing to the API mock:

  • API_KEY=api key
  • API_SECRET=api secret
  • WS_URL=ws://localhost:42000

start the API mock:

node test/integration/public_api_example.js

start the example:

node examples/ao_host.js

Possible future improvements

  • Replay events coming from files (CSV?)
  • Extract generic helpers (ws server/connection, pseudo-random data generator) into a different repo for reuse (maybe open-source it)
  • Add chaos factors for message delivery to test resilience and guarantees of message delivery

@@ -0,0 +1,20 @@
'use strict'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this example will be replaced by an actual integration test.

@@ -0,0 +1,54 @@
'use strict'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this example will be replaced by an actual integration test.

const _omit = require('lodash/omit')

const MAIN_CHAN_ID = 0
const SNAPSHOT_TYPES = ['ps', 'ws', 'os', 'fos', 'fcs', 'fls']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with constants with better naming

@ghost ghost mentioned this pull request May 17, 2021
@tarcisiozf
Copy link
Contributor Author

I'll reopen it with the final implementation

@tarcisiozf tarcisiozf closed this May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant