Skip to content

Commit

Permalink
sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
tacyarg committed Dec 15, 2019
1 parent f96ad9c commit 3ea672e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions apps/trader.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function main(config, { bybit, stats, trades, events, tickers }) {
if (trade) {
close = trader.close(trade.id, price, trade.qty)
}
return { ...trade, ...close }
return { ...trade, ...close, updated: r.created }
}

// close the previous position.
Expand All @@ -69,11 +69,11 @@ async function main(config, { bybit, stats, trades, events, tickers }) {
switch (r.type) {
case 'LONG': {
const long = trader.openLong(r.id, price)
return { ...r, ...long }
return { ...r, ...long, created: r.created }
}
case 'SHORT': {
const short = trader.openShort(r.id, price)
return { ...r, ...short }
return { ...r, ...short, created: r.created }
}
// case 'MARKET_TREND': {
// // const stats = trader.updateMarketCondition(r.marketCondition)
Expand Down
2 changes: 1 addition & 1 deletion libs/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ module.exports = ({
const provider = await users.get(providerid)
assert(provider.userid === userid, 'provider does not belong to you.')

return trades.listUserSorted(provider.id)
return trades.listUserSorted(provider.id, 'desc')
},
async listMyProviderStats({ token }) {
assert(token, 'token required')
Expand Down
6 changes: 3 additions & 3 deletions models/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = async con => {
const q = table
.table()
.orderBy({ index: table.r.desc('created') })
.limit(100)
.limit(1000)
.coerceTo('array')
return table.run(q)
},
Expand All @@ -43,7 +43,7 @@ module.exports = async con => {
.table()
.orderBy({ index: 'created' })
.filter({ userid })
.limit(100)
.limit(1000)
.coerceTo('array')
return table.run(query)
},
Expand All @@ -52,7 +52,7 @@ module.exports = async con => {
.table()
.orderBy({ index: 'created' })
.filter({ [index]: value })
.limit(100)
.limit(1000)
.coerceTo('array')
return table.run(query)
},
Expand Down
8 changes: 4 additions & 4 deletions models/trades.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ module.exports = async con => {
const q = table
.table()
.orderBy({ index: table.r.desc('created') })
.limit(100)
.limit(1000)
.coerceTo('array')
return table.run(q)
},
listUserSorted(userid) {
listUserSorted(userid, sort ='desc') {
const query = table
.table()
.orderBy({ index: 'created' })
.orderBy({ index: table.r[sort]('created') })
.filter({ userid })
.limit(100)
.limit(1000)
.coerceTo('array')
return table.run(query)
},
Expand Down

0 comments on commit 3ea672e

Please sign in to comment.