vegaprotocol / vega

A Go implementation of the Vega Protocol, a protocol for creating and trading derivatives on a fully decentralised network.
https://vega.xyz
GNU Affero General Public License v3.0
36 stars 22 forks source link

Add base and quote currency symbols to Instrument returned by APIs #251

Closed ashleyvega closed 4 years ago

ashleyvega commented 4 years ago

In GitLab by @mattrussell36 on Apr 18, 2019, 18:22

The client repo currently has this blocked issue to remove hard coded currency symbols from the UI.

To achieve this we need access to the base and quote currency symbols. We could write some regex to get these values from code on Instrument but we feel it would be cleaner to add them as individual properties on Instrument

type Instrument would become

# Describe something that can be traded on Vega
type Instrument {
  # A short non necessarily unique code used to easily describe the instrument (e.g: FX:BTCUSD/DEC18) (string)
  code: String!

  # Text string describing the base currency of this instrument
  base: String!

  # Text string describing the quote currency of this instrument
  quote: String!

  ...
}

Returning:

{
  "data": {
    "market": {
      "id": "ETH/JUN19",
      "tradableInstrument": {
        "instrument": {
          "code": "ETH/USDJun19",
          "base": "ETH",
          "quote": "USD"
        }
      }
    }
  }
}
ashleyvega commented 4 years ago

In GitLab by @mattrussell36 on Apr 18, 2019, 18:23

changed the description

ashleyvega commented 4 years ago

In GitLab by @barnabee on Apr 29, 2019, 20:42

@tamlyn10 could you take a look at this? We need to be careful not to hard code something here that only works for a subset of products…

As a starting point, I think that something like the below would work everywhere but not 100% sure. It’s also possible that we have covered this in another ticket or comment thread but the plane wifi is terrible and I can;t find it.

ashleyvega commented 4 years ago

In GitLab by @barnabee on Apr 29, 2019, 20:52

See also Product here: https://gitlab.com/vega-protocol/product/issues/80

ashleyvega commented 4 years ago

In GitLab by @tamlyn10 on May 1, 2019, 13:05

Agree @barnabee

The 'price/quote units' defined at the Product level will dictate the default unit for display on the order book, the deal ticket and potentially other components.

The 'settlement assets' will be used for open MTM, PnL's etc.

How these assets are defined and then converted into a readable symbol is, I believe still up for debate. There was talk of defining the asset in terms of the host chain and then the token 'name'.

ashleyvega commented 4 years ago

In GitLab by @barnabee on May 1, 2019, 18:46

Yes, still up for debate.

At a minimum we know an asset must be defined in a completely unambiguous way that references both the blockchain or network it is on (“host chain”) and how to uniquely indentify if, e.g. that it is an ERC20 token at contract address C, for example. That might be three fields:

Asset { 
  chain: “Ethereum”, 
  type: “ERC20”,
  address: “C...”
}

Although it may just make more sense for a variety of reasons to have a single address/identifier:

Ethereum/ERC20/C

Beyond that we almost certainly want a “friendly name” and probably a (potentially non-unique) short code. I’m not sure if these will be discernible from the host chain or something that’ll need to be supplied.

NB: it is likely we will have an asset whitelist where initially we add tokens that can be traded on Vega and later we allow token holders to do this through a vote.

ashleyvega commented 4 years ago

In GitLab by @cdm on May 2, 2019, 21:05

changed title from {-GraphQL: Add base and quote currency symbols to Instrument-} to {+Add base and quote currency symbols to Instrument returned by APIs+}

ashleyvega commented 4 years ago

In GitLab by @cdm on May 2, 2019, 21:33

Just spoken with @tamlyn10 and she says this is needed for 1906/May 9th release, @barnabee what needs to be done for nicenet?

ashleyvega commented 4 years ago

In GitLab by @tamlyn10 on May 2, 2019, 21:40

To be clear, we just need some way of distinguishing markets since we will have 3!! This can be hard-coded as the lightest weight solution!

ashleyvega commented 4 years ago

In GitLab by @barnabee on May 7, 2019, 20:32

@tamlyn10 you mean assets/currencies not markets?

ashleyvega commented 4 years ago

In GitLab by @barnabee on May 7, 2019, 20:38

