Skip to content

Commit

Permalink
Merge pull request #32 from tiagosiebler/orders
Browse files Browse the repository at this point in the history
fix(): post req orders
  • Loading branch information
tiagosiebler authored Sep 19, 2024
2 parents 89df598 + f0b7d6f commit eac31a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/CBExchangeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ export class CBExchangeClient extends BaseRestClient {
* Get a single order by id.
*/
getOrder(params: { order_id: string; market_type?: string }): Promise<any> {
return this.getPrivate(`/orders/${params.order_id}`, params);
const { order_id, ...otherParams } = params;
return this.getPrivate(`/orders/${order_id}`, otherParams);
}

/**
Expand All @@ -432,8 +433,9 @@ export class CBExchangeClient extends BaseRestClient {
* Cancel a single open order by id.
*/
cancelOrder(params: CancelCBExchOrderRequest): Promise<any> {
return this.deletePrivate(`/orders/${params.order_id}`, {
query: params,
const { order_id, ...otherParams } = params;
return this.deletePrivate(`/orders/${order_id}`, {
body: otherParams,
});
}

Expand Down
16 changes: 8 additions & 8 deletions src/lib/BaseRestClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
import https from 'https';
import { nanoid } from 'nanoid';
Expand Down Expand Up @@ -397,9 +396,7 @@ export abstract class BaseRestClient {
const encodeQueryStringValues = true;

const requestBody = data?.body || data;
const requestBodyString = requestBody
? JSON.stringify(data?.body || data)
: '';
const requestBodyString = requestBody ? JSON.stringify(requestBody) : '';

if (signMethod === 'coinbase') {
const clientType = this.getClientType();
Expand Down Expand Up @@ -458,7 +455,7 @@ export abstract class BaseRestClient {
const timestampInSeconds = timestampInMs / 1000; // decimals are OK

const signInput =
timestampInSeconds + method + endpoint + requestBodyString;
timestampInSeconds + method + endpoint + signRequestParams;

if (!apiSecret) {
throw new Error(`No API secret provided, cannot sign request.`);
Expand All @@ -483,6 +480,7 @@ export abstract class BaseRestClient {
'CB-ACCESS-PASSPHRASE': apiPassphrase,
};

// console.log('sign res: ', { signInput, ...headers });
return {
...res,
sign: sign,
Expand Down Expand Up @@ -656,10 +654,12 @@ export abstract class BaseRestClient {
...options.headers,
};

const urlWithQueryParams =
options.url + '?' + signResult.queryParamsWithSign;
let urlWithQueryParams = options.url;

if (method === 'GET' || !params?.body) {
if (method === 'GET') {
if (signResult.queryParamsWithSign) {
urlWithQueryParams += signResult.queryParamsWithSign;
}
return {
...options,
headers: requestHeaders,
Expand Down

0 comments on commit eac31a8

Please sign in to comment.