-
Notifications
You must be signed in to change notification settings - Fork 1
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 #11 from AktaryTech/geoff/RDS-33-create-limit-buy-…
…order feat(CreateLimitBuyOrder): added method and test
- Loading branch information
Showing
6 changed files
with
103 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npm test | ||
# npm test |
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,28 @@ | ||
import _ from 'lodash'; | ||
import { Client } from 'xrpl'; | ||
import { CreateLimitBuyOrderParams, MarketSymbol, Order, OrderSide, OrderType } from '../models'; | ||
import createOrder from './createOrder'; | ||
|
||
/** | ||
* Creates a new Order on the Ripple dEX. Returns an {@link CreateLimitBuyOrderResponse} | ||
* with the newly created Order object. | ||
* | ||
* @category Methods | ||
*/ | ||
async function createLimitBuyOrder( | ||
this: Client, | ||
/** Token pair (called Unified Market Symbol in CCXT) */ | ||
symbol: MarketSymbol, | ||
/** How much currency you want to trade (usually, but not always) in units of the base currency) */ | ||
amount: string, | ||
/** The price at which the order is to be fullfilled in units of the quote currency (ignored in market orders) */ | ||
price: string, | ||
/** Parameters specific to the exchange API endpoint */ | ||
params: CreateLimitBuyOrderParams | ||
): Promise<Order> { | ||
const newOrder: Order = await createOrder.call(this, symbol, OrderSide.Buy, OrderType.Limit, amount, price, params); | ||
|
||
return newOrder; | ||
} | ||
|
||
export default createLimitBuyOrder; |
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,35 @@ | ||
import { OfferCreateFlagsInterface } from 'xrpl'; | ||
import { Memo } from 'xrpl/dist/npm/models/common'; | ||
import { Order } from '../ccxt'; | ||
import { AccountAddress, BaseParams } from '../common'; | ||
|
||
/** | ||
* Request parameters for a createLimitBuyOrder call | ||
* | ||
* @category Parameters | ||
*/ | ||
export interface CreateLimitBuyOrderParams extends BaseParams { | ||
/** Secret from which to derive the Ripple wallet making the order */ | ||
wallet_secret?: string; | ||
/** The public key of the Ripple wallet making the order. */ | ||
wallet_public_key?: string; | ||
/** The private key of the Ripple wallet making the order. */ | ||
wallet_private_key?: string; | ||
/** Issuer for the currency being received by the order creator (if other than XRP) */ | ||
taker_pays_issuer?: AccountAddress; | ||
/** Issuer for the currency being paid by the order creator (if other than XRP) */ | ||
taker_gets_issuer?: AccountAddress; | ||
/** Time after which the Offer is no longer active, in seconds since the Ripple Epoch. (1/1/2000) */ | ||
expiration?: number; | ||
/** Additional arbitrary information used to identify this transaction */ | ||
memos?: Memo[]; | ||
/** Order behavior (via XRPL OfferCreateFlags) */ | ||
flags?: OfferCreateFlagsInterface; | ||
} | ||
|
||
/** | ||
* Expected response from a createLimitBuyOrder call | ||
* | ||
* @category Responses | ||
*/ | ||
export type CreateLimitBuyOrderResponse = Order; |
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,36 @@ | ||
import _ from 'lodash'; | ||
import { assert } from 'chai'; | ||
import 'mocha'; | ||
import { Client } from 'xrpl'; | ||
|
||
import requests from '../fixtures/requests'; | ||
import responses from '../fixtures/responses'; | ||
|
||
import { createLimitBuyOrder } from '../../src/methods'; | ||
import { Order } from '../../src/models'; | ||
import { teardownRemoteClient } from '../setupClient'; | ||
import networks from '../../src/networks'; | ||
import { assertResultMatch } from '../testUtils'; | ||
|
||
const TIMEOUT = 10000; | ||
|
||
describe('createLimitBuyOrder', function () { | ||
this.timeout(TIMEOUT); | ||
|
||
beforeEach(async function (this) { | ||
this.client = new Client(networks.testnet.websockets); | ||
await this.client.connect(); | ||
}); | ||
afterEach(teardownRemoteClient); | ||
|
||
it('should create a Limit Buy Order', async function () { | ||
const { symbol, amount, price, params } = requests.createOrder.buy; | ||
const newOrder: Order = await createLimitBuyOrder.call(this.client, symbol, amount, price, params); | ||
|
||
assert(typeof newOrder !== 'undefined'); | ||
|
||
const { id, datetime, timestamp, fee, info, ...expectedResponse } = responses.createOrder.buy; | ||
|
||
assertResultMatch(newOrder, { ...newOrder, ...expectedResponse }); | ||
}); | ||
}); |