<template>
<Page class="page">
<ActionBar class="action-bar">
<Label class="action-bar-title" text="Home"></Label>
</ActionBar>
<GridLayout>
<Label
class="info"
horizontalAlignment="center"
verticalAlignment="center"
>
<FormattedString>
<Span class="fa" text.decode=" " />
<Span :text="message" />
</FormattedString>
</Label>
</GridLayout>
</Page>
</template>
<script>
export default {
computed: {
message() {
return "Blank {N}-Vue app"
}
}
}
</script>
<style scoped lang="scss">
// Start custom common variables
@import "../app-variables";
// End custom common variables
// Custom styles
.fa {
color: $accent-dark;
}
.info {
font-size: 20;
}
</style>
<template>
<Page class="page">
<ActionBar class="action-bar">
<Label class="action-bar-title" text="Home"></Label>
</ActionBar>
<GridLayout rows="auto,*,auto">
<StackLayout row="0">
<Label class="info" horizontalAlignment="center">钱包</Label>
<TextView :text="wallet_text" editable="false"></TextView>
</StackLayout>
<StackLayout row="1" verticalAlignment="middle">
<Label class="info" horizontalAlignment="center">帐本</Label>
<TextView :text="ledger_text" editable="false"></TextView>
</StackLayout>
<StackLayout row="2">
<Button class="btn btn-primary full" horizontalAlignment="center"
>价格</Button
>
<TextView :text="price_text" editable="false"></TextView>
</StackLayout>
</GridLayout>
</Page>
</template>
<script>
const SwtcLib = require("@swtc/lib")
const Wallet = SwtcLib.Wallet
const Remote = SwtcLib.Remote
const remote = new Remote()
const currency_swt = remote.makeCurrency()
const currency_cny = remote.makeCurrency("CNY")
const swt_vs_cny = { limit: 5, gets: currency_swt, pays: currency_cny }
export default {
data() {
return {
wallet: {},
ledger: {},
price: [],
state: ""
}
},
computed: {
wallet_text() {
return JSON.stringify(this.wallet, "", 2)
},
ledger_text() {
return JSON.stringify(this.ledger, "", 2)
},
price_text() {
return this.price.join("\n")
}
},
created() {
this.wallet = Wallet.generate()
},
async mounted() {
try {
await remote.connectPromise()
remote.on("ledger_closed", ledger_data => {
this.ledger = ledger_data
})
} catch (error) {
this.state = "连接不上"
}
setInterval(() => {
this.wallet = Wallet.generate()
console.log(this.wallet)
}, 10000)
setInterval(() => {
remote.requestOrderBook(swt_vs_cny).submit((error, orderbooks) => {
if (error) {
this.state = "查询挂单出错了"
} else {
orderbooks.offers.map(offer => {
let quantity = Math.floor(parseInt(offer.TakerPays) / 1000000)
let price =
Math.floor((1000000 * 1000 * 100) / Number(offer.quality)) /
100000
this.price.unshift(
`价格: ${price}\t挂单量: ${quantity}\t${offer.Account}`
)
this.price.splice(5)
})
}
})
}, 10000)
}
}
</script>
<style scoped lang="scss">
// Start custom common variables
@import "../app-variables";
// End custom common variables
// Custom styles
.info {
font-size: 20;
}
</style>