@riocrypto/common-server 1.0.2748 → 1.0.2749

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,6 +83,27 @@ export interface BinanceExchangeInfo {
83
83
  serverTime: number;
84
84
  symbols: any[];
85
85
  }
86
+ export interface BinanceFiatWithdrawResponse {
87
+ code: string;
88
+ message: string;
89
+ data: {
90
+ orderId: string;
91
+ };
92
+ }
93
+ export interface BinanceFiatOrderDetail {
94
+ code: string;
95
+ message: string;
96
+ data: {
97
+ orderId: string;
98
+ orderStatus: string;
99
+ amount: string;
100
+ fee: string;
101
+ fiatCurrency: string;
102
+ errorCode: string;
103
+ errorMessage: string;
104
+ ext: Record<string, any>;
105
+ };
106
+ }
86
107
  export declare enum BinanceOrderStatus {
87
108
  NEW = "NEW",
88
109
  PARTIALLY_FILLED = "PARTIALLY_FILLED",
@@ -103,6 +124,7 @@ declare class BinanceClient {
103
124
  private sign;
104
125
  private signedGet;
105
126
  private signedPost;
127
+ private signedPostWithBody;
106
128
  private signedDelete;
107
129
  private publicGet;
108
130
  getAccountInformation(skipLogging?: boolean): Promise<BinanceAccountInfo>;
@@ -154,12 +176,24 @@ declare class BinanceClient {
154
176
  limit?: number;
155
177
  txId?: string;
156
178
  }): Promise<BinanceDepositHistoryItem[]>;
179
+ withdrawFiat(params: {
180
+ currency: string;
181
+ apiPaymentMethod: string;
182
+ amount: number;
183
+ accountInfo: {
184
+ accountNumber: string;
185
+ [key: string]: any;
186
+ };
187
+ ext?: Record<string, any>;
188
+ }): Promise<BinanceFiatWithdrawResponse>;
189
+ getFiatOrderDetail(orderNo: string): Promise<BinanceFiatOrderDetail>;
157
190
  private convertCryptoToBinanceDescriptor;
158
191
  getDepositAddressForCrypto(cryptoAsset: Crypto): Promise<{
159
192
  address: string;
160
193
  memo?: string;
161
194
  }>;
162
195
  withdrawCrypto(cryptoAsset: Crypto, amount: number, address: string, memo?: string): Promise<string>;
196
+ withdrawMXN(amount: number, clabe: string): Promise<string>;
163
197
  getWithdrawalHistoryByOrderId(withdrawalId: string): Promise<BinanceWithdrawHistoryItem[]>;
164
198
  getDepositByTxHash(hash: string): Promise<BinanceDepositHistoryItem | undefined>;
165
199
  createMarketOrder(symbol: string, amount: number, side: "BUY" | "SELL"): Promise<BinanceOrderResponse>;
@@ -72,6 +72,21 @@ class BinanceClient {
72
72
  return response.data;
73
73
  });
74
74
  }
75
+ signedPostWithBody(path, body, queryParams = {}) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const allQueryParams = Object.assign(Object.assign({}, queryParams), { timestamp: Date.now() });
78
+ const queryString = this.buildQueryString(allQueryParams);
79
+ const bodyString = JSON.stringify(body);
80
+ const signature = this.sign(queryString + bodyString);
81
+ const response = yield this.axiosClient.post(`${this.baseUrl}${path}?${queryString}&signature=${signature}`, body, {
82
+ headers: {
83
+ "X-MBX-APIKEY": this.apiKey,
84
+ "Content-Type": "application/json",
85
+ },
86
+ });
87
+ return response.data;
88
+ });
89
+ }
75
90
  signedDelete(path, params = {}) {
76
91
  return __awaiter(this, void 0, void 0, function* () {
77
92
  const allParams = Object.assign(Object.assign({}, params), { timestamp: Date.now() });
@@ -201,6 +216,17 @@ class BinanceClient {
201
216
  return this.signedGet("/sapi/v1/capital/deposit/hisrec", params || {});
202
217
  });
203
218
  }
219
+ // Fiat
220
+ withdrawFiat(params) {
221
+ return __awaiter(this, void 0, void 0, function* () {
222
+ return this.signedPostWithBody("/sapi/v2/fiat/withdraw", params);
223
+ });
224
+ }
225
+ getFiatOrderDetail(orderNo) {
226
+ return __awaiter(this, void 0, void 0, function* () {
227
+ return this.signedGet("/sapi/v1/fiat/get-order-detail", { orderNo });
228
+ });
229
+ }
204
230
  // Convenience methods
205
231
  convertCryptoToBinanceDescriptor(cryptoAsset) {
206
232
  switch (cryptoAsset) {
@@ -271,6 +297,23 @@ class BinanceClient {
271
297
  }
272
298
  });
273
299
  }
300
+ withdrawMXN(amount, clabe) {
301
+ return __awaiter(this, void 0, void 0, function* () {
302
+ if ([common_1.RioEnv.Sandbox, common_1.RioEnv.Local, common_1.RioEnv.Test].includes(process.env.RIO_ENV)) {
303
+ throw new Error("Binance fiat withdraw not allowed in sandbox");
304
+ }
305
+ const response = yield this.withdrawFiat({
306
+ currency: "MXN",
307
+ apiPaymentMethod: "bank_transfer",
308
+ amount,
309
+ accountInfo: { accountNumber: clabe },
310
+ });
311
+ if (response.code !== "000000") {
312
+ throw new Error(`Fiat withdraw failed: ${response.message}`);
313
+ }
314
+ return response.data.orderId;
315
+ });
316
+ }
274
317
  getWithdrawalHistoryByOrderId(withdrawalId) {
275
318
  return __awaiter(this, void 0, void 0, function* () {
276
319
  console.log("Withdrawal id: ", withdrawalId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2748",
3
+ "version": "1.0.2749",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",