-
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.
Merge pull request #88 from Augmint/staging
* chore(package): update rollup to version 1.12.4 * publish API documentation (#83) * add toNumber to Wei (#85) * Market order matching estimates (#79) * Bump fstream from 1.0.11 to 1.0.12 (#86)
- Loading branch information
Showing
9 changed files
with
380 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
|
||
cat >./dist/sourcefile-map.json <<EOF | ||
[ | ||
{ | ||
"pattern": "^", | ||
"replace": "${REPOSITORY_URL}/tree/${BRANCH}/src/" | ||
} | ||
] | ||
EOF | ||
|
||
typedoc \ | ||
--out ./dist/docs ./src \ | ||
--mode modules \ | ||
--target ES6 \ | ||
--tsconfig ./tsconfig.json \ | ||
--exclude node_modules \ | ||
--ignoreCompilerErrors \ | ||
--excludeExternals \ | ||
--excludePrivate \ | ||
--excludeNotExported \ | ||
--sourcefile-url-map ./dist/sourcefile-map.json |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const { assert } = require("chai"); | ||
|
||
const { normalizeBN } = require("./testHelpers/normalize.js"); | ||
const { Augmint, utils, Wei, Tokens, Ratio } = require("../dist/index.js"); | ||
const loadEnv = require("./testHelpers/loadEnv.js"); | ||
const OrderBook = Augmint.Exchange.OrderBook; | ||
|
||
const config = loadEnv(); | ||
|
||
if (config.LOG) { | ||
utils.logger.level = config.LOG; | ||
} | ||
|
||
const RATE = Tokens.of(400.00); | ||
|
||
describe("calculate market orders", () => { | ||
it("should return matching info", () => { | ||
const buyOrders = [ | ||
{ amount: Wei.of(0.0070), price: Ratio.of(1.2) }, | ||
{ amount: Wei.of(0.0094), price: Ratio.of(1) }, | ||
{ amount: Wei.of(0.0064), price: Ratio.of(0.7) } | ||
]; | ||
|
||
const sellOrders = [ | ||
{ amount: Tokens.of(1), price: Ratio.of(1.02) }, | ||
{ amount: Tokens.of(10), price: Ratio.of(1.03) } | ||
]; | ||
|
||
const orderBook = new OrderBook(buyOrders, sellOrders); | ||
|
||
const sellResult = { | ||
filledTokens: Tokens.of(6), | ||
filledEthers: Wei.of(0.016165), | ||
limitPrice: Ratio.of(1), | ||
averagePrice: Ratio.of(1.077673) | ||
}; | ||
|
||
const sellMatches = orderBook.estimateMarketSell(Tokens.of(6), RATE); | ||
|
||
assert.deepEqual(normalizeBN(sellResult), normalizeBN(sellMatches)); | ||
|
||
const buyResult = { | ||
filledTokens: Tokens.of(2), | ||
filledEthers: Wei.of(0.005125), | ||
limitPrice: Ratio.of(1.03), | ||
averagePrice: Ratio.of(1.02501) | ||
}; | ||
|
||
const buyMatches = orderBook.estimateMarketBuy(Tokens.of(2), RATE); | ||
|
||
assert.deepEqual(normalizeBN(buyMatches), normalizeBN(buyResult)); | ||
}); | ||
|
||
it("should work on empty order book", () => { | ||
const orderBook = new OrderBook([], []); | ||
const exp = { | ||
filledTokens: Tokens.of(0), | ||
filledEthers: Wei.of(0) | ||
}; | ||
const buyMatches = orderBook.estimateMarketBuy(Tokens.of(100), RATE); | ||
const sellMatches = orderBook.estimateMarketSell(Tokens.of(100), RATE) | ||
assert.deepEqual(normalizeBN(buyMatches), normalizeBN(exp)); | ||
assert.deepEqual(normalizeBN(sellMatches), normalizeBN(exp)); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const BN = require("bn.js"); | ||
|
||
BN.prototype.inspect = function() { | ||
return this.toString(); | ||
}; | ||
|
||
module.exports = { normalizeBN }; | ||
|
||
// deeply normalize all BN properties so they can be compared with deepEquals | ||
// NOTE: object graph must not have cycles | ||
function normalizeBN(obj) { | ||
Object.keys(obj).map((key, index) => { | ||
const o = obj[key]; | ||
if (o instanceof BN) { | ||
obj[key] = new BN(o.toString()); | ||
} else if (o instanceof Object) { | ||
obj[key] = normalizeBN(o); | ||
} | ||
}); | ||
return obj; | ||
} |
Oops, something went wrong.