{"id":22359016,"url":"https://github.com/bitcoinwarrior1/bfx-test","last_synced_at":"2025-03-26T13:44:53.712Z","repository":{"id":203330959,"uuid":"708274327","full_name":"bitcoinwarrior1/bfx-test","owner":"bitcoinwarrior1","description":"The Bitfinex backend challenge","archived":false,"fork":false,"pushed_at":"2023-10-22T05:45:58.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T15:19:02.848Z","etag":null,"topics":["bitfinex","exchange","grenache","p2p"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitcoinwarrior1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-22T03:46:57.000Z","updated_at":"2023-12-22T21:43:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"a8c6a443-9840-43a1-852a-6287ff0ca77a","html_url":"https://github.com/bitcoinwarrior1/bfx-test","commit_stats":null,"previous_names":["james-sangalli/bfx-test","bitcoinwarrior1/bfx-test"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoinwarrior1%2Fbfx-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoinwarrior1%2Fbfx-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoinwarrior1%2Fbfx-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoinwarrior1%2Fbfx-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitcoinwarrior1","download_url":"https://codeload.github.com/bitcoinwarrior1/bfx-test/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245667751,"owners_count":20652983,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitfinex","exchange","grenache","p2p"],"created_at":"2024-12-04T15:19:08.921Z","updated_at":"2025-03-26T13:44:53.688Z","avatar_url":"https://github.com/bitcoinwarrior1.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The BFX challenge\n\nHi and congratulations to your progress with Bitfinex!\n\nYour task is to create a simplified P2P distributed exchange\n\n* Each client will have its own instance of the orderbook.\n* Clients submit orders to their own instance of orderbook. The order is distributed to other instances, too.\n* If a client's order matches with another order, any remainer is added to the orderbook, too.\n\nRequirement:\n* Code in Javascript\n* Use Grenache for communication between nodes\n* Simple order matching engine\n* You don't need to create a UI or HTTP API\n\nYou 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.\n\n\nIf 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.\n\nGood luck!\n\n## Tips\n\n- you don't need to store state in a DB or filesystem\n- it is possible to solve the task with the node std lib, async and grenache libraries\n- beware of race conditions!\n- no need for express or any other http api layers\n\n### Setting up the DHT\n\n```\nnpm i -g grenache-grape\n```\n\n```\n# boot two grape servers\n\ngrape --dp 20001 --aph 30001 --bn '127.0.0.1:20002'\ngrape --dp 20002 --aph 40001 --bn '127.0.0.1:20001'\n```\n\n### Setting up Grenache in your project\n\n```\nnpm install --save grenache-nodejs-http\nnpm install --save grenache-nodejs-link\n```\n\n\n### Example RPC server / client with \"Hello World\"\n\n```js\n// This RPC server will announce itself as `rpc_test`\n// in our Grape Bittorrent network\n// When it receives requests, it will answer with 'world'\n\n'use strict'\n\nconst { PeerRPCServer }  = require('grenache-nodejs-http')\nconst Link = require('grenache-nodejs-link')\n\n\nconst link = new Link({\n  grape: 'http://127.0.0.1:30001'\n})\nlink.start()\n\nconst peer = new PeerRPCServer(link, {\n  timeout: 300000\n})\npeer.init()\n\nconst port = 1024 + Math.floor(Math.random() * 1000)\nconst service = peer.transport('server')\nservice.listen(port)\n\nsetInterval(function () {\n  link.announce('rpc_test', service.port, {})\n}, 1000)\n\nservice.on('request', (rid, key, payload, handler) =\u003e {\n  console.log(payload) //  { msg: 'hello' }\n  handler.reply(null, { msg: 'world' })\n})\n\n```\n\n```js\n// This client will as the DHT for a service called `rpc_test`\n// and then establishes a P2P connection it.\n// It will then send { msg: 'hello' } to the RPC server\n\n'use strict'\n\nconst { PeerRPCClient }  = require('grenache-nodejs-http')\nconst Link = require('grenache-nodejs-link')\n\nconst link = new Link({\n  grape: 'http://127.0.0.1:30001'\n})\nlink.start()\n\nconst peer = new PeerRPCClient(link, {})\npeer.init()\n\npeer.request('rpc_test', { msg: 'hello' }, { timeout: 10000 }, (err, data) =\u003e {\n  if (err) {\n    console.error(err)\n    process.exit(-1)\n  }\n  console.log(data) // { msg: 'world' }\n})\n```\n\n### More Help\n\n- http://blog.bitfinex.com/tutorial/bitfinex-loves-microservices-grenache/\n- https://github.com/bitfinexcom/grenache-nodejs-example-fib-client\n- https://github.com/bitfinexcom/grenache-nodejs-example-fib-server\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitcoinwarrior1%2Fbfx-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitcoinwarrior1%2Fbfx-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitcoinwarrior1%2Fbfx-test/lists"}