diff options
Diffstat (limited to 'packages/asset-buyer/src/order_fetchers')
-rw-r--r-- | packages/asset-buyer/src/order_fetchers/provided_order_fetcher.ts | 32 | ||||
-rw-r--r-- | packages/asset-buyer/src/order_fetchers/standard_relayer_api_order_fetcher.ts | 78 |
2 files changed, 0 insertions, 110 deletions
diff --git a/packages/asset-buyer/src/order_fetchers/provided_order_fetcher.ts b/packages/asset-buyer/src/order_fetchers/provided_order_fetcher.ts deleted file mode 100644 index 397f296d7..000000000 --- a/packages/asset-buyer/src/order_fetchers/provided_order_fetcher.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { schemas } from '@0xproject/json-schemas'; -import { SignedOrder } from '@0xproject/types'; -import * as _ from 'lodash'; - -import { OrderProvider, OrderProviderRequest, OrderProviderResponse } from '../types'; -import { assert } from '../utils/assert'; - -export class ProvidedOrderFetcher implements OrderProvider { - public readonly providedOrders: SignedOrder[]; - /** - * Instantiates a new ProvidedOrderFetcher instance - * @param providedOrders An array of objects that conform to SignedOrder to fetch from. - * @return An instance of ProvidedOrderFetcher - */ - constructor(providedOrders: SignedOrder[]) { - assert.doesConformToSchema('providedOrders', providedOrders, schemas.signedOrdersSchema); - this.providedOrders = providedOrders; - } - /** - * Given an object that conforms to OrderFetcherRequest, return the corresponding OrderFetcherResponse that satisfies the request. - * @param orderFetchRequest An instance of OrderFetcherRequest. See type for more information. - * @return An instance of OrderFetcherResponse. See type for more information. - */ - public async getOrdersAsync(orderFetchRequest: OrderProviderRequest): Promise<OrderProviderResponse> { - assert.isValidOrderFetcherRequest('orderFetchRequest', orderFetchRequest); - const { makerAssetData, takerAssetData } = orderFetchRequest; - const orders = _.filter(this.providedOrders, order => { - return order.makerAssetData === makerAssetData && order.takerAssetData === takerAssetData; - }); - return { orders }; - } -} diff --git a/packages/asset-buyer/src/order_fetchers/standard_relayer_api_order_fetcher.ts b/packages/asset-buyer/src/order_fetchers/standard_relayer_api_order_fetcher.ts deleted file mode 100644 index 730eaf4e0..000000000 --- a/packages/asset-buyer/src/order_fetchers/standard_relayer_api_order_fetcher.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { APIOrder, HttpClient, OrderbookResponse } from '@0xproject/connect'; -import * as _ from 'lodash'; - -import { - AssetBuyerError, - OrderProvider, - OrderProviderRequest, - OrderProviderResponse, - SignedOrderWithRemainingFillableMakerAssetAmount, -} from '../types'; -import { assert } from '../utils/assert'; -import { orderUtils } from '../utils/order_utils'; - -export class StandardRelayerAPIOrderFetcher implements OrderProvider { - public readonly apiUrl: string; - private readonly _sraClient: HttpClient; - /** - * Given an array of APIOrder objects from a standard relayer api, return an array - * of SignedOrderWithRemainingFillableMakerAssetAmounts - */ - private static _getSignedOrderWithRemainingFillableMakerAssetAmountFromApi( - apiOrders: APIOrder[], - ): SignedOrderWithRemainingFillableMakerAssetAmount[] { - const result = _.map(apiOrders, apiOrder => { - const { order, metaData } = apiOrder; - // calculate remainingFillableMakerAssetAmount from api metadata, else assume order is completely fillable - const remainingFillableTakerAssetAmount = _.get( - metaData, - 'remainingTakerAssetAmount', - order.takerAssetAmount, - ); - const remainingFillableMakerAssetAmount = orderUtils.calculateRemainingMakerAssetAmount( - order, - remainingFillableTakerAssetAmount, - ); - const newOrder = { - ...order, - remainingFillableMakerAssetAmount, - }; - return newOrder; - }); - return result; - } - /** - * Instantiates a new StandardRelayerAPIOrderFetcher instance - * @param apiUrl The standard relayer API base HTTP url you would like to source orders from. - * @return An instance of StandardRelayerAPIOrderFetcher - */ - constructor(apiUrl: string) { - assert.isWebUri('apiUrl', apiUrl); - this.apiUrl = apiUrl; - this._sraClient = new HttpClient(apiUrl); - } - /** - * Given an object that conforms to OrderFetcherRequest, return the corresponding OrderFetcherResponse that satisfies the request. - * @param orderFetchRequest An instance of OrderFetcherRequest. See type for more information. - * @return An instance of OrderFetcherResponse. See type for more information. - */ - public async getOrdersAsync(orderFetchRequest: OrderProviderRequest): Promise<OrderProviderResponse> { - assert.isValidOrderFetcherRequest('orderFetchRequest', orderFetchRequest); - const { makerAssetData, takerAssetData, networkId } = orderFetchRequest; - const orderbookRequest = { baseAssetData: makerAssetData, quoteAssetData: takerAssetData }; - const requestOpts = { networkId }; - let orderbook: OrderbookResponse; - try { - orderbook = await this._sraClient.getOrderbookAsync(orderbookRequest, requestOpts); - } catch (err) { - throw new Error(AssetBuyerError.StandardRelayerApiError); - } - const apiOrders = orderbook.asks.records; - const orders = StandardRelayerAPIOrderFetcher._getSignedOrderWithRemainingFillableMakerAssetAmountFromApi( - apiOrders, - ); - return { - orders, - }; - } -} |