@riocrypto/common-server 1.0.2748 → 1.0.2750

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,20 @@ 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 signature = this.sign(queryString);
80
+ const response = yield this.axiosClient.post(`${this.baseUrl}${path}?${queryString}&signature=${signature}`, body, {
81
+ headers: {
82
+ "X-MBX-APIKEY": this.apiKey,
83
+ "Content-Type": "application/json",
84
+ },
85
+ });
86
+ return response.data;
87
+ });
88
+ }
75
89
  signedDelete(path, params = {}) {
76
90
  return __awaiter(this, void 0, void 0, function* () {
77
91
  const allParams = Object.assign(Object.assign({}, params), { timestamp: Date.now() });
@@ -201,6 +215,17 @@ class BinanceClient {
201
215
  return this.signedGet("/sapi/v1/capital/deposit/hisrec", params || {});
202
216
  });
203
217
  }
218
+ // Fiat
219
+ withdrawFiat(params) {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ return this.signedPostWithBody("/sapi/v2/fiat/withdraw", params);
222
+ });
223
+ }
224
+ getFiatOrderDetail(orderNo) {
225
+ return __awaiter(this, void 0, void 0, function* () {
226
+ return this.signedGet("/sapi/v1/fiat/get-order-detail", { orderNo });
227
+ });
228
+ }
204
229
  // Convenience methods
205
230
  convertCryptoToBinanceDescriptor(cryptoAsset) {
206
231
  switch (cryptoAsset) {
@@ -271,6 +296,23 @@ class BinanceClient {
271
296
  }
272
297
  });
273
298
  }
299
+ withdrawMXN(amount, clabe) {
300
+ return __awaiter(this, void 0, void 0, function* () {
301
+ if ([common_1.RioEnv.Sandbox, common_1.RioEnv.Local, common_1.RioEnv.Test].includes(process.env.RIO_ENV)) {
302
+ throw new Error("Binance fiat withdraw not allowed in sandbox");
303
+ }
304
+ const response = yield this.withdrawFiat({
305
+ currency: "MXN",
306
+ apiPaymentMethod: "bank_transfer",
307
+ amount,
308
+ accountInfo: { accountNumber: clabe },
309
+ });
310
+ if (response.code !== "000000") {
311
+ throw new Error(`Fiat withdraw failed: ${response.message}`);
312
+ }
313
+ return response.data.orderId;
314
+ });
315
+ }
274
316
  getWithdrawalHistoryByOrderId(withdrawalId) {
275
317
  return __awaiter(this, void 0, void 0, function* () {
276
318
  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.2750",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",