Fix delay when bad request. Fixavg premium to weighted avg premium

This commit is contained in:
Reckless_Satoshi 2022-01-15 06:22:07 -08:00
parent 8e609b9e47
commit f390a8f2f1
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 27 additions and 20 deletions

View File

@ -369,7 +369,7 @@ class Logics():
order.last_satoshis = cls.satoshis_now(order) order.last_satoshis = cls.satoshis_now(order)
bond_satoshis = int(order.last_satoshis * BOND_SIZE) bond_satoshis = int(order.last_satoshis * BOND_SIZE)
pos_text = 'Buying' if cls.is_buyer(order, user) else 'Selling' pos_text = 'Buying' if cls.is_buyer(order, user) else 'Selling'
description = (f"RoboSats - Taking 'Order {order.id}' {pos_text} BTC for {float(order.amount) + Order.currency_dict[str(order.currency)]}" description = (f"RoboSats - Taking 'Order {order.id}' {pos_text} BTC for {str(float(order.amount)) + Order.currency_dict[str(order.currency)]}"
+ " - This is a taker bond, it will freeze in your wallet temporarily and automatically return. It will be charged if you cheat or cancel.") + " - This is a taker bond, it will freeze in your wallet temporarily and automatically return. It will be charged if you cheat or cancel.")
# Gen hold Invoice # Gen hold Invoice

View File

@ -207,7 +207,7 @@ class OrderView(viewsets.ViewSet):
def take_update_confirm_dispute_cancel(self, request, format=None): def take_update_confirm_dispute_cancel(self, request, format=None):
''' '''
Here takes place all of updatesto the order object. Here takes place all of the updates to the order object.
That is: take, confim, cancel, dispute, update_invoice or rate. That is: take, confim, cancel, dispute, update_invoice or rate.
''' '''
order_id = request.GET.get(self.lookup_url_kwarg) order_id = request.GET.get(self.lookup_url_kwarg)
@ -430,18 +430,20 @@ class InfoView(ListAPIView):
queryset = MarketTick.objects.filter(timestamp__day=today.day) queryset = MarketTick.objects.filter(timestamp__day=today.day)
if not len(queryset) == 0: if not len(queryset) == 0:
premiums = [] weighted_premiums = []
volumes = [] volumes = []
for tick in queryset: for tick in queryset:
premiums.append(tick.premium) weighted_premiums.append(tick.premium*tick.volume)
volumes.append(tick.volume) volumes.append(tick.volume)
avg_premium = sum(premiums) / len(premiums)
total_volume = sum(volumes) total_volume = sum(volumes)
# Avg_premium is the weighted average of the premiums by volume
avg_premium = sum(weighted_premiums) / total_volume
else: else:
avg_premium = 0 avg_premium = 0
total_volume = 0 total_volume = 0
context['today_avg_nonkyc_btc_premium'] = avg_premium context['today_avg_nonkyc_btc_premium'] = round(avg_premium,2)
context['today_total_volume'] = total_volume context['today_total_volume'] = total_volume
context['lnd_version'] = get_lnd_version() context['lnd_version'] = get_lnd_version()
context['robosats_running_commit_hash'] = get_commit_robosats() context['robosats_running_commit_hash'] = get_commit_robosats()

View File

