-
Notifications
You must be signed in to change notification settings - Fork 43
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 #791 from ExchangeUnion/listTrades-grpc
feat: listtrades grpc command #667
- Loading branch information
Showing
13 changed files
with
1,019 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,53 @@ | ||
import { Arguments } from 'yargs'; | ||
import { callback, loadXudClient } from '../command'; | ||
import { ListTradesRequest, ListTradesResponse, Trade } from '../../proto/xudrpc_pb'; | ||
import Table, { HorizontalTable } from 'cli-table3'; | ||
import colors from 'colors/safe'; | ||
import { satsToCoinsStr } from '../utils'; | ||
|
||
const HEADERS = [ | ||
colors.blue('Trading Pair'), | ||
colors.blue('Trade Quantity'), | ||
colors.blue('Price'), | ||
colors.blue('Order Type'), | ||
]; | ||
|
||
const displayTrades = (trades: ListTradesResponse.AsObject) => { | ||
const table = new Table({ head: HEADERS }) as HorizontalTable; | ||
trades.tradesList.forEach((trade: Trade.AsObject) => { | ||
const type = trade.makerOrder ? 'maker' : 'taker'; | ||
let price = 0; | ||
if (trade.makerOrder) { | ||
price = trade.makerOrder.price; | ||
} else if (trade.takerOrder) { | ||
price = trade.takerOrder.price; | ||
} | ||
|
||
table.push([ | ||
trade.pairId, | ||
satsToCoinsStr(trade.quantity), | ||
parseFloat(price.toFixed(5)), | ||
type, | ||
]); | ||
}); | ||
console.log(colors.underline(colors.bold('\Trades:'))); | ||
console.log(table.toString()); | ||
}; | ||
|
||
export const command = 'listtrades [limit]'; | ||
|
||
export const describe = 'list completed trades'; | ||
|
||
export const builder = { | ||
limit: { | ||
description: 'the maximum number of trades to display', | ||
type: 'number', | ||
default: 15, | ||
}, | ||
}; | ||
|
||
export const handler = (argv: Arguments) => { | ||
const request = new ListTradesRequest(); | ||
request.setLimit(argv.limit); | ||
loadXudClient(argv).listTrades(request, callback(argv, displayTrades)); | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.