decred.org/dcrdex@v1.0.5/server/admin/types.go (about)

     1  // This code is available on the terms of the project LICENSE.md file,
     2  // also available online at https://blueoakcouncil.org/license/1.0.0.
     3  
     4  package admin
     5  
     6  import (
     7  	"time"
     8  
     9  	"decred.org/dcrdex/dex"
    10  )
    11  
    12  // AssetPost is the expected structure of the asset POST data.
    13  type AssetPost struct {
    14  	FeeRateScale *float64 `json:"feeRateScale,omitempty"`
    15  }
    16  
    17  // AssetInfo is the result of the asset GET. Note that ScaledFeeRate is
    18  // CurrentFeeRate multiplied by an operator-specified fee scale rate for this
    19  // asset, and then limited by the dex.Asset.MaxFeeRate.
    20  type AssetInfo struct {
    21  	dex.Asset
    22  	CurrentFeeRate uint64   `json:"currentFeeRate,omitempty"`
    23  	ScaledFeeRate  uint64   `json:"scaledFeeRate,omitempty"`
    24  	Synced         bool     `json:"synced"`
    25  	Errors         []string `json:"errors,omitempty"`
    26  }
    27  
    28  // MarketStatus summarizes the operational status of a market.
    29  type MarketStatus struct {
    30  	Name          string `json:"market,omitempty"`
    31  	Running       bool   `json:"running"`
    32  	EpochDuration uint64 `json:"epochlen"`
    33  	ActiveEpoch   int64  `json:"activeepoch"`
    34  	StartEpoch    int64  `json:"startepoch"`
    35  	SuspendEpoch  int64  `json:"finalepoch,omitempty"`
    36  	PersistBook   *bool  `json:"persistbook,omitempty"`
    37  }
    38  
    39  // MatchData describes a match.
    40  type MatchData struct {
    41  	ID          string `json:"id"`
    42  	TakerSell   bool   `json:"takerSell"`
    43  	Maker       string `json:"makerOrder"`
    44  	MakerAcct   string `json:"makerAcct"`
    45  	MakerSwap   string `json:"makerSwap"`
    46  	MakerRedeem string `json:"makerRedeem"`
    47  	MakerAddr   string `json:"makerAddr"`
    48  	Taker       string `json:"takerOrder"`
    49  	TakerAcct   string `json:"takerAcct"`
    50  	TakerSwap   string `json:"takerSwap"`
    51  	TakerRedeem string `json:"takerRedeem"`
    52  	TakerAddr   string `json:"takerAddr"`
    53  	EpochIdx    uint64 `json:"epochIdx"`
    54  	EpochDur    uint64 `json:"epochDur"`
    55  	Quantity    uint64 `json:"quantity"`
    56  	Rate        uint64 `json:"rate"`
    57  	BaseRate    uint64 `json:"baseFeeRate"`
    58  	QuoteRate   uint64 `json:"quoteFeeRate"`
    59  	Active      bool   `json:"active"`
    60  	Status      string `json:"status"`
    61  }
    62  
    63  // APITime marshals and unmarshals a time value in time.RFC3339Nano format.
    64  type APITime struct {
    65  	time.Time
    66  }
    67  
    68  // SuspendResult describes the result of a market suspend request. FinalEpoch is
    69  // the last epoch before shutdown, and it the market will run for it's entire
    70  // duration. As such, SuspendTime is the time at which the market is closed,
    71  // immediately after close of FinalEpoch.
    72  type SuspendResult struct {
    73  	Market      string  `json:"market"`
    74  	FinalEpoch  int64   `json:"finalepoch"`
    75  	SuspendTime APITime `json:"supendtime"`
    76  }
    77  
    78  // ResumeResult is the result of a market resume request.
    79  type ResumeResult struct {
    80  	Market     string  `json:"market"`
    81  	StartEpoch int64   `json:"startepoch"`
    82  	StartTime  APITime `json:"starttime"`
    83  }
    84  
    85  // RFC3339Milli is the RFC3339 time formatting with millisecond precision.
    86  const RFC3339Milli = "2006-01-02T15:04:05.999Z07:00"
    87  
    88  // MarshalJSON marshals APITime to a JSON string in RFC3339 format except with
    89  // millisecond precision.
    90  func (at *APITime) MarshalJSON() ([]byte, error) {
    91  	return []byte(`"` + at.Time.Format(RFC3339Milli) + `"`), nil
    92  }
    93  
    94  // UnmarshalJSON unmarshals JSON string containing a time in RFC3339 format with
    95  // millisecond precision into an APITime.
    96  func (at *APITime) UnmarshalJSON(b []byte) error {
    97  	if len(b) < 2 {
    98  		return nil
    99  	}
   100  	// Parenthesis are included in b and must be removed.
   101  	t, err := time.Parse(RFC3339Milli, string(b[1:len(b)-1]))
   102  	if err != nil {
   103  		return nil
   104  	}
   105  	at.Time = t
   106  	return nil
   107  }
   108  
   109  // ForgiveResult holds the result of a forgive_match.
   110  type ForgiveResult struct {
   111  	AccountID   string  `json:"accountid"`
   112  	Forgiven    bool    `json:"forgiven"`
   113  	Unbanned    bool    `json:"unbanned"`
   114  	ForgiveTime APITime `json:"forgivetime"`
   115  }