-
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.
This replaces the partially implemented `ListTrades` call with the more comprehensive and descriptive `TradeHistory`. This displays key info about every trade we have made. Closes #1232.
- Loading branch information
Showing
25 changed files
with
1,943 additions
and
1,443 deletions.
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
This file was deleted.
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,73 @@ | ||
import Table, { HorizontalTable } from 'cli-table3'; | ||
import colors from 'colors/safe'; | ||
import { Arguments, Argv } from 'yargs'; | ||
import { Role, Trade, TradeHistoryRequest, TradeHistoryResponse } from '../../proto/xudrpc_pb'; | ||
import { callback, loadXudClient } from '../command'; | ||
import { satsToCoinsStr, trim } from '../utils'; | ||
|
||
const HEADERS = [ | ||
colors.blue('Maker Order'), | ||
colors.blue('Taker Order'), | ||
colors.blue('Swap Hash'), | ||
colors.blue('Price'), | ||
colors.blue('Quantity'), | ||
colors.blue('Role'), | ||
colors.blue('Counterparty'), | ||
colors.blue('Executed At'), | ||
]; | ||
|
||
const displayTrades = (trades: TradeHistoryResponse.AsObject) => { | ||
const table = new Table({ head: HEADERS }) as HorizontalTable; | ||
trades.tradesList.forEach((trade: Trade.AsObject) => { | ||
const [baseCurrency, quoteCurrency] = trade.pairId.split('/'); | ||
let counterparty: string; | ||
let role: string; | ||
switch (trade.role) { | ||
case Role.TAKER: | ||
counterparty = trade.makerOrder!.nodeIdentifier!.alias; | ||
role = 'Taker'; | ||
break; | ||
case Role.MAKER: | ||
counterparty = trade.takerOrder!.nodeIdentifier!.alias; | ||
role = 'Maker'; | ||
break; | ||
case Role.INTERNAL: | ||
counterparty = ''; | ||
role = 'Internal'; | ||
break; | ||
} | ||
const details = [ | ||
trim(trade.makerOrder?.id ?? '', 8), | ||
trim(trade.takerOrder?.id ?? '', 8), | ||
trim(trade.rHash, 6), | ||
`${trade.price} ${quoteCurrency}`, | ||
`${satsToCoinsStr(trade.quantity)} ${baseCurrency}`, | ||
role, | ||
counterparty, | ||
new Date(trade.executedAt).toLocaleString(), | ||
]; | ||
|
||
table.push(details); | ||
}); | ||
console.log(colors.underline(colors.bold('\Trades:'))); | ||
console.log(table.toString()); | ||
}; | ||
|
||
export const command = 'tradehistory [limit]'; | ||
|
||
export const describe = 'list completed trades'; | ||
|
||
export const builder = (argv: Argv) => argv | ||
.option('limit', { | ||
description: 'the maximum number of trades to display', | ||
type: 'number', | ||
default: 15, | ||
}) | ||
.example('$0 tradehistory', 'list most recent trades') | ||
.example('$0 tradehistory 50', 'list the 50 most recent trades'); | ||
|
||
export const handler = async (argv: Arguments<any>) => { | ||
const request = new TradeHistoryRequest(); | ||
request.setLimit(argv.limit); | ||
(await loadXudClient(argv)).tradeHistory(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
Oops, something went wrong.