diff --git a/src/api/ledger/orderbook.js b/src/api/ledger/orderbook.js index f211ea98..75b0a848 100644 --- a/src/api/ledger/orderbook.js +++ b/src/api/ledger/orderbook.js @@ -40,9 +40,13 @@ function formatBidsAndAsks(orderbook, offers) { // for both bids and asks, lowest quality is closest to mid-market // we sort the orders so that earlier orders are closer to mid-market const orders = _.sortBy(offers, 'quality').map(parseOrderbookOrder); - const bids = orders.filter(_.partial(orderFilter, orderbook.base, 'buy')); - const asks = orders.filter(_.partial(orderFilter, orderbook.base, 'sell')); - return {bids, asks}; + const {base, counter} = orderbook; + const bids = orders.filter(_.partial(orderFilter, base, 'buy')); + const asks = orders.filter(_.partial(orderFilter, base, 'sell')); + const flippedBids = orders.filter(_.partial(orderFilter, counter, 'buy')); + const flippedAsks = orders.filter(_.partial(orderFilter, counter, 'sell')); + const flipped = {bids: flippedBids, asks: flippedAsks}; + return {bids, asks, flipped}; } function getOrderBook(account, orderbook, options, callback) { diff --git a/test/fixtures/get-orderbook-response.json b/test/fixtures/get-orderbook-response.json index c5b49bee..3b163a95 100644 --- a/test/fixtures/get-orderbook-response.json +++ b/test/fixtures/get-orderbook-response.json @@ -366,5 +366,99 @@ "sequence": 35789 } } - ] + ], + "flipped": { + "bids": [ + { + "specification": { + "direction": "buy", + "quantity": { + "currency": "BTC", + "value": "93.030522464522", + "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }, + "totalPrice": { + "currency": "USD", + "value": "0.2849323720855092", + "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + } + }, + "properties": { + "maker": "rwBYyfufTzk77zUSKEu4MvixfarC35av1J", + "sequence": 386940 + } + }, + { + "specification": { + "direction": "buy", + "quantity": { + "currency": "BTC", + "value": "1", + "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }, + "totalPrice": { + "currency": "USD", + "value": "0.00302447007930511", + "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + } + }, + "properties": { + "maker": "rwjsRktX1eguUr1pHTffyHnC4uyrvX58V1", + "sequence": 207855 + } + }, + { + "specification": { + "direction": "buy", + "quantity": { + "currency": "BTC", + "value": "182.9814890090516", + "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }, + "totalPrice": { + "currency": "USD", + "value": "0.5", + "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + } + }, + "properties": { + "maker": "rUeCeioKJkbYhv4mRGuAbZpPcqkMCoYq6N", + "sequence": 5255 + }, + "state": { + "availableQuantity": { + "currency": "BTC", + "value": "82.50309772176658", + "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }, + "priceOfAvailableQuantity": { + "currency": "USD", + "value": "0.2254411038203033", + "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + } + } + } + ], + "asks": [ + { + "specification": { + "direction": "sell", + "quantity": { + "currency": "BTC", + "value": "1.24252537879871", + "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + }, + "totalPrice": { + "currency": "USD", + "value": "0.003967400879423823", + "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" + } + }, + "properties": { + "maker": "rDbsCJr5m8gHDCNEHCZtFxcXHsD4S9jH83", + "sequence": 110099 + } + } + ] + } }