Skip to content

Commit

Permalink
Rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
rsercano committed Oct 20, 2020
2 parents e2ff8c2 + 77079ee commit b57f63f
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 214 deletions.
1 change: 0 additions & 1 deletion lib/service/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,6 @@ class Service {
const array = side === OrderSide.Sell ? orderArrays.buyArray : orderArrays.sellArray;
for (const order of array) {
if (order.quantity && order.price) {
// market buy max calculation
const maxBuyableFromThisPrice = currentBalance / order.price;
const calculatedQuantity = (maxBuyableFromThisPrice > order.quantity) ? order.quantity : maxBuyableFromThisPrice;
result += calculatedQuantity;
Expand Down
2 changes: 1 addition & 1 deletion proto/xudrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ message TradingLimits {
// The outbound amount reserved for open orders.
uint64 reserved_outbound = 3 [json_name = "reserved_outbound"];
// The inbound amount reserved for open orders.
uint64 reserved_inbound = 4 [json_name = "reserved_outbound"];
uint64 reserved_inbound = 4 [json_name = "reserved_inbound"];
}

message TradingLimitsRequest {
Expand Down
12 changes: 5 additions & 7 deletions test/integration/Service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,8 @@ describe('API Service', () => {
btcUsdt.set('BTC/USDT', {
buyArray: [],
sellArray: [
{ quantity: 0.00045, price: 15000, pairId: 'BTC/USDT', id: 'test_1', createdAt: 1, side: OrderSide.Sell,
{ quantity: 0.38919755, price: 12082.5528, pairId: 'BTC/USDT', id: 'test_1', createdAt: 1, side: OrderSide.Sell,
isOwnOrder: false, nodeIdentifier: { nodePubKey: 'some_key1' } },
{ quantity: 1.05, price: 20000, pairId: 'BTC/USDT', id: 'test_2', createdAt: 1, side: OrderSide.Sell,
isOwnOrder: false, nodeIdentifier: { nodePubKey: 'some_key2' } },
],
});
const ethBtc = new Map<string, ServiceOrderSidesArrays>();
Expand Down Expand Up @@ -425,20 +423,20 @@ describe('API Service', () => {
const tradingLimitsMap = new Map<string, TradingLimits>();
tradingLimitsMap.set('BTC', {
maxSell: 0,
maxBuy : 1.025,
maxBuy : 2.4499095,
reservedOutbound: 0,
reservedInbound: 0,
});
tradingLimitsMap.set('USDT', {
maxSell: 5,
maxSell: 1000,
maxBuy : 0,
reservedOutbound: 0,
reservedInbound: 0,
});
tradingLimitsStub.returns(Promise.resolve(tradingLimitsMap));

const number = await service['calculateOrderMaxQuantity']('BTC', 'USDT', OrderSide.Buy, undefined, SwapClientType.Lnd, SwapClientType.Connext);
await expect(number).to.equal(0.0003333333333333333);
await expect(number).to.equal(0.08276396689944529);
});

it('should return min(max amount of base using max sell bound for quote, buy max base) lnd/connext mkt buy - 2', async () => {
Expand All @@ -458,7 +456,7 @@ describe('API Service', () => {
tradingLimitsStub.returns(Promise.resolve(tradingLimitsMap));

const number = await service['calculateOrderMaxQuantity']('BTC', 'USDT', OrderSide.Buy, undefined, SwapClientType.Lnd, SwapClientType.Connext);
await expect(number).to.equal(0.00006666666666666667);
await expect(number).to.equal(0.0000827639668994453);
});

it('should return (uses max sell bound for quote to calculate base amount) connext/lnd mkt buy', async () => {
Expand Down
Loading

0 comments on commit b57f63f

Please sign in to comment.