@riocrypto/common-server 1.0.1125 → 1.0.1127

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.
@@ -1,5 +1,5 @@
1
1
  import { AxiosRequestConfig } from "axios";
2
- import { BankAccount, User } from "@riocrypto/common";
2
+ import { BankAccount, Crypto, User } from "@riocrypto/common";
3
3
  declare class BitsoClient {
4
4
  private apiKey;
5
5
  private apiSecret;
@@ -9,6 +9,24 @@ declare class BitsoClient {
9
9
  createClabe(): Promise<string>;
10
10
  createReceivingAccount(user: User, bankAccount: BankAccount, bitsoBankAccountCode: string): Promise<string>;
11
11
  createWithdraw(bitsoReceivingAccountId: string, amount: number, concept: string, rfc?: string): Promise<string>;
12
+ createLimitOrder(asset: string, amount: number, price: number, side: "buy" | "sell"): Promise<{
13
+ amountFilled: number;
14
+ oid?: string;
15
+ }>;
16
+ getOrderBook(crypto: Crypto): Promise<{
17
+ asks: {
18
+ book: string;
19
+ price: string;
20
+ amount: string;
21
+ }[];
22
+ bids: {
23
+ book: string;
24
+ price: string;
25
+ amount: string;
26
+ }[];
27
+ updated_at: string;
28
+ sequence: string;
29
+ }>;
12
30
  signRequest(requestConfig: AxiosRequestConfig): AxiosRequestConfig;
13
31
  }
14
32
  export declare const buildBistoClient: () => Promise<BitsoClient>;
@@ -26,6 +26,7 @@ class BitsoClient {
26
26
  env === "production"
27
27
  ? "https://api.bitso.com"
28
28
  : "https://stage.bitso.com";
29
+ console.log("This base url is: ", this.baseUrl);
29
30
  }
30
31
  createClabe() {
31
32
  return __awaiter(this, void 0, void 0, function* () {
@@ -102,6 +103,48 @@ class BitsoClient {
102
103
  return data.payload;
103
104
  });
104
105
  }
106
+ createLimitOrder(asset, amount, price, side) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const requestConfig = {
109
+ method: "POST",
110
+ url: `${this.baseUrl}/api/v3/orders`,
111
+ headers: {
112
+ "Content-Type": "application/json",
113
+ },
114
+ data: {
115
+ book: `${asset}_mxn`,
116
+ minor: amount.toString(),
117
+ price: price.toString(),
118
+ side,
119
+ time_in_force: "fillorkill",
120
+ type: "limit",
121
+ },
122
+ };
123
+ const signedRequestConfig = this.signRequest(requestConfig);
124
+ const { data } = yield (0, axios_1.default)(signedRequestConfig);
125
+ if (!data.success) {
126
+ throw new Error("Error creating Bitso limit order");
127
+ }
128
+ return data.payload;
129
+ });
130
+ }
131
+ getOrderBook(crypto) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ const requestConfig = {
134
+ method: "GET",
135
+ url: `${this.baseUrl}/api/v3/order_book/?book=${crypto.toLocaleLowerCase()}_mxn`,
136
+ headers: {
137
+ "Content-Type": "application/json",
138
+ },
139
+ };
140
+ const signedRequestConfig = this.signRequest(requestConfig);
141
+ const { data } = yield (0, axios_1.default)(signedRequestConfig);
142
+ if (!data.success) {
143
+ throw new Error("Error getting Bitso order book");
144
+ }
145
+ return data.payload;
146
+ });
147
+ }
105
148
  signRequest(requestConfig) {
106
149
  var _a;
107
150
  const url = new URL(requestConfig.url || "");
@@ -132,8 +175,7 @@ const buildBistoClient = () => __awaiter(void 0, void 0, void 0, function* () {
132
175
  throw new common_1.SecretManagerError();
133
176
  }
134
177
  const env = process.env.RIO_ENV === common_1.RioEnv.Production ||
135
- process.env.RIO_ENV === common_1.RioEnv.Staging ||
136
- process.env.RIO_ENV === common_1.RioEnv.Development
178
+ process.env.RIO_ENV === common_1.RioEnv.Staging
137
179
  ? "production"
138
180
  : "sandbox";
139
181
  return new BitsoClient(BITSO_API_KEY, BITSO_API_SECRET, env);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1125",
3
+ "version": "1.0.1127",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "@aws-sdk/client-s3": "^3.297.0",
27
27
  "@everapi/currencyapi-js": "^1.0.6",
28
28
  "@google-cloud/storage": "^6.9.5",
29
- "@riocrypto/common": "^1.0.972",
29
+ "@riocrypto/common": "^1.0.974",
30
30
  "@types/express": "^4.17.13",
31
31
  "axios": "^0.27.2",
32
32
  "ccxt": "^3.0.30",