@cdm it would be good to understand what already exists in the market framework… the ticket (https://gitlab.com/vega-protocol/product/issues/80) already covers the need for these things:

Products must expose certain data to Vega WHEN they are instantiated as an instrument by providing parameters:

  • Settlement assets: one or more (for Nicenet it'll be one) assets that can be involved in settlement
  • Margin assets: one or more (for Nicenet it'll be one) assets that may be required as margin (usually the same set as settlement assets, but not always)
  • Price / quote units: the unit in which prices (e.g. on the order book are quoted), usually but not always one of the settlement assets. Usually but not always (e.g. for bonds traded on yield, units = % return or options traded on implied volatility, units = % annualised vol) an asset (currency, commodity, etc.)
  • Status: e.g. Active | Matured (these are the only statuses I can think of for now)

And here, where we give an example for Futures (Nicenet == futures):

  • Product specific parameters which can be single values or streams (e.g. events from an oracle), e.g. for a future:
    • Settlement, pricing, and margin asset
    • Maturity date
    • Oracle reference -'Contract' size
    • Note: the specific parameters for a product are defined by the product and will vary between products, so the system needs to be flexible in this regard.

If you are just asking how we specify them, a ‘currency’ code, for which we can include a list of valid values in the configuration (e.g asset_codes = [“ETH”, “USD”, “EUR”]), would be fine.

We will need a framework for asssrts including having unique IDs and source blockchain link data, etc. in future, but not for Nicenet.

ashleyvega commented 4 years ago

In GitLab by @cdm on May 7, 2019, 20:44

@barnabee AFAIK we implemented to the spec in the product ticket, prob worth @jeremyletang input here if we have not?

{
  "id": "BTC/DEC19",
  "tradableInstrument": {
    "instrument": {
      "id": "Crypto/BTCUSD/Futures/Dec19",
      "code": "FX:BTCUSD/DEC19",
      "name": "December 2019 BTC vs USD future",
      "metadata": {
        "tags": [
          "asset_class:fx/crypto",
          "product:futures"
        ]
      },
      "future": {
        "maturity": "2019-12-31T00:00:00Z",
        "asset": "Ethereum/Ether",
        "ethereumEvent": {
          "contractID": "0x0B484706fdAF3A4F24b2266446B1cb6d648E3cC1",
          "event": "price_changed"
        }
      }
    },
    "builtinFutures": {
      "historicVolatility": 0.15
    }
  },
  "continuous": {

  }
}

^ This is a dump of the default btcdec19.json file we use to create a market for nicenet (we load from json files as a hack until we have persistent storage of market data I believe). The json is converted into proto structs

ashleyvega commented 4 years ago

In GitLab by @barnabee on May 7, 2019, 21:14

The key things are the settlement and margin assets (in Nicenet it's just a single asset, but that is product dependent). Probably worth discussing tomorrow.

ashleyvega commented 4 years ago

In GitLab by @tamlyn10 on May 8, 2019, 12:07

yes, sorry I mean assets/currencies. my point was really that if we only had one market it could be inferred or hard coded into the front end. but as we have more markets (with different assets/currencies) that doesn't work.

ashleyvega commented 4 years ago

In GitLab by @cdm on May 24, 2019, 15:40

@tamlyn10 @barnabee did you discuss this in the end, any further thoughts?

ashleyvega commented 4 years ago

In GitLab by @tamlyn10 on Jun 11, 2019, 17:49

I don't recall a discussion - @barnabee ?

ashleyvega commented 4 years ago

In GitLab by @barnabee on Jun 11, 2019, 18:18

@cdm I meant to discuss with you not Tamlyn, as I think what's described here https://gitlab.com/vega-protocol/trading-core/issues/251#note_167677096 is the solution for Nicenet (i.e. we have a configured set of simple asset/currency codes such as asset_codes = [“ETH”, “USD”, “EUR”] and these are used for specifying the settlement and margin assets.

Example: USD vs ETH future market that settles in Ether based on the price of Ether in dollars

For a simple (cash settled) futures product, there would be 1 product parameter: settlement and margin asset, which for the above example would be ETH (this value must be one of the configured valid asset/currency codes, in Nicenet — in future our blockchain integration will help to provide valid IDs and as these will be longer than ETH, etc. we would also store a short code for display.)

The price/quote units do not have to be a valid asset code, and can be any string that describes the units of the prie. This might be one of the codes (e.g. USD) but, for the example above, the price/quote units would be USD/ETH, which reads as 'US dollars per 1 Ether'.

The minimum tick size of the market is always expressed in terms of the price/quote units.

ashleyvega commented 4 years ago

In GitLab by @cdm on Aug 2, 2019, 10:58

closed