github.com/diadata-org/diadata@v1.4.593/pkg/model/types.go (about) 1 package models 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/diadata-org/diadata/pkg/dia" 8 clientInfluxdb "github.com/influxdata/influxdb1-client/v2" 9 ) 10 11 type SymbolExchangeDetails struct { 12 Name string 13 Price float64 14 PriceYesterday *float64 15 VolumeYesterdayUSD *float64 16 Time *time.Time 17 LastTrades []dia.Trade 18 } 19 20 // Quotation is deprecating. Going to be substituted by AssetQuotation 21 type Quotation struct { 22 Symbol string `json:"Symbol"` 23 Name string `json:"Name"` 24 Price float64 `json:"Price"` 25 PriceYesterday *float64 `json:"PriceYesterday"` 26 VolumeYesterdayUSD *float64 `json:"VolumeYesterdayUSD"` 27 Source string `json:"Source"` 28 Time time.Time `json:"Time"` 29 } 30 31 type StockQuotation struct { 32 Symbol string 33 Name string 34 PriceAsk float64 35 PriceBid float64 36 SizeAskLot float64 37 SizeBidLot float64 38 Source string 39 Time time.Time 40 ISIN string 41 } 42 43 type Stock struct { 44 Symbol string 45 Name string 46 ISIN string 47 } 48 49 // MarshalBinary for quotations 50 func (e *Quotation) MarshalBinary() ([]byte, error) { 51 return json.Marshal(e) 52 } 53 54 // UnmarshalBinary for quotations 55 func (e *Quotation) UnmarshalBinary(data []byte) error { 56 if err := json.Unmarshal(data, &e); err != nil { 57 return err 58 } 59 return nil 60 } 61 62 type FiatQuotation struct { 63 QuoteCurrency string `json:"QuoteCurrency"` 64 BaseCurrency string `json:"BaseCurrency"` 65 Price float64 `json:"Price"` 66 Source string `json:"Source"` 67 Time time.Time `json:"Time"` 68 } 69 70 // MarshalBinary for fiat quotations 71 func (fq *FiatQuotation) MarshalBinary() ([]byte, error) { 72 return json.Marshal(fq) 73 } 74 75 // UnmarshalBinary for fiat quotations 76 func (fq *FiatQuotation) UnmarshalBinary(data []byte) error { 77 if err := json.Unmarshal(data, &fq); err != nil { 78 return err 79 } 80 return nil 81 } 82 83 // AssetQuotation is the most recent price point information on an asset. 84 type AssetQuotation struct { 85 Asset dia.Asset `json:"Asset"` 86 Price float64 `json:"Price"` 87 Source string `json:"Source"` 88 Time time.Time `json:"Time"` 89 } 90 91 // MarshalBinary for quotations 92 func (aq *AssetQuotation) MarshalBinary() ([]byte, error) { 93 return json.Marshal(aq) 94 } 95 96 // UnmarshalBinary for quotations 97 func (aq *AssetQuotation) UnmarshalBinary(data []byte) error { 98 if err := json.Unmarshal(data, &aq); err != nil { 99 return err 100 } 101 return nil 102 } 103 104 type AssetQuotationFull struct { 105 Symbol string `json:"Symbol"` 106 Name string `json:"Name"` 107 Address string `json:"Address"` 108 Blockchain string `json:"Blockchain"` 109 Price float64 `json:"Price"` 110 PriceYesterday float64 `json:"PriceYesterday"` 111 VolumeYesterdayUSD float64 `json:"VolumeYesterdayUSD"` 112 Time time.Time `json:"Time"` 113 Source string `json:"Source"` 114 Signature string `json:"Signature,omitempty"` 115 } 116 117 // MarshalBinary for quotations 118 func (aq *AssetQuotationFull) MarshalBinary() ([]byte, error) { 119 return json.Marshal(aq) 120 } 121 122 // UnmarshalBinary for quotations 123 func (aq *AssetQuotationFull) UnmarshalBinary(data []byte) error { 124 if err := json.Unmarshal(data, &aq); err != nil { 125 return err 126 } 127 return nil 128 } 129 130 type Price struct { 131 Symbol string 132 Name string 133 Price float64 134 Time time.Time 135 } 136 137 type CurrencyChange struct { 138 Symbol string 139 Rate float64 140 RateYesterday float64 141 } 142 143 type Change struct { 144 USD []CurrencyChange `json:"USD"` 145 } 146 147 // MarshalBinary - 148 func (e *Change) MarshalBinary() ([]byte, error) { 149 return json.Marshal(e) 150 } 151 152 // UnmarshalBinary - 153 func (e *Change) UnmarshalBinary(data []byte) error { 154 if err := json.Unmarshal(data, &e); err != nil { 155 return err 156 } 157 return nil 158 } 159 160 type Points struct { 161 DataPoints []clientInfluxdb.Result `json:"DataPoints"` 162 } 163 164 func (e *Points) UnmarshalBinary(data []byte) error { 165 if err := json.Unmarshal(data, &e); err != nil { 166 return err 167 } 168 return nil 169 } 170 171 // MarshalBinary - 172 func (e *Points) MarshalBinary() ([]byte, error) { 173 return json.Marshal(e) 174 } 175 176 type CoinSymbolAndName struct { 177 Symbol string 178 Name string 179 } 180 181 type Pairs struct { 182 Pairs []dia.ExchangePair 183 } 184 185 // HistoricalQuote is a historical price of an asset. 186 type HistoricalQuote struct { 187 Symbol string `db:"symbol"` 188 Price float64 `db:"price"` 189 QuoteTime time.Time `db:"quote_time"` 190 Source string `db:"source"` 191 }