@openweb3-io/dex-aggregator
Version:
dex-aggregator API client and webhook verification library
131 lines (101 loc) • 5.22 kB
text/typescript
// TODO: better import syntax?
import {BaseAPIRequestFactory, RequiredError, COLLECTION_FORMATS} from './baseapi';
import {Configuration} from '../configuration';
import {RequestContext, HttpMethod, ResponseContext, HttpFile, HttpInfo} from '../http/http';
import {ObjectSerializer} from '../models/ObjectSerializer';
import {ApiException} from './exception';
import {canConsumeForm, isCodeInRange} from '../util';
import {SecurityAuthentication} from '../auth/auth';
import { TradePage } from '../models/TradePage';
/**
* no description
*/
export class TradeApiRequestFactory extends BaseAPIRequestFactory {
/**
* CONTROLLER.TRADE.GET.TOKEN.DESCRIPTION
* CONTROLLER.TRADE.GET.TOKEN.SUMMARY
* @param chain GLOBAL.CHAIN.DESCRIPTION
* @param cursor CONTROLLER.TRADE.LIST.CURSOR.DESCRIPTION
* @param limit DTO.TRADE.QUERY.LIMIT
* @param tokenAddress DTO.TRADE.QUERY.TOKEN_ADDRESS
* @param walletAddress DTO.TRADE.QUERY.WALLET_ADDRESS
* @param direction DTO.TRADE.QUERY.DIRECTION
*/
public async getTrades(chain: 'sol' | 'base', cursor?: string, limit?: number, tokenAddress?: string, walletAddress?: string, direction?: 'next' | 'prev', _options?: Configuration): Promise<RequestContext> {
let _config = _options || this.configuration;
// verify required parameter 'chain' is not null or undefined
if (chain === null || chain === undefined) {
throw new RequiredError("TradeApi", "getTrades", "chain");
}
// Path Params
const localVarPath = '/trade';
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
const randomId = Math.floor(Math.random() * Math.pow(2, 32))
requestContext.setHeaderParam("x-req-id", randomId.toString())
// Query Params
if (cursor !== undefined) {
requestContext.setQueryParam("cursor", ObjectSerializer.serialize(cursor, "string", ""));
}
// Query Params
if (limit !== undefined) {
requestContext.setQueryParam("limit", ObjectSerializer.serialize(limit, "number", ""));
}
// Query Params
if (tokenAddress !== undefined) {
requestContext.setQueryParam("tokenAddress", ObjectSerializer.serialize(tokenAddress, "string", ""));
}
// Query Params
if (walletAddress !== undefined) {
requestContext.setQueryParam("walletAddress", ObjectSerializer.serialize(walletAddress, "string", ""));
}
// Query Params
if (chain !== undefined) {
requestContext.setQueryParam("chain", ObjectSerializer.serialize(chain, "'sol' | 'base'", ""));
}
// Query Params
if (direction !== undefined) {
requestContext.setQueryParam("direction", ObjectSerializer.serialize(direction, "'next' | 'prev'", ""));
}
let authMethod: SecurityAuthentication | undefined;
// Apply auth methods
authMethod = _config.authMethods["bearer"]
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
}
export class TradeApiResponseProcessor {
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to getTrades
* @throws ApiException if the response code was not in [200, 299]
*/
public async getTradesWithHttpInfo(response: ResponseContext): Promise<HttpInfo<TradePage >> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body: TradePage = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"TradePage", ""
) as TradePage;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body: TradePage = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"TradePage", ""
) as TradePage;
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers);
}
}