@ -25,7 +25,7 @@ export default class BottomBar extends Component {
num_public_sell_orders: null, num_public_sell_orders: null,
fee: null, fee: null,
today_avg_nonkyc_btc_premium: null, today_avg_nonkyc_btc_premium: null,
today_volume: null, today_total_volume: null,
}; };
this.getInfo(); this.getInfo();
} }
@ -78,7 +78,7 @@ export default class BottomBar extends Component {
<Divider/> <Divider/>
<ListItem> <ListItem>
<ListItemIcon><EqualizerIcon/></ListItemIcon> <ListItemIcon><EqualizerIcon/></ListItemIcon>
<ListItemText primary={this.state.today_volume} secondary="Today traded volume"/> <ListItemText primary={this.state.today_total_volume+" BTC"} secondary="Today traded volume"/>
</ListItem> </ListItem>
</List> </List>
</DialogContent> </DialogContent>
@ -203,8 +203,8 @@ export default class BottomBar extends Component {
<ListItemText <ListItemText
primaryTypographyProps={{fontSize: '14px'}} primaryTypographyProps={{fontSize: '14px'}}
secondaryTypographyProps={{fontSize: '12px'}} secondaryTypographyProps={{fontSize: '12px'}}
primary={this.state.today_avg_nonkyc_btc_premium} primary={this.state.today_avg_nonkyc_btc_premium+"%"}
secondary="Today Avg Premium" /> secondary="Today Non-KYC Avg Premium" />
</ListItem> </ListItem>
</Grid> </Grid>

View File

@ -89,7 +89,7 @@ export default class InfoDialog extends Component {
inspecting the source code </a> </p> inspecting the source code </a> </p>
</Typography> </Typography>
<Typography component="h5" variant="h5">What happens if <i>RoboSats</i> suddently disapears?</Typography> <Typography component="h5" variant="h5">What happens if <i>RoboSats</i> suddenly disapears?</Typography>
<Typography component="body2" variant="body2"> <Typography component="body2" variant="body2">
<p> Your sats will most likely return to you. Any hold invoice that is not <p> Your sats will most likely return to you. Any hold invoice that is not
settled would be automatically returned even if <i>RoboSats</i> goes down settled would be automatically returned even if <i>RoboSats</i> goes down

View File

@ -51,9 +51,9 @@ export default class OrderPage extends Component {
this.statusToDelay = { this.statusToDelay = {
"0": 3000, //'Waiting for maker bond' "0": 3000, //'Waiting for maker bond'
"1": 30000, //'Public' "1": 30000, //'Public'
"2": 999999, //'Deleted' "2": 9999999, //'Deleted'
"3": 3000, //'Waiting for taker bond' "3": 3000, //'Waiting for taker bond'
"4": 999999, //'Cancelled' "4": 9999999, //'Cancelled'
"5": 999999, //'Expired' "5": 999999, //'Expired'
"6": 3000, //'Waiting for trade collateral and buyer invoice' "6": 3000, //'Waiting for trade collateral and buyer invoice'
"7": 3000, //'Waiting only for seller trade collateral' "7": 3000, //'Waiting only for seller trade collateral'
@ -61,13 +61,13 @@ export default class OrderPage extends Component {
"9": 10000, //'Sending fiat - In chatroom' "9": 10000, //'Sending fiat - In chatroom'
"10": 15000, //'Fiat sent - In chatroom' "10": 15000, //'Fiat sent - In chatroom'
"11": 300000, //'In dispute' "11": 300000, //'In dispute'
"12": 999999, //'Collaboratively cancelled' "12": 9999999,//'Collaboratively cancelled'
"13": 120000, //'Sending satoshis to buyer' "13": 120000, //'Sending satoshis to buyer'
"14": 999999, //'Sucessful trade' "14": 9999999,//'Sucessful trade'
"15": 15000, //'Failed lightning network routing' "15": 10000, //'Failed lightning network routing'
"16": 999999, //'Maker lost dispute' "16": 9999999,//'Maker lost dispute'
"17": 999999, //'Taker lost dispute' "17": 9999999,//'Taker lost dispute'
} }
} }
getOrderDetails() { getOrderDetails() {
@ -77,7 +77,7 @@ export default class OrderPage extends Component {
.then((data) => {console.log(data) & .then((data) => {console.log(data) &
this.setState({ this.setState({
loading: false, loading: false,
delay: this.statusToDelay[data.status.toString()], delay: this.setDelay(data.status),
id: data.id, id: data.id,
statusCode: data.status, statusCode: data.status,
statusText: data.status_message, statusText: data.status_message,
@ -207,6 +207,11 @@ export default class OrderPage extends Component {
})); }));
} }
// set delay to the one matching the order status. If no order status, set delay to 9999999
setDelay(val){
return val ? this.statusToDelay[val.toString()] : 99999999;
}
getCurrencyCode(val){ getCurrencyCode(val){
let code = val ? this.state.currencies_dict[val.toString()] : "" let code = val ? this.state.currencies_dict[val.toString()] : ""
return code return code