-
Notifications
You must be signed in to change notification settings - Fork 502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exp/ticker: Orderbook data support #1193
Changes from 21 commits
5b37560
6e1346c
5df5153
44463a9
3d0e4d2
bc5ff85
1eda6dc
fd0250a
c3a1a78
5215bdb
b25240e
d5fce2a
aa513d9
22a01aa
c90b270
3bc5ad4
f311ee4
9185656
3f7c748
e534072
4d24aa5
9025afb
878d795
a1e9383
fbdff21
f290fc8
37beb42
361f5e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package ticker | ||
|
||
import ( | ||
"time" | ||
|
||
horizonclient "github.com/stellar/go/clients/horizonclient" | ||
"github.com/stellar/go/exp/ticker/internal/scraper" | ||
"github.com/stellar/go/exp/ticker/internal/tickerdb" | ||
"github.com/stellar/go/support/errors" | ||
hlog "github.com/stellar/go/support/log" | ||
) | ||
|
||
// RefreshOrderbookEntries updates the orderbook entries for the relevant markets that were active | ||
// in the past 7-day interval | ||
func RefreshOrderbookEntries(s *tickerdb.TickerSession, c *horizonclient.Client, l *hlog.Entry) error { | ||
sc := scraper.ScraperConfig{ | ||
Client: c, | ||
Logger: l, | ||
} | ||
|
||
// Retrieve relevant markets for the past 7 days (168 hours): | ||
mkts, err := s.Retrieve7DRelevantMarkets() | ||
if err != nil { | ||
return errors.Wrap(err, "could not retrieve partial markets") | ||
} | ||
|
||
for _, mkt := range mkts { | ||
ob, err := sc.FetchOrderbookForAssets( | ||
mkt.BaseAssetType, | ||
mkt.BaseAssetCode, | ||
mkt.BaseAssetIssuer, | ||
mkt.CounterAssetType, | ||
mkt.CounterAssetCode, | ||
mkt.CounterAssetIssuer, | ||
) | ||
if err != nil { | ||
l.Error(errors.Wrap(err, "could not fetch orderbook for assets")) | ||
continue | ||
} | ||
|
||
dbOS := orderbookStatsToDBOrderbookStats(ob, mkt.BaseAssetID, mkt.CounterAssetID) | ||
err = s.InsertOrUpdateOrderbookStats(&dbOS, []string{"base_asset_id", "counter_asset_id"}) | ||
if err != nil { | ||
l.Error(errors.Wrap(err, "could not insert orderbook stats into db")) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func orderbookStatsToDBOrderbookStats(os scraper.OrderbookStats, bID, cID int32) tickerdb.OrderbookStats { | ||
return tickerdb.OrderbookStats{ | ||
BaseAssetID: bID, | ||
CounterAssetID: cID, | ||
NumBids: os.NumBids, | ||
BidVolume: os.BidVolume, | ||
HighestBid: os.HighestBid, | ||
NumAsks: os.NumAsks, | ||
AskVolume: os.AskVolume, | ||
LowestAsk: os.LowestAsk, | ||
Spread: os.Spread, | ||
SpreadMidPoint: os.SpreadMidPoint, | ||
UpdatedAt: time.Now(), | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,14 @@ type MarketStats struct { | |
Price float64 `json:"price"` | ||
Close float64 `json:"close"` | ||
CloseTime int64 `json:"close_time"` | ||
NumBids int `json:"num_bids"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about it, maybe we should unify where
and the same for What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that makes sense! I've pushed a change that updates all the related fields to have |
||
BidVolume float64 `json:"bid_volume"` | ||
HighestBid float64 `json:"highest_bid"` | ||
NumAsks int `json:"num_asks"` | ||
AskVolume float64 `json:"ask_volume"` | ||
LowestAsk float64 `json:"lowest_ask"` | ||
Spread float64 `json:"spread"` | ||
SpreadMidPoint float64 `json:"spread_mid_point"` | ||
} | ||
|
||
// Asset Sumary represents the collection of valid assets. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you want this
,
or the ones belowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I've sent a fix for that.