Skip to content

Commit

Permalink
🎨 Format Go source code
Browse files Browse the repository at this point in the history
  • Loading branch information
micheartin committed Oct 27, 2022
1 parent c0b7635 commit 37f1a97
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 46 deletions.
2 changes: 1 addition & 1 deletion cmd/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func listProviderNames() []string {
if *cex {
*providers += ",deribit,delta"
}
if *dex { //deprecating "opyn" & "psy"
if *dex { // deprecating "opyn" & "psy"
*providers += ",lyra,zeta"
}
if *exotic {
Expand Down
8 changes: 4 additions & 4 deletions pkg/provider/deltaexchange/delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func (pro Provider) Options() ([]rainbow.Option, error) {
if err != nil {
return nil, err
}
//log.Printf(p.ID)
//spew.Dump(p)
// log.Printf(p.ID)
// spew.Dump(p)

options = append(options, rainbow.Option{
Name: p.Symbol,
Expand All @@ -91,8 +91,8 @@ func (pro Provider) Options() ([]rainbow.Option, error) {
Bid: bids,
Ask: asks,
URL: baseURL + p.ContractUnitCurrency + "/" + p.Symbol,
//TODO add MarketIV
//https://docs.delta.exchange/#get-tickers-for-products
// TODO add MarketIV
// https://docs.delta.exchange/#get-tickers-for-products
})
log.Print(options[len(options)-1].URL)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/provider/lyra/lyra.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,16 @@ func Asset(address common.Address) string {

// TODO check function on their frontend.
func url(o *rainbow.Option, strikeID *big.Int) string {
//base := "https://app.lyra.finance/position/?"
// base := "https://app.lyra.finance/position/?"
base := "https://app.lyra.finance/trade"
asset := strings.ToLower(o.Asset[1:])
// TODO if they include asset with decimal, modify this
// most likely example: SOL, LINK
//strike := fmt.Sprintf("%.f", rainbow.ToFloat(strikeID, 0))
//t := strings.ToLower(o.Type)
// strike := fmt.Sprintf("%.f", rainbow.ToFloat(strikeID, 0))
// t := strings.ToLower(o.Type)

return base + "/" + asset //+ "/" + strike + "/" + t
//return base + "market=" + asset + "&id=" + ""
// return base + "market=" + asset + "&id=" + ""
}

func expiration(e *big.Int) string {
Expand Down
4 changes: 2 additions & 2 deletions pkg/provider/thales/thales.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ func getOption(m *thales.AllMarketsMarketsMarket, side uint8, layer string) (rai
Layer: "L2",
LayerName: layer,
Provider: name + "::" + layer,
//Link: url(m.Id)
// Link: url(m.Id)
QuoteCurrency: "USD", // sUSD for optimism, usdc for polygon/arbitrum,busd for binance
// TODO add underlying quote currency to be able to specify the token
Bid: nil,
Ask: nil,
Strike: rainbow.ToFloat(strikeInt, rainbow.DefaultEthereumDecimals),
}
binary.Name = binary.OptionName()
//log.Printf("%s\n", binary.Name)
// log.Printf("%s\n", binary.Name)
buy, err := getQuote(m, side, "BUY", layer)
if err != nil {
log.Error(err)
Expand Down
15 changes: 7 additions & 8 deletions pkg/provider/zetamarkets/anchor/anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func Query() ([]Option, map[string][]uint64, error) {

err = bin.NewBinDecoder(account.Account.Data.GetBinary()).Decode(&z)
if err != nil {
//spew.Dump(account.Pubkey)
//too many accounts with that error to explicitely log. so we just silently skip them
// spew.Dump(account.Pubkey)
// too many accounts with that error to explicitely log. so we just silently skip them
continue
//return []Option{}, log.Error("NewBinDecoder", "account=", account, err).Err()
// return []Option{}, log.Error("NewBinDecoder", "account=", account, err).Err()

}
fillmap(m, z)
Expand All @@ -63,14 +63,13 @@ func Query() ([]Option, map[string][]uint64, error) {
err = bin.NewBinDecoder(greekInfo.Value.Data.GetBinary()).Decode(&gr)
if err != nil {
return []Option{}, nil, log.Error("NewBinDecoder", "greeks=", z.Greeks, err).Err()

}

result = append(result, extractOptions(z, gr, false)...)
result = append(result, extractOptions(z, gr, true)...) // extra space that might be used in the future
}
//spew.Dump(m)
//spew.Dump(&m)
// spew.Dump(m)
// spew.Dump(&m)

return result, m, nil
}
Expand All @@ -83,15 +82,13 @@ func extractOptions(z *zeta.ZetaGroup, g *zeta.Greeks, padding bool) []Option {
options = append(options, Option{z, &z.ProductsPadding[i], &g.ProductGreeksPadding[i%23], z.ExpirySeriesPadding[i/23].ExpiryTs})
}
}

}
if !padding {
for i := range z.Products {
if z.Products[i].Strike.IsSet && z.Products[i].Kind.String() != "Future" {
options = append(options, Option{z, &z.Products[i], &g.ProductGreeks[i%23], z.ExpirySeries[i/23].ExpiryTs})
}
}

}

return options
Expand All @@ -105,6 +102,7 @@ func fillmap(m map[string][]uint64, z *zeta.ZetaGroup) {

m[a] = extractExpiries(e)
}

func extractExpiries(ze []zeta.ExpirySeries) []uint64 {
exp := make([]uint64, 0, len(ze))
for _, e := range ze {
Expand Down Expand Up @@ -145,6 +143,7 @@ func (o Option) Quote() string {
func (o Option) Asset() string {
return Asset(o.ZG)
}

func Asset(zg *zeta.ZetaGroup) string {
switch {
case zg.UnderlyingMint == solana.MustPublicKeyFromBase58(SOLAddress):
Expand Down
19 changes: 10 additions & 9 deletions pkg/provider/zetamarkets/anchor/decimals.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,27 @@ import (

// https://github.com/zetamarkets/sdk/blob/79b4f37dea9c494091b924d241c3437885bd6f5f/src/decimal.ts#L23

const SCALE_MASK = 0x00ff_0000
const SCALE_SHIFT = 16
const SIGN_MASK = 0x8000_0000
const (
SCALE_MASK = 0x00ff_0000
SCALE_SHIFT = 16
SIGN_MASK = 0x8000_0000
)

func FromAnchorToDecimals(a zeta.AnchorDecimal) float64 {
//spew.Dump(a)
// spew.Dump(a)
scale := scale(a)
//spew.Dump(scale)
// spew.Dump(scale)
array := make([]byte, 0, 4*3*4)
//AppendUint32 does the work for us.
// AppendUint32 does the work for us.
array = binary.BigEndian.AppendUint32(array, a.Hi)
array = binary.BigEndian.AppendUint32(array, a.Mid)
array = binary.BigEndian.AppendUint32(array, a.Lo)

z := new(big.Int)
z.SetBytes(array)
//spew.Dump(array)
//spew.Dump(z)
// spew.Dump(array)
// spew.Dump(z)
return rainbow.ToFloat(z, int64(scale)-2)

}

func scale(a zeta.AnchorDecimal) uint32 {
Expand Down
26 changes: 11 additions & 15 deletions pkg/provider/zetamarkets/zeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func (p Provider) Options() ([]rainbow.Option, error) {
if err != nil {
return nil, fmt.Errorf("anchor.query: %w", err)
}
//spew.Dump(m)
//spew.Dump(&m)
// spew.Dump(m)
// spew.Dump(&m)
zoi := OpenInterestMap(m)
//spew.Dump(zoi)
// spew.Dump(zoi)

client := rpc.NewClient(anchor.SolanaRPC)

Expand All @@ -58,7 +58,6 @@ func (p Provider) Options() ([]rainbow.Option, error) {
if err != nil {
// previously just silently skipped because of a weird error from Serum
return []rainbow.Option{}, log.Error("serum FetchMarket", err).Err()

}

// inverting the order to be able to quickly find the best bid (bids[0]) and ask (asks[len(offer)-1])
Expand Down Expand Up @@ -154,13 +153,12 @@ func normalizeOrders(
}

func OpenInterestMap(m map[string][]uint64) ZetaOI {
//if error fail with just a log
//let's keep it like that for now because evyrything shouldn't fail if zeta api is down
//oi := make(map[string]ZetaAPI)
// if error fail with just a log
// let's keep it like that for now because evyrything shouldn't fail if zeta api is down
// oi := make(map[string]ZetaAPI)
var oi ZetaOI

for asset, expiries := range m {

for _, e := range expiries {
url := ZetaAPIUrl + asset + "?expiry=" + strconv.FormatUint(e, 10)
spew.Dump(url)
Expand All @@ -170,7 +168,7 @@ func OpenInterestMap(m map[string][]uint64) ZetaOI {
return nil
}
defer resp.Body.Close()
//spew.Dump(resp.Body)
// spew.Dump(resp.Body)

/*var result struct {
Result []ZetaAPI `json:"result"`
Expand All @@ -184,14 +182,12 @@ func OpenInterestMap(m map[string][]uint64) ZetaOI {
spew.Dump(result)*/
data, _ := io.ReadAll(resp.Body)
json.Unmarshal(data, &oi)
//spew.Dump(oi)
// spew.Dump(oi)
}

}
//spew.Dump(oi)
// spew.Dump(oi)

return oi

}

// type ZetaAPI struct {
Expand All @@ -209,7 +205,7 @@ type ZetaOI map[string]struct {
func OpenInterest(o *anchor.Option, zoi ZetaOI) float64 {
key := o.Asset() + `#` + strconv.FormatUint(o.Expiry, 10) +
`#` + strings.ToLower(o.OptionType()) + `#` + fmt.Sprintf("%.1f", o.Strike())
//spew.Dump(key)
//spew.Dump(zoi[key])
// spew.Dump(key)
// spew.Dump(zoi[key])
return zoi[key].OpenInterest
}
1 change: 0 additions & 1 deletion pkg/rainbow/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type Option struct {
Greeks TheGreeks `json:"greeks"` // Greeks measure the sensitivity of an option’s price to its the underlying determining parameters.
Strike float64 `json:"strike"` //
OpenInterest float64 `json:"openinterest"` //

}

// TODO put standard name here.
Expand Down
4 changes: 2 additions & 2 deletions poc/anchor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func main() {
spew.Dump(zo.ExpirySeries)
spew.Dump(zo.ExpirySeriesPadding)
spew.Dump(zo.Products[5]) // opt)////TODO compute the right index
//spew.Dump(zo.Products[6]) // opt)////TODO compute the right index
// spew.Dump(zo.Products[6]) // opt)////TODO compute the right index
spew.Dump(zo.Products[16]) // opt)////TODO compute the right index
//spew.Dump(zo.Products[17]) // opt)////TODO compute the right index
// spew.Dump(zo.Products[17]) // opt)////TODO compute the right index
spew.Dump(zo.Greeks) // opt)

ooo, err := client.GetAccountInfo(
Expand Down

0 comments on commit 37f1a97

Please sign in to comment.