Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bitcoinwarrior1/bfx-test
The Bitfinex backend challenge
https://github.com/bitcoinwarrior1/bfx-test
bitfinex exchange grenache p2p
Last synced: 22 days ago
JSON representation
The Bitfinex backend challenge
- Host: GitHub
- URL: https://github.com/bitcoinwarrior1/bfx-test
- Owner: bitcoinwarrior1
- Created: 2023-10-22T03:46:57.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-22T05:45:58.000Z (about 1 year ago)
- Last Synced: 2023-12-10T01:26:57.449Z (about 1 year ago)
- Topics: bitfinex, exchange, grenache, p2p
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# The BFX challenge
Hi and congratulations to your progress with Bitfinex!
Your task is to create a simplified P2P distributed exchange
* Each client will have its own instance of the orderbook.
* Clients submit orders to their own instance of orderbook. The order is distributed to other instances, too.
* If a client's order matches with another order, any remainer is added to the orderbook, too.Requirement:
* Code in Javascript
* Use Grenache for communication between nodes
* Simple order matching engine
* You don't need to create a UI or HTTP APIYou should not spend more time than 6-8 hours on the task. We know that its probably not possible to complete the task 100% in the given time.
If you don't get to the end, just write up what is missing for a complete implementation of the task. Also, if your implementation has limitation and issues, that's no big deal. Just write everything down and indicate how you could solve them, given there was more time.
Good luck!
## Tips
- you don't need to store state in a DB or filesystem
- it is possible to solve the task with the node std lib, async and grenache libraries
- beware of race conditions!
- no need for express or any other http api layers### Setting up the DHT
```
npm i -g grenache-grape
``````
# boot two grape serversgrape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'
grape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'
```### Setting up Grenache in your project
```
npm install --save grenache-nodejs-http
npm install --save grenache-nodejs-link
```### Example RPC server / client with "Hello World"
```js
// This RPC server will announce itself as `rpc_test`
// in our Grape Bittorrent network
// When it receives requests, it will answer with 'world''use strict'
const { PeerRPCServer } = require('grenache-nodejs-http')
const Link = require('grenache-nodejs-link')const link = new Link({
grape: 'http://127.0.0.1:30001'
})
link.start()const peer = new PeerRPCServer(link, {
timeout: 300000
})
peer.init()const port = 1024 + Math.floor(Math.random() * 1000)
const service = peer.transport('server')
service.listen(port)setInterval(function () {
link.announce('rpc_test', service.port, {})
}, 1000)service.on('request', (rid, key, payload, handler) => {
console.log(payload) // { msg: 'hello' }
handler.reply(null, { msg: 'world' })
})```
```js
// This client will as the DHT for a service called `rpc_test`
// and then establishes a P2P connection it.
// It will then send { msg: 'hello' } to the RPC server'use strict'
const { PeerRPCClient } = require('grenache-nodejs-http')
const Link = require('grenache-nodejs-link')const link = new Link({
grape: 'http://127.0.0.1:30001'
})
link.start()const peer = new PeerRPCClient(link, {})
peer.init()peer.request('rpc_test', { msg: 'hello' }, { timeout: 10000 }, (err, data) => {
if (err) {
console.error(err)
process.exit(-1)
}
console.log(data) // { msg: 'world' }
})
```### More Help
- http://blog.bitfinex.com/tutorial/bitfinex-loves-microservices-grenache/
- https://github.com/bitfinexcom/grenache-nodejs-example-fib-client
- https://github.com/bitfinexcom/grenache-nodejs-example-fib-server