Skip to content

Commit 8b455a4

Browse files
added num_qt field representing number of quoters that make up the aggregate price
1 parent cd9dc8c commit 8b455a4

File tree

10 files changed

+32
-10
lines changed

10 files changed

+32
-10
lines changed

dashboard/dashboard.js

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Prices
5555
this.draw_cell( row.cells[col++], twap.toFixed(expo), color );
5656
this.draw_cell( row.cells[col++], twac.toFixed(expo), color );
5757
this.draw_cell( row.cells[col++], res.status, color );
58+
this.draw_cell( row.cells[col++], res.num_qt, color );
5859
this.draw_cell( row.cells[col++], res.valid_slot, color );
5960
this.draw_cell( row.cells[col++], res.pub_slot, color );
6061
row.cells[col++].style.color = color;
@@ -104,6 +105,7 @@ class Prices
104105
row.appendChild( document.createElement( 'TD' ) );
105106
row.appendChild( document.createElement( 'TD' ) );
106107
row.appendChild( document.createElement( 'TD' ) );
108+
row.appendChild( document.createElement( 'TD' ) );
107109
row.appendChild( this.get_title( att, 'tenor') );
108110
row.appendChild( this.get_title( att, 'quote_currency') );
109111
row.appendChild( this.get_title( att, 'description') );

dashboard/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ <h2>pyth dashboard
2020
<th width=100px>twap</th>
2121
<th width=100px>twac</th>
2222
<th width=80>status</th>
23+
<th>nqt</th>
2324
<th>valid_slot</th>
2425
<th>pub_slot</th>
2526
<th>tenor</th>

pc/request.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,11 @@ symbol_status price::get_status() const
19241924
return (symbol_status)pptr_->agg_.status_;
19251925
}
19261926

