From efa67d87aa4f8d9d57883ee85b59f5aaf211eb12 Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 26 Jul 2018 14:52:23 -0700 Subject: Rename to sra-api --- packages/sra-api/src/api.ts | 165 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 packages/sra-api/src/api.ts (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts new file mode 100644 index 000000000..9043f6245 --- /dev/null +++ b/packages/sra-api/src/api.ts @@ -0,0 +1,165 @@ +import { OpenApiSpec } from '@loopback/openapi-v3-types'; + +export const api: OpenApiSpec = { + openapi: '3.0.0', + info: { + version: '1.0.0', + title: 'Swagger Petstore', + license: { + name: 'MIT', + }, + }, + servers: [ + { + url: 'http://petstore.swagger.io/v1', + }, + ], + paths: { + '/pets': { + get: { + summary: 'List all pets', + operationId: 'listPets', + tags: ['pets'], + parameters: [ + { + name: 'limit', + in: 'query', + description: 'How many items to return at one time (max 100)', + required: false, + schema: { + type: 'integer', + format: 'int32', + }, + }, + ], + responses: { + '200': { + description: 'An paged array of pets', + headers: { + 'x-next': { + description: 'A link to the next page of responses', + schema: { + type: 'string', + }, + }, + }, + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/Pets', + }, + }, + }, + }, + default: { + description: 'unexpected error', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/Error', + }, + }, + }, + }, + }, + }, + post: { + summary: 'Create a pet', + operationId: 'createPets', + tags: ['pets'], + responses: { + '201': { + description: 'Null response', + }, + default: { + description: 'unexpected error', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/Error', + }, + }, + }, + }, + }, + }, + }, + '/pets/{petId}': { + get: { + summary: 'Info for a specific pet', + operationId: 'showPetById', + tags: ['pets'], + parameters: [ + { + name: 'petId', + in: 'path', + required: true, + description: 'The id of the pet to retrieve', + schema: { + type: 'string', + }, + }, + ], + responses: { + '200': { + description: 'Expected response to a valid request', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/Pets', + }, + }, + }, + }, + default: { + description: 'unexpected error', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/Error', + }, + }, + }, + }, + }, + }, + }, + }, + components: { + schemas: { + Pet: { + required: ['id', 'name'], + properties: { + id: { + type: 'integer', + format: 'int64', + }, + name: { + type: 'string', + }, + tag: { + type: 'string', + }, + }, + }, + Pets: { + type: 'array', + items: { + $ref: '#/components/schemas/Pet', + }, + }, + Error: { + required: ['code', 'message'], + properties: { + code: { + type: 'integer', + format: 'int32', + }, + message: { + type: 'string', + }, + }, + }, + }, + }, +}; -- cgit v1.2.3 From 43d7045a5badf61efabffc2844cc6e14fe6f424f Mon Sep 17 00:00:00 2001 From: fragosti Date: Fri, 27 Jul 2018 10:19:20 -0700 Subject: Add scripts --- packages/sra-api/src/api.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index 9043f6245..c05311516 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -4,15 +4,14 @@ export const api: OpenApiSpec = { openapi: '3.0.0', info: { version: '1.0.0', - title: 'Swagger Petstore', + title: 'Standard Relayer REST API', license: { - name: 'MIT', + name: 'Apache 2.0', + url: 'https://www.apache.org/licenses/LICENSE-2.0.html', }, }, servers: [ - { - url: 'http://petstore.swagger.io/v1', - }, + // TODO: Use relayer registry information here? ], paths: { '/pets': { -- cgit v1.2.3 From 4aff9515d807feb5fc30431d109d503a6c52f0cd Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 31 Jul 2018 16:37:51 -0700 Subject: Get schema tests running (not crashiing) --- packages/sra-api/src/api.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index c05311516..fd64ab1d7 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -1,3 +1,4 @@ +import { schemas } from '@0xproject/json-schemas'; import { OpenApiSpec } from '@loopback/openapi-v3-types'; export const api: OpenApiSpec = { @@ -14,6 +15,55 @@ export const api: OpenApiSpec = { // TODO: Use relayer registry information here? ], paths: { + '/orders': { + get: { + summary: 'List all pets', + operationId: 'listPets2', + tags: ['pets'], + parameters: [ + { + name: 'limit', + in: 'query', + description: 'How many items to return at one time (max 100)', + required: false, + schema: { + type: 'integer', + format: 'int32', + }, + }, + ], + responses: { + '200': { + description: 'An paged array of pets', + headers: { + 'x-next': { + description: 'A link to the next page of responses', + schema: { + type: 'string', + }, + }, + }, + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/Pets', + }, + }, + }, + }, + default: { + description: 'unexpected error', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/Error', + }, + }, + }, + }, + }, + }, + }, '/pets': { get: { summary: 'List all pets', @@ -141,6 +191,7 @@ export const api: OpenApiSpec = { }, }, }, + // Orderbook: schemas.relayerApiOrderBookResponseSchema, Pets: { type: 'array', items: { -- cgit v1.2.3 From 1ce6579c3a05264f93957b0c2d845a1351f4a3b1 Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 2 Aug 2018 15:25:40 -0700 Subject: Create asset_pairs SRA endpoint (and establish conventions) --- packages/sra-api/src/api.ts | 226 +++++++++++--------------------------------- 1 file changed, 55 insertions(+), 171 deletions(-) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index fd64ab1d7..7d2cc6e08 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -1,11 +1,49 @@ import { schemas } from '@0xproject/json-schemas'; import { OpenApiSpec } from '@loopback/openapi-v3-types'; +import { examples } from './examples'; +// We need to replace the `$ref`s to be openAPI compliant. +const openApiSchemas = JSON.parse(JSON.stringify(schemas).replace(/(\/\w+)/g, match => `#/components/schemas${match}`)); + +const paginationParameters = [ + { + name: 'page', + in: 'query', + description: 'The number of the page to request in the collection.', + example: 3, + schema: { + type: 'number', + }, + }, + { + name: 'per_page', + in: 'query', + description: 'The number of records to return per page.', + example: 10, + schema: { + type: 'number', + }, + }, +]; + +const networkdIdParameter = { + name: 'network_id', + in: 'query', + description: 'The id of the Ethereum network', + example: 42, + default: 1, + schema: { + type: 'number', + }, +}; + export const api: OpenApiSpec = { openapi: '3.0.0', info: { version: '1.0.0', title: 'Standard Relayer REST API', + description: + '0x Protocol is an open standard. Because of this, we expect many independent applications to be built that will want to use the protocol. In order to make it easier for anyone to source liquidity that conforms to the 0x order format, relayers can opt-in to implementing a set of standard relayer API endpoints. In doing so, they allow clients of the standard relayer API to access the orders on their orderbook.', license: { name: 'Apache 2.0', url: 'https://www.apache.org/licenses/LICENSE-2.0.html', @@ -15,158 +53,39 @@ export const api: OpenApiSpec = { // TODO: Use relayer registry information here? ], paths: { - '/orders': { + '/asset_pairs': { get: { - summary: 'List all pets', - operationId: 'listPets2', - tags: ['pets'], + description: + 'Retrieves a list of available asset pairs and the information required to trade them (in any order). Setting only `asset_data_a` or `asset_data_b` returns pairs filtered by that asset only.', + operationId: 'getAssetPairs', parameters: [ + networkdIdParameter, + ...paginationParameters, { - name: 'limit', + name: 'asset_data_a', in: 'query', - description: 'How many items to return at one time (max 100)', - required: false, + description: 'The assetData value for the first asset in the pair.', + example: '0xf47261b04c32345ced77393b3530b1eed0f346429d', schema: { - type: 'integer', - format: 'int32', - }, - }, - ], - responses: { - '200': { - description: 'An paged array of pets', - headers: { - 'x-next': { - description: 'A link to the next page of responses', - schema: { - type: 'string', - }, - }, - }, - content: { - 'application/json': { - schema: { - $ref: '#/components/schemas/Pets', - }, - }, - }, - }, - default: { - description: 'unexpected error', - content: { - 'application/json': { - schema: { - $ref: '#/components/schemas/Error', - }, - }, + $ref: '#/components/schemas/hexSchema', }, }, - }, - }, - }, - '/pets': { - get: { - summary: 'List all pets', - operationId: 'listPets', - tags: ['pets'], - parameters: [ { - name: 'limit', + name: 'asset_data_b', in: 'query', - description: 'How many items to return at one time (max 100)', - required: false, + description: 'The assetData value for the second asset in the pair.', + example: '0x0257179264389b814a946f3e92105513705ca6b990', schema: { - type: 'integer', - format: 'int32', + $ref: '#/components/schemas/hexSchema', }, }, ], responses: { '200': { - description: 'An paged array of pets', - headers: { - 'x-next': { - description: 'A link to the next page of responses', - schema: { - type: 'string', - }, - }, - }, - content: { - 'application/json': { - schema: { - $ref: '#/components/schemas/Pets', - }, - }, - }, - }, - default: { - description: 'unexpected error', content: { 'application/json': { - schema: { - $ref: '#/components/schemas/Error', - }, - }, - }, - }, - }, - }, - post: { - summary: 'Create a pet', - operationId: 'createPets', - tags: ['pets'], - responses: { - '201': { - description: 'Null response', - }, - default: { - description: 'unexpected error', - content: { - 'application/json': { - schema: { - $ref: '#/components/schemas/Error', - }, - }, - }, - }, - }, - }, - }, - '/pets/{petId}': { - get: { - summary: 'Info for a specific pet', - operationId: 'showPetById', - tags: ['pets'], - parameters: [ - { - name: 'petId', - in: 'path', - required: true, - description: 'The id of the pet to retrieve', - schema: { - type: 'string', - }, - }, - ], - responses: { - '200': { - description: 'Expected response to a valid request', - content: { - 'application/json': { - schema: { - $ref: '#/components/schemas/Pets', - }, - }, - }, - }, - default: { - description: 'unexpected error', - content: { - 'application/json': { - schema: { - $ref: '#/components/schemas/Error', - }, + schema: { $ref: '#/components/schemas/relayerApiAssetDataPairsResponseSchema' }, + example: examples.relayerApiAssetDataPairsResponseSchema, }, }, }, @@ -175,41 +94,6 @@ export const api: OpenApiSpec = { }, }, components: { - schemas: { - Pet: { - required: ['id', 'name'], - properties: { - id: { - type: 'integer', - format: 'int64', - }, - name: { - type: 'string', - }, - tag: { - type: 'string', - }, - }, - }, - // Orderbook: schemas.relayerApiOrderBookResponseSchema, - Pets: { - type: 'array', - items: { - $ref: '#/components/schemas/Pet', - }, - }, - Error: { - required: ['code', 'message'], - properties: { - code: { - type: 'integer', - format: 'int32', - }, - message: { - type: 'string', - }, - }, - }, - }, + schemas: openApiSchemas, }, }; -- cgit v1.2.3 From 36e7cb16aa086892ace18b2c6f3ed5a6e3b26a70 Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 2 Aug 2018 18:24:24 -0700 Subject: Add errors and headers --- packages/sra-api/src/api.ts | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index 7d2cc6e08..2a43e3e8e 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -37,6 +37,51 @@ const networkdIdParameter = { }, }; +const headers = { + 'X-Rate-Limit-Limit': { + description: `The maximum number of requests you're permitted to make per hour.`, + schema: { + type: 'integer', + }, + }, + 'X-Rate-Limit-Remaining': { + description: 'The number of requests remaining in the current rate limit window.', + schema: { + type: 'integer', + }, + }, + 'X-Rate-Limit-Reset': { + description: 'The time at which the current rate limit window resets in UTC epoch seconds.', + schema: { + type: 'integer', + }, + }, +}; + +const errorResponses = { + '400': { + description: 'Validation error', + content: { + 'application/json': { + schema: { $ref: '#/components/schemas/relayerApiErrorResponseSchema' }, + example: examples.validationError, + }, + }, + }, + '404': { + description: 'Not found', + }, + '429': { + description: 'Too many requests - Rate limit exceeded', + }, + '500': { + description: 'Internal Server Error', + }, + '501': { + description: 'Not implemented.', + }, +}; + export const api: OpenApiSpec = { openapi: '3.0.0', info: { @@ -82,6 +127,8 @@ export const api: OpenApiSpec = { ], responses: { '200': { + headers, + description: 'OK', content: { 'application/json': { schema: { $ref: '#/components/schemas/relayerApiAssetDataPairsResponseSchema' }, @@ -89,6 +136,7 @@ export const api: OpenApiSpec = { }, }, }, + ...errorResponses, }, }, }, -- cgit v1.2.3 From 260640feed5dcda52936873397cf3b2c899718c6 Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 2 Aug 2018 18:39:52 -0700 Subject: Refactor using some utility methods --- packages/sra-api/src/api.ts | 135 +++++++++----------------------------------- 1 file changed, 26 insertions(+), 109 deletions(-) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index 2a43e3e8e..33d4d3619 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -2,86 +2,11 @@ import { schemas } from '@0xproject/json-schemas'; import { OpenApiSpec } from '@loopback/openapi-v3-types'; import { examples } from './examples'; +import { generateParameters } from './parameters'; +import { generateResponses } from './responses'; // We need to replace the `$ref`s to be openAPI compliant. const openApiSchemas = JSON.parse(JSON.stringify(schemas).replace(/(\/\w+)/g, match => `#/components/schemas${match}`)); -const paginationParameters = [ - { - name: 'page', - in: 'query', - description: 'The number of the page to request in the collection.', - example: 3, - schema: { - type: 'number', - }, - }, - { - name: 'per_page', - in: 'query', - description: 'The number of records to return per page.', - example: 10, - schema: { - type: 'number', - }, - }, -]; - -const networkdIdParameter = { - name: 'network_id', - in: 'query', - description: 'The id of the Ethereum network', - example: 42, - default: 1, - schema: { - type: 'number', - }, -}; - -const headers = { - 'X-Rate-Limit-Limit': { - description: `The maximum number of requests you're permitted to make per hour.`, - schema: { - type: 'integer', - }, - }, - 'X-Rate-Limit-Remaining': { - description: 'The number of requests remaining in the current rate limit window.', - schema: { - type: 'integer', - }, - }, - 'X-Rate-Limit-Reset': { - description: 'The time at which the current rate limit window resets in UTC epoch seconds.', - schema: { - type: 'integer', - }, - }, -}; - -const errorResponses = { - '400': { - description: 'Validation error', - content: { - 'application/json': { - schema: { $ref: '#/components/schemas/relayerApiErrorResponseSchema' }, - example: examples.validationError, - }, - }, - }, - '404': { - description: 'Not found', - }, - '429': { - description: 'Too many requests - Rate limit exceeded', - }, - '500': { - description: 'Internal Server Error', - }, - '501': { - description: 'Not implemented.', - }, -}; - export const api: OpenApiSpec = { openapi: '3.0.0', info: { @@ -103,41 +28,33 @@ export const api: OpenApiSpec = { description: 'Retrieves a list of available asset pairs and the information required to trade them (in any order). Setting only `asset_data_a` or `asset_data_b` returns pairs filtered by that asset only.', operationId: 'getAssetPairs', - parameters: [ - networkdIdParameter, - ...paginationParameters, - { - name: 'asset_data_a', - in: 'query', - description: 'The assetData value for the first asset in the pair.', - example: '0xf47261b04c32345ced77393b3530b1eed0f346429d', - schema: { - $ref: '#/components/schemas/hexSchema', - }, - }, - { - name: 'asset_data_b', - in: 'query', - description: 'The assetData value for the second asset in the pair.', - example: '0x0257179264389b814a946f3e92105513705ca6b990', - schema: { - $ref: '#/components/schemas/hexSchema', + parameters: generateParameters( + [ + { + name: 'asset_data_a', + in: 'query', + description: 'The assetData value for the first asset in the pair.', + example: '0xf47261b04c32345ced77393b3530b1eed0f346429d', + schema: { + $ref: '#/components/schemas/hexSchema', + }, }, - }, - ], - responses: { - '200': { - headers, - description: 'OK', - content: { - 'application/json': { - schema: { $ref: '#/components/schemas/relayerApiAssetDataPairsResponseSchema' }, - example: examples.relayerApiAssetDataPairsResponseSchema, + { + name: 'asset_data_b', + in: 'query', + description: 'The assetData value for the second asset in the pair.', + example: '0x0257179264389b814a946f3e92105513705ca6b990', + schema: { + $ref: '#/components/schemas/hexSchema', }, }, - }, - ...errorResponses, - }, + ], + true, + ), + responses: generateResponses( + 'relayerApiAssetDataPairsResponseSchema', + examples.relayerApiAssetDataPairsResponseSchema, + ), }, }, }, -- cgit v1.2.3 From be472b61e776ea44a872b54742af8664660aa27c Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 7 Aug 2018 13:22:11 -0700 Subject: Add markdown section --- packages/sra-api/src/api.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index 33d4d3619..da61cb1b0 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -2,6 +2,7 @@ import { schemas } from '@0xproject/json-schemas'; import { OpenApiSpec } from '@loopback/openapi-v3-types'; import { examples } from './examples'; +import { md } from './md'; import { generateParameters } from './parameters'; import { generateResponses } from './responses'; // We need to replace the `$ref`s to be openAPI compliant. @@ -10,10 +11,9 @@ const openApiSchemas = JSON.parse(JSON.stringify(schemas).replace(/(\/\w+)/g, ma export const api: OpenApiSpec = { openapi: '3.0.0', info: { - version: '1.0.0', + version: '2.0.0', title: 'Standard Relayer REST API', - description: - '0x Protocol is an open standard. Because of this, we expect many independent applications to be built that will want to use the protocol. In order to make it easier for anyone to source liquidity that conforms to the 0x order format, relayers can opt-in to implementing a set of standard relayer API endpoints. In doing so, they allow clients of the standard relayer API to access the orders on their orderbook.', + description: md.introduction, license: { name: 'Apache 2.0', url: 'https://www.apache.org/licenses/LICENSE-2.0.html', -- cgit v1.2.3 From 3b542bf356f14e7bfd5bbd740d2df55ff64e1309 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 7 Aug 2018 13:36:59 -0700 Subject: Add static site build --- packages/sra-api/src/api.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index da61cb1b0..762d3f4d6 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -19,11 +19,8 @@ export const api: OpenApiSpec = { url: 'https://www.apache.org/licenses/LICENSE-2.0.html', }, }, - servers: [ - // TODO: Use relayer registry information here? - ], paths: { - '/asset_pairs': { + '/v2/asset_pairs': { get: { description: 'Retrieves a list of available asset pairs and the information required to trade them (in any order). Setting only `asset_data_a` or `asset_data_b` returns pairs filtered by that asset only.', -- cgit v1.2.3 From f4c2fabbf8f8eccd5cd7c65035e78ad268a34b57 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 7 Aug 2018 15:03:52 -0700 Subject: Minor refactoring --- packages/sra-api/src/api.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index 762d3f4d6..c93d57946 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -50,7 +50,8 @@ export const api: OpenApiSpec = { ), responses: generateResponses( 'relayerApiAssetDataPairsResponseSchema', - examples.relayerApiAssetDataPairsResponseSchema, + examples.relayerApiAssetDataPairsResponse, + `Returns a collection of available asset pairs with some meta info`, ), }, }, -- cgit v1.2.3 From f36a43a83f6c8ae32d36768da8c97858ef051446 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 7 Aug 2018 15:38:50 -0700 Subject: Add orders endpoint --- packages/sra-api/src/api.ts | 127 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 1 deletion(-) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index c93d57946..d80fb9b41 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -5,7 +5,7 @@ import { examples } from './examples'; import { md } from './md'; import { generateParameters } from './parameters'; import { generateResponses } from './responses'; -// We need to replace the `$ref`s to be openAPI compliant. +// We need to replace the `$ref`s to be OpenAPI compliant. const openApiSchemas = JSON.parse(JSON.stringify(schemas).replace(/(\/\w+)/g, match => `#/components/schemas${match}`)); export const api: OpenApiSpec = { @@ -55,6 +55,131 @@ export const api: OpenApiSpec = { ), }, }, + '/v2/orders': { + get: { + description: + 'Retrieves a list of orders given query parameters. This endpoint should be [paginated](#section/Pagination). For querying an entire orderbook snapshot, the [orderbook endpoint](#operation/getOrderbook) is recommended. If both makerAssetData and takerAssetData are specified, returned orders will be sorted by price determined by (takerTokenAmount/makerTokenAmount) in ascending order. By default, orders returned by this endpoint are unsorted.', + operationId: 'getOrders', + parameters: generateParameters( + [ + { + name: 'makerAssetProxyId', + in: 'query', + description: `The maker [asset proxy id](https://0xproject.com/docs/0x.js#types-AssetProxyId) (example: "0xf47261b0" for ERC20, "0x02571792" for ERC721).`, + example: '0xf47261b0', + schema: { + $ref: '#/components/schemas/hexSchema', + }, + }, + { + name: 'takerAssetProxyId', + in: 'query', + description: `The taker asset [asset proxy id](https://0xproject.com/docs/0x.js#types-AssetProxyId) (example: "0xf47261b0" for ERC20, "0x02571792" for ERC721).`, + example: '0x02571792', + schema: { + $ref: '#/components/schemas/hexSchema', + }, + }, + { + name: 'makerAssetAddress', + in: 'query', + description: `The contract address for the maker asset.`, + example: '0xe41d2489571d322189246dafa5ebde1f4699f498', + schema: { + $ref: '#/components/schemas/addressSchema', + }, + }, + { + name: 'takerAssetAddress', + in: 'query', + description: `The contract address for the taker asset.`, + example: '0xe41d2489571d322189246dafa5ebde1f4699f498', + schema: { + $ref: '#/components/schemas/addressSchema', + }, + }, + { + name: 'exchangeAddress', + in: 'query', + description: `Same as exchangeAddress in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`, + example: '0xe41d2489571d322189246dafa5ebde1f4699f498', + schema: { + $ref: '#/components/schemas/addressSchema', + }, + }, + { + name: 'senderAddress', + in: 'query', + description: `Same as senderAddress in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`, + example: '0xe41d2489571d322189246dafa5ebde1f4699f498', + schema: { + $ref: '#/components/schemas/addressSchema', + }, + }, + { + name: 'makerAssetData', + in: 'query', + description: `Same as makerAssetData in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`, + example: '0xe41d2489571d322189246dafa5ebde1f4699f498', + schema: { + $ref: '#/components/schemas/hexSchema', + }, + }, + { + name: 'takerAssetData', + in: 'query', + description: `Same as takerAssetData in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`, + example: '0xe41d2489571d322189246dafa5ebde1f4699f498', + schema: { + $ref: '#/components/schemas/hexSchema', + }, + }, + { + name: 'traderAssetData', + in: 'query', + description: `Same as traderAssetData in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`, + example: '0xe41d2489571d322189246dafa5ebde1f4699f498', + schema: { + $ref: '#/components/schemas/hexSchema', + }, + }, + { + name: 'makerAddress', + in: 'query', + description: `Same as makerAddress in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`, + example: '0xe41d2489571d322189246dafa5ebde1f4699f498', + schema: { + $ref: '#/components/schemas/addressSchema', + }, + }, + { + name: 'traderAddress', + in: 'query', + description: `Same as traderAddress in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`, + example: '0xe41d2489571d322189246dafa5ebde1f4699f498', + schema: { + $ref: '#/components/schemas/addressSchema', + }, + }, + { + name: 'feeRecipientAddress', + in: 'query', + description: `Same as feeRecipientAddress in the [0x Protocol v2 Specification](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format)`, + example: '0xe41d2489571d322189246dafa5ebde1f4699f498', + schema: { + $ref: '#/components/schemas/addressSchema', + }, + }, + ], + true, + ), + responses: generateResponses( + 'relayerApiOrdersResponseSchema', + examples.relayerApiOrdersResponse, + `Returns a collection of 0x orders with meta-data as specified by query params`, + ), + }, + }, }, components: { schemas: openApiSchemas, -- cgit v1.2.3 From f6dbc239958e37a585d3f89b98eb6cd473895335 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 7 Aug 2018 16:10:59 -0700 Subject: Add GET order endpoint spec --- packages/sra-api/src/api.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index d80fb9b41..2cc15b297 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -176,7 +176,32 @@ export const api: OpenApiSpec = { responses: generateResponses( 'relayerApiOrdersResponseSchema', examples.relayerApiOrdersResponse, - `Returns a collection of 0x orders with meta-data as specified by query params`, + `A collection of 0x orders with meta-data as specified by query params`, + ), + }, + }, + '/v2/order/{orderHash}': { + get: { + description: 'Retrieves the 0x order with meta info that is associated with the hash.', + operationId: 'getOrder', + parameters: generateParameters( + [ + { + name: 'orderHash', + in: 'path', + description: 'The hash of the desired 0x order.', + example: '0xd4b103c42d2512eef3fee775e097f044291615d25f5d71e0ac70dbd49d223591', + schema: { + $ref: '#/components/schemas/orderHashSchema', + }, + }, + ], + true, + ), + responses: generateResponses( + 'relayerApiOrderSchema', + examples.relayerApiOrder, + `The order and meta info associated with the orderHash`, ), }, }, -- cgit v1.2.3 From 3771df728c2dfcdeeb3fc49cd27ef864f2e94316 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 7 Aug 2018 16:24:31 -0700 Subject: Add GET OrderBook endpoint --- packages/sra-api/src/api.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index 2cc15b297..5289a31f3 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -205,6 +205,42 @@ export const api: OpenApiSpec = { ), }, }, + '/v2/orderbook': { + get: { + description: `Retrieves the orderbook for a given asset pair. This endpoint should be [paginated](#section/Pagination). Bids will be sorted in descending order by price, and asks will be sorted in ascending order by price. Within the price sorted orders, the orders are further sorted by _taker fee price_ which is defined as the **takerFee** divided by **takerTokenAmount**. After _taker fee price_, orders are to be sorted by expiration in ascending order. The way pagination works for this endpoint is that the **page** and **per_page** query params apply to both \`bids\` and \`asks\` collections, and if \`page\` * \`per_page\` > \`total\` for a certain collection, the \`records\` for that collection should just be empty. `, + operationId: 'getOrderBook', + parameters: generateParameters( + [ + { + name: 'baseAssetData', + in: 'query', + description: `assetData (makerAssetData or takerAssetData) designated as the base currency in the [currency pair calculation](https://en.wikipedia.org/wiki/Currency_pair) of price.`, + required: true, + example: '0xf47261b04c32345ced77393b3530b1eed0f346429d', + schema: { + $ref: '#/components/schemas/hexSchema', + }, + }, + { + name: 'quoteAssetData', + in: 'query', + description: `assetData (makerAssetData or takerAssetData) designated as the quote currency in the currency pair calculation of price (required).`, + required: true, + example: '0xf47261b04c32345ced77393b3530b1eed0f346429d', + schema: { + $ref: '#/components/schemas/hexSchema', + }, + }, + ], + true, + ), + responses: generateResponses( + 'relayerApiOrderBookResponseSchema', + examples.relayerApiOrderBookResponse, + `The sorted order book for the specified asset pair.`, + ), + }, + }, }, components: { schemas: openApiSchemas, -- cgit v1.2.3 From b0a7db81cb2bde774f410938578476200d1dc694 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 7 Aug 2018 16:51:47 -0700 Subject: Add GET order_config --- packages/sra-api/src/api.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index 5289a31f3..129fd3722 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -241,6 +241,29 @@ export const api: OpenApiSpec = { ), }, }, + '/v2/order_config': { + get: { + description: `Relayers have full discretion over the orders that they are willing to host on their orderbooks (e.g what fees they charge, etc...). In order for traders to discover their requirements programmatically, they can send an incomplete order to this endpoint and receive the missing fields, specifc to that order. This gives relayers a large amount of flexibility to tailor fees to unique traders, trading pairs and volume amounts. Submit a partial order and receive information required to complete the order: \`senderAddress\`, \`feeRecipientAddress\`, \`makerFee\`, \`takerFee\`. `, + operationId: 'getOrderConfig', + requestBody: { + description: + 'The fields of a 0x order the relayer may want to decide what configuration to send back.', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/relayerApiOrderConfigPayloadSchema', + }, + example: examples.relayerApiOrderConfigPayload, + }, + }, + }, + responses: generateResponses( + 'relayerApiOrderConfigResponseSchema', + examples.relayerApiOrderConfigResponse, + `The additional fields necessary in order to submit an order to the relayer.`, + ), + }, + }, }, components: { schemas: openApiSchemas, -- cgit v1.2.3 From 95b656f360f635447725e00bb90642f1b859477a Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 7 Aug 2018 17:42:22 -0700 Subject: Add GET fee_recipients --- packages/sra-api/src/api.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index 129fd3722..50e656599 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -264,6 +264,18 @@ export const api: OpenApiSpec = { ), }, }, + '/v2/fee_recipients': { + get: { + description: `Retrieves a collection of all fee recipient addresses for a relayer. This endpoint should be [paginated](#section/Pagination).`, + operationId: 'getFeeRecipients', + parameters: generateParameters([], true), + responses: generateResponses( + 'relayerApiFeeRecipientsResponseSchema', + examples.relayerApiFeeRecipientsResponse, + `A collection of all used fee recipient addresses.`, + ), + }, + }, }, components: { schemas: openApiSchemas, -- cgit v1.2.3 From 4e30bc3e16d7e0e8876fab09a61e9446c2c9d93f Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 7 Aug 2018 17:58:38 -0700 Subject: Add POST order endpoint --- packages/sra-api/src/api.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index 50e656599..5973e11cd 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -196,7 +196,7 @@ export const api: OpenApiSpec = { }, }, ], - true, + false, ), responses: generateResponses( 'relayerApiOrderSchema', @@ -245,6 +245,7 @@ export const api: OpenApiSpec = { get: { description: `Relayers have full discretion over the orders that they are willing to host on their orderbooks (e.g what fees they charge, etc...). In order for traders to discover their requirements programmatically, they can send an incomplete order to this endpoint and receive the missing fields, specifc to that order. This gives relayers a large amount of flexibility to tailor fees to unique traders, trading pairs and volume amounts. Submit a partial order and receive information required to complete the order: \`senderAddress\`, \`feeRecipientAddress\`, \`makerFee\`, \`takerFee\`. `, operationId: 'getOrderConfig', + parameters: generateParameters([], false), requestBody: { description: 'The fields of a 0x order the relayer may want to decide what configuration to send back.', @@ -276,6 +277,25 @@ export const api: OpenApiSpec = { ), }, }, + '/v2/order': { + post: { + description: `Submit a signed order to the relayer.`, + operationId: 'postOrder', + parameters: generateParameters([], false), + requestBody: { + description: 'A valid signed 0x order based on the schema.', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/signedOrderSchema', + }, + example: examples.signedOrder, + }, + }, + }, + responses: generateResponses(), + }, + }, }, components: { schemas: openApiSchemas, -- cgit v1.2.3 From 9aacceb0e4549a7a72cae7cbf74ea819db184d80 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 8 Aug 2018 14:00:50 -0700 Subject: Remove tests directory, use swagger api, make json api compliant --- packages/sra-api/src/api.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index 5973e11cd..e578ddc74 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -1,12 +1,10 @@ -import { schemas } from '@0xproject/json-schemas'; import { OpenApiSpec } from '@loopback/openapi-v3-types'; import { examples } from './examples'; +import { schemas } from './json-schemas'; import { md } from './md'; import { generateParameters } from './parameters'; import { generateResponses } from './responses'; -// We need to replace the `$ref`s to be OpenAPI compliant. -const openApiSchemas = JSON.parse(JSON.stringify(schemas).replace(/(\/\w+)/g, match => `#/components/schemas${match}`)); export const api: OpenApiSpec = { openapi: '3.0.0', @@ -298,6 +296,6 @@ export const api: OpenApiSpec = { }, }, components: { - schemas: openApiSchemas, + schemas, }, }; -- cgit v1.2.3 From 6121a6d2bffed7187a875148a5e36d0b4b7645ac Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 8 Aug 2018 14:28:09 -0700 Subject: Add to changelog and fix OrderBook typo --- packages/sra-api/src/api.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/sra-api/src/api.ts') diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index e578ddc74..c2236fda5 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -206,7 +206,7 @@ export const api: OpenApiSpec = { '/v2/orderbook': { get: { description: `Retrieves the orderbook for a given asset pair. This endpoint should be [paginated](#section/Pagination). Bids will be sorted in descending order by price, and asks will be sorted in ascending order by price. Within the price sorted orders, the orders are further sorted by _taker fee price_ which is defined as the **takerFee** divided by **takerTokenAmount**. After _taker fee price_, orders are to be sorted by expiration in ascending order. The way pagination works for this endpoint is that the **page** and **per_page** query params apply to both \`bids\` and \`asks\` collections, and if \`page\` * \`per_page\` > \`total\` for a certain collection, the \`records\` for that collection should just be empty. `, - operationId: 'getOrderBook', + operationId: 'getOrderbook', parameters: generateParameters( [ { @@ -233,8 +233,8 @@ export const api: OpenApiSpec = { true, ), responses: generateResponses( - 'relayerApiOrderBookResponseSchema', - examples.relayerApiOrderBookResponse, + 'relayerApiOrderbookResponseSchema', + examples.relayerApiOrderbookResponse, `The sorted order book for the specified asset pair.`, ), }, -- cgit v1.2.3