1927+
uint32_t price::get_num_qt() const
1928+
{
1929+
return pptr_->num_qt_;
1930+
}
1931+
19271932
uint64_t price::get_lamports() const
19281933
{
19291934
return lamports_;

pc/request.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ namespace pc
687687
int64_t get_price() const;
688688
uint64_t get_conf() const;
689689
symbol_status get_status() const;
690+
uint32_t get_num_qt() const;
690691
uint64_t get_lamports() const;
691692
int64_t get_twap() const;
692693
uint64_t get_twac() const;

pc/user.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ void user::on_response( price *rptr, uint64_t idx )
357357
jw_.add_key( "twap", rptr->get_twap() );
358358
jw_.add_key( "twac", rptr->get_twac() );
359359
jw_.add_key( "status", symbol_status_to_str( rptr->get_status() ) );
360+
jw_.add_key( "num_qt", (uint64_t)rptr->get_num_qt() );
360361
jw_.add_key( "valid_slot", rptr->get_valid_slot() );
361362
jw_.add_key( "pub_slot", rptr->get_pub_slot() );
362363
jw_.pop();

pcapps/pyth_csv.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void csv_print::print_header()
7777
<< ",conf"
7878
<< ",twap"
7979
<< ",twac"
80+
<< ",num_qt"
8081
<< ",valid_slot"
8182
<< ",pub_slot"
8283
<< ",prev_slot"
@@ -140,6 +141,7 @@ void csv_print::parse_price( replay& rep )
140141
<< ',' << ptr->agg_.conf_
141142
<< ',' << ptr->twap_.val_
142143
<< ',' << ptr->twac_.val_
144+
<< ',' << ptr->num_qt_
143145
<< ',' << ptr->valid_slot_
144146
<< ',' << ptr->agg_.pub_slot_
145147
<< ',' << ptr->prev_slot_

pctest/test_publish.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ void test_publish::on_response( pc::price *sym, uint64_t )
238238
.add( "agg_spread", spread )
239239
.add( "twap", expo_*(double)sym->get_twap() )
240240
.add( "twac", expo_*(double)sym->get_twac() )
241+
.add( "num_qt", sym->get_num_qt() )
241242
.add( "valid_slot", sym->get_valid_slot() )
242243
.add( "pub_slot", sym->get_pub_slot() )
243244
.add( "my_price", my_price )

program/src/oracle/oracle.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ typedef struct pc_price
135135
uint32_t ptype_; // price or calculation type
136136
int32_t expo_; // price exponent
137137
uint32_t num_; // number of component prices
138-
uint32_t unused_;
138+
uint32_t num_qt_; // number of quoters that make up aggregate
139139
uint64_t last_slot_; // slot of last valid aggregate price
140140
uint64_t valid_slot_; // valid on-chain slot of agg. price
141141
pc_ema_t twap_; // time-weighted average price

program/src/oracle/test_oracle.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,10 @@ Test( oracle, upd_aggregate ) {
469469
px->comp_[0].latest_ = p1;
470470
upd_aggregate( px, 1001 );
471471
cr_assert( px->agg_.price_ == 100 );
472-
cr_assert( px->agg_.conf_ == 50 );
472+
cr_assert( px->agg_.conf_ == 10 );
473473
cr_assert( px->twap_.val_ == 100 );
474-
cr_assert( px->twac_.val_ == 50 );
474+
cr_assert( px->twac_.val_ == 10 );
475+
cr_assert( px->num_qt_ == 1 );
475476

476477
// two publishers
477478
px->num_ = 0;
@@ -483,7 +484,8 @@ Test( oracle, upd_aggregate ) {
483484
cr_assert( px->agg_.price_ == 147 );
484485
cr_assert( px->agg_.conf_ == 48 );
485486
cr_assert( px->twap_.val_ == 123 );
486-
cr_assert( px->twac_.val_ == 48 );
487+
cr_assert( px->twac_.val_ == 29 );
488+
cr_assert( px->num_qt_ == 2 );
487489

488490
// three publishers
489491
px->num_ = 0;
@@ -496,7 +498,8 @@ Test( oracle, upd_aggregate ) {
496498
cr_assert( px->agg_.price_ == 191 );
497499
cr_assert( px->agg_.conf_ == 74 );
498500
cr_assert( px->twap_.val_ == 146 );
499-
cr_assert( px->twac_.val_ == 57 );
501+
cr_assert( px->twac_.val_ == 44 );
502+
cr_assert( px->num_qt_ == 3 );
500503

501504
// four publishers
502505
px->num_ = 0;
@@ -510,17 +513,20 @@ Test( oracle, upd_aggregate ) {
510513
cr_assert( px->agg_.price_ == 235 );
511514
cr_assert( px->agg_.conf_ == 99 );
512515
cr_assert( px->twap_.val_ == 168 );
513-
cr_assert( px->twac_.val_ == 67 );
516+
cr_assert( px->twac_.val_ == 57 );
514517
cr_assert( px->last_slot_ == 1001 );
518+
cr_assert( px->num_qt_ == 4 );
515519

516520
upd_aggregate( px, 1025 );
517521
cr_assert( px->agg_.status_ == PC_STATUS_TRADING );
518522
cr_assert( px->last_slot_ == 1025 );
523+
cr_assert( px->num_qt_ == 4 );
519524

520525
// check what happens when nothing publishes for a while
521526
upd_aggregate( px, 1026 );
522527
cr_assert( px->agg_.status_ == PC_STATUS_UNKNOWN );
523528
cr_assert( px->last_slot_ == 1025 );
529+
cr_assert( px->num_qt_ == 0 );
524530
}
525531

526532
Test( oracle, del_publisher ) {

program/src/oracle/upd_aggregate.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ static void upd_aggregate( pc_price_t *ptr, uint64_t slot )
301301
}
302302
}
303303

304-
// zero quotes
304+
// zero quoters
305+
ptr->num_qt_ = numa;
305306
if ( numa == 0 ) {
306307
ptr->agg_.status_ = PC_STATUS_UNKNOWN;
307308
upd_twap( ptr, agg_diff, qs );
@@ -311,10 +312,12 @@ static void upd_aggregate( pc_price_t *ptr, uint64_t slot )
311312
// update status and publish slot of last trading status price
312313
ptr->agg_.status_ = PC_STATUS_TRADING;
313314
ptr->last_slot_ = slot;
315+
316+
// single quoter
314317
if ( numa == 1 ) {
315-
int64_t price = ptr->comp_[aidx[0]].agg_.price_;
316-
ptr->agg_.price_ = price;
317-
ptr->agg_.conf_ = (price>0?price:-price)/2L;
318+
pc_price_comp_t *iptr = &ptr->comp_[aidx[0]];
319+
ptr->agg_.price_ = iptr->agg_.price_;
320+
ptr->agg_.conf_ = iptr->agg_.conf_;
318321
upd_twap( ptr, agg_diff, qs );
319322
return;
320323
}

0 commit comments

Comments
 (0)