@yuants/vendor-gate 0.9.12 → 0.9.13

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.
Files changed (37) hide show
  1. package/dist/api/private-api.js.map +1 -1
  2. package/dist/services/orders/listOrders.js +2 -0
  3. package/dist/services/orders/listOrders.js.map +1 -1
  4. package/dist/services/orders/mapGateOrderToOrderType.js +10 -0
  5. package/dist/services/orders/mapGateOrderToOrderType.js.map +1 -0
  6. package/dist/services/orders/mapOrderTypeToTif.js +12 -0
  7. package/dist/services/orders/mapOrderTypeToTif.js.map +1 -0
  8. package/dist/services/orders/order-type-mapping.test.js +146 -0
  9. package/dist/services/orders/order-type-mapping.test.js.map +1 -0
  10. package/dist/services/orders/submitOrder.js +2 -8
  11. package/dist/services/orders/submitOrder.js.map +1 -1
  12. package/lib/api/private-api.d.ts +1 -0
  13. package/lib/api/private-api.d.ts.map +1 -1
  14. package/lib/api/private-api.js.map +1 -1
  15. package/lib/services/orders/listOrders.d.ts.map +1 -1
  16. package/lib/services/orders/listOrders.js +2 -0
  17. package/lib/services/orders/listOrders.js.map +1 -1
  18. package/lib/services/orders/mapGateOrderToOrderType.d.ts +5 -0
  19. package/lib/services/orders/mapGateOrderToOrderType.d.ts.map +1 -0
  20. package/lib/services/orders/mapGateOrderToOrderType.js +14 -0
  21. package/lib/services/orders/mapGateOrderToOrderType.js.map +1 -0
  22. package/lib/services/orders/mapOrderTypeToTif.d.ts +2 -0
  23. package/lib/services/orders/mapOrderTypeToTif.d.ts.map +1 -0
  24. package/lib/services/orders/mapOrderTypeToTif.js +16 -0
  25. package/lib/services/orders/mapOrderTypeToTif.js.map +1 -0
  26. package/lib/services/orders/order-type-mapping.test.d.ts +2 -0
  27. package/lib/services/orders/order-type-mapping.test.d.ts.map +1 -0
  28. package/lib/services/orders/order-type-mapping.test.js +148 -0
  29. package/lib/services/orders/order-type-mapping.test.js.map +1 -0
  30. package/lib/services/orders/submitOrder.d.ts.map +1 -1
  31. package/lib/services/orders/submitOrder.js +2 -8
  32. package/lib/services/orders/submitOrder.js.map +1 -1
  33. package/package.json +5 -5
  34. package/temp/build/typescript/ts_Eujh_fX2.json +1 -1
  35. package/temp/package-deps.json +10 -7
  36. package/temp/test/jest/haste-map-ac984f375ffe2771b37aa116ca7fe6f5-87fb4bb14df3d29fb61369ce8cbe1fe1-6499ab22de0ac9ce813ded0e96430273 +0 -0
  37. package/temp/test/jest/perf-cache-ac984f375ffe2771b37aa116ca7fe6f5-da39a3ee5e6b4b0d3255bfef95601890 +1 -1
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapGateOrderToOrderType = void 0;
4
+ const mapGateOrderToOrderType = (order) => {
5
+ if (order.tif === 'fok')
6
+ return 'FOK';
7
+ if (order.tif === 'ioc') {
8
+ return Number(order.price) === 0 ? 'MARKET' : 'IOC';
9
+ }
10
+ // Gate does not expose enough stable data here to distinguish gtc as LIMIT vs MAKER.
11
+ return undefined;
12
+ };
13
+ exports.mapGateOrderToOrderType = mapGateOrderToOrderType;
14
+ //# sourceMappingURL=mapGateOrderToOrderType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapGateOrderToOrderType.js","sourceRoot":"","sources":["../../../src/services/orders/mapGateOrderToOrderType.ts"],"names":[],"mappings":";;;AAAO,MAAM,uBAAuB,GAAG,CAAC,KAAuC,EAAE,EAAE;IACjF,IAAI,KAAK,CAAC,GAAG,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,KAAK,CAAC,GAAG,KAAK,KAAK,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;IACtD,CAAC;IACD,qFAAqF;IACrF,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAPW,QAAA,uBAAuB,2BAOlC","sourcesContent":["export const mapGateOrderToOrderType = (order: { tif?: string; price?: string }) => {\n if (order.tif === 'fok') return 'FOK';\n if (order.tif === 'ioc') {\n return Number(order.price) === 0 ? 'MARKET' : 'IOC';\n }\n // Gate does not expose enough stable data here to distinguish gtc as LIMIT vs MAKER.\n return undefined;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const mapOrderTypeToTif: (orderType?: string) => string;
2
+ //# sourceMappingURL=mapOrderTypeToTif.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOrderTypeToTif.d.ts","sourceRoot":"","sources":["../../../src/services/orders/mapOrderTypeToTif.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,GAAI,YAAY,MAAM,KAAG,MAMtD,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapOrderTypeToTif = void 0;
4
+ const mapOrderTypeToTif = (orderType) => {
5
+ if (orderType === 'MARKET')
6
+ return 'ioc';
7
+ if (orderType === 'LIMIT' || orderType === 'MAKER')
8
+ return 'gtc';
9
+ if (orderType === 'IOC')
10
+ return 'ioc';
11
+ if (orderType === 'FOK')
12
+ return 'fok';
13
+ throw new Error(`Unsupported order_type: ${orderType}`);
14
+ };
15
+ exports.mapOrderTypeToTif = mapOrderTypeToTif;
16
+ //# sourceMappingURL=mapOrderTypeToTif.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOrderTypeToTif.js","sourceRoot":"","sources":["../../../src/services/orders/mapOrderTypeToTif.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,CAAC,SAAkB,EAAU,EAAE;IAC9D,IAAI,SAAS,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACzC,IAAI,SAAS,KAAK,OAAO,IAAI,SAAS,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACjE,IAAI,SAAS,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,SAAS,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACtC,MAAM,IAAI,KAAK,CAAC,2BAA2B,SAAS,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC;AANW,QAAA,iBAAiB,qBAM5B","sourcesContent":["export const mapOrderTypeToTif = (orderType?: string): string => {\n if (orderType === 'MARKET') return 'ioc';\n if (orderType === 'LIMIT' || orderType === 'MAKER') return 'gtc';\n if (orderType === 'IOC') return 'ioc';\n if (orderType === 'FOK') return 'fok';\n throw new Error(`Unsupported order_type: ${orderType}`);\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=order-type-mapping.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-type-mapping.test.d.ts","sourceRoot":"","sources":["../../../src/services/orders/order-type-mapping.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mapGateOrderToOrderType_1 = require("./mapGateOrderToOrderType");
4
+ const mapOrderTypeToTif_1 = require("./mapOrderTypeToTif");
5
+ jest.mock('../../api/private-api', () => ({
6
+ getFuturesOrders: jest.fn(async () => []),
7
+ postFutureOrders: jest.fn(async (_credential, _settle, payload) => (Object.assign({ id: 'mock-order-id' }, payload))),
8
+ }));
9
+ const { getFuturesOrders, postFutureOrders } = jest.requireMock('../../api/private-api');
10
+ const { listOrders } = require('./listOrders');
11
+ const { submitOrder } = require('./submitOrder');
12
+ const baseOrder = {
13
+ account_id: 'gate/test/future/USDT',
14
+ product_id: 'GATE/FUTURE/BTC_USDT',
15
+ order_direction: 'OPEN_LONG',
16
+ volume: 1,
17
+ };
18
+ describe('mapOrderTypeToTif', () => {
19
+ test('maps IOC and FOK to Gate tif values', () => {
20
+ expect((0, mapOrderTypeToTif_1.mapOrderTypeToTif)('IOC')).toBe('ioc');
21
+ expect((0, mapOrderTypeToTif_1.mapOrderTypeToTif)('FOK')).toBe('fok');
22
+ });
23
+ });
24
+ describe('mapGateOrderToOrderType', () => {
25
+ test('maps Gate tif and price to Yuan order types', () => {
26
+ expect((0, mapGateOrderToOrderType_1.mapGateOrderToOrderType)({ tif: 'ioc', price: '0' })).toBe('MARKET');
27
+ expect((0, mapGateOrderToOrderType_1.mapGateOrderToOrderType)({ tif: 'ioc', price: '12345' })).toBe('IOC');
28
+ expect((0, mapGateOrderToOrderType_1.mapGateOrderToOrderType)({ tif: 'fok', price: '12345' })).toBe('FOK');
29
+ });
30
+ test('returns undefined when Gate tif cannot be mapped reliably', () => {
31
+ expect((0, mapGateOrderToOrderType_1.mapGateOrderToOrderType)({ tif: 'gtc', price: '12345' })).toBeUndefined();
32
+ expect((0, mapGateOrderToOrderType_1.mapGateOrderToOrderType)({ tif: 'poc', price: '12345' })).toBeUndefined();
33
+ });
34
+ });
35
+ describe('submitOrder order type mapping', () => {
36
+ beforeEach(() => {
37
+ postFutureOrders.mockClear();
38
+ });
39
+ test('forwards IOC with tif=ioc and keeps the real price', async () => {
40
+ await submitOrder({}, Object.assign(Object.assign({}, baseOrder), { order_type: 'IOC', price: 12345 }));
41
+ expect(postFutureOrders).toHaveBeenCalledWith(expect.anything(), 'usdt', expect.objectContaining({
42
+ tif: 'ioc',
43
+ price: '12345',
44
+ }));
45
+ });
46
+ test('forwards FOK with tif=fok and keeps the real price', async () => {
47
+ await submitOrder({}, Object.assign(Object.assign({}, baseOrder), { order_type: 'FOK', price: 12345 }));
48
+ expect(postFutureOrders).toHaveBeenCalledWith(expect.anything(), 'usdt', expect.objectContaining({
49
+ tif: 'fok',
50
+ price: '12345',
51
+ }));
52
+ });
53
+ test('still sends market orders with price=0', async () => {
54
+ await submitOrder({}, Object.assign(Object.assign({}, baseOrder), { order_type: 'MARKET' }));
55
+ expect(postFutureOrders).toHaveBeenCalledWith(expect.anything(), 'usdt', expect.objectContaining({
56
+ tif: 'ioc',
57
+ price: '0',
58
+ }));
59
+ });
60
+ });
61
+ describe('listOrders order type mapping', () => {
62
+ beforeEach(() => {
63
+ getFuturesOrders.mockClear();
64
+ });
65
+ test('adds order_type without changing representative listOrders fields', async () => {
66
+ getFuturesOrders.mockResolvedValueOnce([
67
+ {
68
+ id: 'market-order',
69
+ contract: 'GATE/FUTURE/BTC_USDT',
70
+ size: 1,
71
+ left: 1,
72
+ price: '0',
73
+ fill_price: '0',
74
+ tif: 'ioc',
75
+ is_close: false,
76
+ create_time: 1,
77
+ status: 'open',
78
+ },
79
+ {
80
+ id: 'ioc-order',
81
+ contract: 'GATE/FUTURE/BTC_USDT',
82
+ size: -2,
83
+ left: -1,
84
+ price: '12345',
85
+ fill_price: '12340',
86
+ tif: 'ioc',
87
+ is_close: true,
88
+ create_time: 2,
89
+ status: 'open',
90
+ },
91
+ {
92
+ id: 'fok-order',
93
+ contract: 'GATE/FUTURE/BTC_USDT',
94
+ size: 3,
95
+ left: 0,
96
+ price: '12345',
97
+ fill_price: '12346',
98
+ tif: 'fok',
99
+ is_close: false,
100
+ create_time: 3,
101
+ status: 'open',
102
+ },
103
+ ]);
104
+ const orders = await listOrders({});
105
+ expect(orders).toEqual([
106
+ {
107
+ order_id: 'market-order',
108
+ account_id: '',
109
+ product_id: 'GATE/FUTURE/BTC_USDT',
110
+ order_direction: 'OPEN_LONG',
111
+ volume: 1,
112
+ price: 0,
113
+ traded_price: 0,
114
+ order_status: 'open',
115
+ traded_volume: 0,
116
+ submit_at: 1000,
117
+ order_type: 'MARKET',
118
+ },
119
+ {
120
+ order_id: 'ioc-order',
121
+ account_id: '',
122
+ product_id: 'GATE/FUTURE/BTC_USDT',
123
+ order_direction: 'CLOSE_LONG',
124
+ volume: 2,
125
+ price: 12345,
126
+ traded_price: 12340,
127
+ order_status: 'open',
128
+ traded_volume: 1,
129
+ submit_at: 2000,
130
+ order_type: 'IOC',
131
+ },
132
+ {
133
+ order_id: 'fok-order',
134
+ account_id: '',
135
+ product_id: 'GATE/FUTURE/BTC_USDT',
136
+ order_direction: 'OPEN_LONG',
137
+ volume: 3,
138
+ price: 12345,
139
+ traded_price: 12346,
140
+ order_status: 'open',
141
+ traded_volume: 3,
142
+ submit_at: 3000,
143
+ order_type: 'FOK',
144
+ },
145
+ ]);
146
+ });
147
+ });
148
+ //# sourceMappingURL=order-type-mapping.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-type-mapping.test.js","sourceRoot":"","sources":["../../../src/services/orders/order-type-mapping.test.ts"],"names":[],"mappings":";;AAAA,uEAAoE;AACpE,2DAAwD;AAExD,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,GAAG,EAAE,CAAC,CAAC;IACxC,gBAAgB,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;IACzC,gBAAgB,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,iBACjE,EAAE,EAAE,eAAe,IAChB,OAAO,EACV,CAAC;CACJ,CAAC,CAAC,CAAC;AAEJ,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,uBAAuB,CAGtF,CAAC;AAEF,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,cAAc,CAAkC,CAAC;AAChF,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,eAAe,CAAmC,CAAC;AAEnF,MAAM,SAAS,GAAG;IAChB,UAAU,EAAE,uBAAuB;IACnC,UAAU,EAAE,sBAAsB;IAClC,eAAe,EAAE,WAAoB;IACrC,MAAM,EAAE,CAAC;CACV,CAAC;AAEF,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,IAAI,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC/C,MAAM,CAAC,IAAA,qCAAiB,EAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7C,MAAM,CAAC,IAAA,qCAAiB,EAAC,KAAK,CA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AAU,EAAE,EAAE;gBACd,UAAU,EAAE,sBAAsB;gBAClC,eAAe,EAAE,YAAY;gBAC7B,MAAM,EAAE,CAAC;gBACT,KAAK,EAAE,KAAK;gBACZ,YAAY,EAAE,KAAK;gBACnB,YAAY,EAAE,MAAM;gBACpB,aAAa,EAAE,CAAC;gBAChB,SAAS,EAAE,IAAI;gBACf,UAAU,EAAE,KAAK;aAClB;YACD;gBACE,QAAQ,EAAE,WAAW;gBACrB,UAAU,EAAE,EAAE;gBACd,UAAU,EAAE,sBAAsB;gBAClC,eAAe,EAAE,WAAW;gBAC5B,MAAM,EAAE,CAAC;gBACT,KAAK,EAAE,KAAK;gBACZ,YAAY,EAAE,KAAK;gBACnB,YAAY,EAAE,MAAM;gBACpB,aAAa,EAAE,CAAC;gBAChB,SAAS,EAAE,IAAI;gBACf,UAAU,EAAE,KAAK;aAClB;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { mapGateOrderToOrderType } from './mapGateOrderToOrderType';\nimport { mapOrderTypeToTif } from './mapOrderTypeToTif';\n\njest.mock('../../api/private-api', () => ({\n getFuturesOrders: jest.fn(async () => []),\n postFutureOrders: jest.fn(async (_credential, _settle, payload) => ({\n id: 'mock-order-id',\n ...payload,\n })),\n}));\n\nconst { getFuturesOrders, postFutureOrders } = jest.requireMock('../../api/private-api') as {\n getFuturesOrders: jest.Mock;\n postFutureOrders: jest.Mock;\n};\n\nconst { listOrders } = require('./listOrders') as typeof import('./listOrders');\nconst { submitOrder } = require('./submitOrder') as typeof import('./submitOrder');\n\nconst baseOrder = {\n account_id: 'gate/test/future/USDT',\n product_id: 'GATE/FUTURE/BTC_USDT',\n order_direction: 'OPEN_LONG' as const,\n volume: 1,\n};\n\ndescribe('mapOrderTypeToTif', () => {\n test('maps IOC and FOK to Gate tif values', () => {\n expect(mapOrderTypeToTif('IOC')).toBe('ioc');\n expect(mapOrderTypeToTif('FOK')).toBe('fok');\n });\n});\n\ndescribe('mapGateOrderToOrderType', () => {\n test('maps Gate tif and price to Yuan order types', () => {\n expect(mapGateOrderToOrderType({ tif: 'ioc', price: '0' })).toBe('MARKET');\n expect(mapGateOrderToOrderType({ tif: 'ioc', price: '12345' })).toBe('IOC');\n expect(mapGateOrderToOrderType({ tif: 'fok', price: '12345' })).toBe('FOK');\n });\n\n test('returns undefined when Gate tif cannot be mapped reliably', () => {\n expect(mapGateOrderToOrderType({ tif: 'gtc', price: '12345' })).toBeUndefined();\n expect(mapGateOrderToOrderType({ tif: 'poc', price: '12345' })).toBeUndefined();\n });\n});\n\ndescribe('submitOrder order type mapping', () => {\n beforeEach(() => {\n postFutureOrders.mockClear();\n });\n\n test('forwards IOC with tif=ioc and keeps the real price', async () => {\n await submitOrder({} as never, {\n ...baseOrder,\n order_type: 'IOC',\n price: 12345,\n });\n\n expect(postFutureOrders).toHaveBeenCalledWith(\n expect.anything(),\n 'usdt',\n expect.objectContaining({\n tif: 'ioc',\n price: '12345',\n }),\n );\n });\n\n test('forwards FOK with tif=fok and keeps the real price', async () => {\n await submitOrder({} as never, {\n ...baseOrder,\n order_type: 'FOK',\n price: 12345,\n });\n\n expect(postFutureOrders).toHaveBeenCalledWith(\n expect.anything(),\n 'usdt',\n expect.objectContaining({\n tif: 'fok',\n price: '12345',\n }),\n );\n });\n\n test('still sends market orders with price=0', async () => {\n await submitOrder({} as never, {\n ...baseOrder,\n order_type: 'MARKET',\n });\n\n expect(postFutureOrders).toHaveBeenCalledWith(\n expect.anything(),\n 'usdt',\n expect.objectContaining({\n tif: 'ioc',\n price: '0',\n }),\n );\n });\n});\n\ndescribe('listOrders order type mapping', () => {\n beforeEach(() => {\n getFuturesOrders.mockClear();\n });\n\n test('adds order_type without changing representative listOrders fields', async () => {\n getFuturesOrders.mockResolvedValueOnce([\n {\n id: 'market-order',\n contract: 'GATE/FUTURE/BTC_USDT',\n size: 1,\n left: 1,\n price: '0',\n fill_price: '0',\n tif: 'ioc',\n is_close: false,\n create_time: 1,\n status: 'open',\n },\n {\n id: 'ioc-order',\n contract: 'GATE/FUTURE/BTC_USDT',\n size: -2,\n left: -1,\n price: '12345',\n fill_price: '12340',\n tif: 'ioc',\n is_close: true,\n create_time: 2,\n status: 'open',\n },\n {\n id: 'fok-order',\n contract: 'GATE/FUTURE/BTC_USDT',\n size: 3,\n left: 0,\n price: '12345',\n fill_price: '12346',\n tif: 'fok',\n is_close: false,\n create_time: 3,\n status: 'open',\n },\n ]);\n\n const orders = await listOrders({} as never);\n\n expect(orders).toEqual([\n {\n order_id: 'market-order',\n account_id: '',\n product_id: 'GATE/FUTURE/BTC_USDT',\n order_direction: 'OPEN_LONG',\n volume: 1,\n price: 0,\n traded_price: 0,\n order_status: 'open',\n traded_volume: 0,\n submit_at: 1000,\n order_type: 'MARKET',\n },\n {\n order_id: 'ioc-order',\n account_id: '',\n product_id: 'GATE/FUTURE/BTC_USDT',\n order_direction: 'CLOSE_LONG',\n volume: 2,\n price: 12345,\n traded_price: 12340,\n order_status: 'open',\n traded_volume: 1,\n submit_at: 2000,\n order_type: 'IOC',\n },\n {\n order_id: 'fok-order',\n account_id: '',\n product_id: 'GATE/FUTURE/BTC_USDT',\n order_direction: 'OPEN_LONG',\n volume: 3,\n price: 12345,\n traded_price: 12346,\n order_status: 'open',\n traded_volume: 3,\n submit_at: 3000,\n order_type: 'FOK',\n },\n ]);\n });\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAoB,MAAM,uBAAuB,CAAC;AAsBtE,eAAO,MAAM,WAAW,EAAE,2BAA2B,CAAC,WAAW,CAmChE,CAAC"}
1
+ {"version":3,"file":"submitOrder.d.ts","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAoB,MAAM,uBAAuB,CAAC;AAiBtE,eAAO,MAAM,WAAW,EAAE,2BAA2B,CAAC,WAAW,CAmChE,CAAC"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.submitOrder = void 0;
4
4
  const private_api_1 = require("../../api/private-api");
5
5
  const utils_1 = require("@yuants/utils");
6
+ const mapOrderTypeToTif_1 = require("./mapOrderTypeToTif");
6
7
  const resolveSizeSign = (order_direction) => {
7
8
  switch (order_direction) {
8
9
  case 'OPEN_LONG':
@@ -15,13 +16,6 @@ const resolveSizeSign = (order_direction) => {
15
16
  throw new Error(`Unsupported order_direction: ${order_direction}`);
16
17
  }
17
18
  };
18
- const resolveTif = (order_type) => {
19
- if (order_type === 'MARKET')
20
- return 'ioc';
21
- if (order_type === 'LIMIT' || order_type === 'MAKER')
22
- return 'gtc';
23
- throw new Error(`Unsupported order_type: ${order_type}`);
24
- };
25
19
  const submitOrder = async (credential, order) => {
26
20
  if (!order.product_id) {
27
21
  throw new Error('Missing product_id');
@@ -30,7 +24,7 @@ const submitOrder = async (credential, order) => {
30
24
  throw new Error('Invalid order volume');
31
25
  }
32
26
  const size = order.volume * resolveSizeSign(order.order_direction);
33
- const tif = resolveTif(order.order_type);
27
+ const tif = (0, mapOrderTypeToTif_1.mapOrderTypeToTif)(order.order_type);
34
28
  const reduce_only = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';
35
29
  const price = order.order_type === 'MARKET' ? '0' : order.price !== undefined ? `${order.price}` : undefined;
36
30
  if (price === undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,uDAAsE;AACtE,yCAA2C;AAE3C,MAAM,eAAe,GAAG,CAAC,eAAwB,EAAU,EAAE;IAC3D,QAAQ,eAAe,E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AAG,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACjG,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IACD,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACxD,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,MAAM,IAAA,8BAAgB,EAAC,UAAU,EAAE,MAAM,EAAE;YACrD,QAAQ;YACR,IAAI;YACJ,KAAK;YACL,GAAG;YACH,WAAW;SACZ,CAAC,CAAC;QAEH,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;YACd,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClF,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE;SACtB,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAC9C,CAAC,CAAC;AAnCW,QAAA,WAAW,eAmCtB","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { ICredential, postFutureOrders } from '../../api/private-api';\nimport { decodePath } from '@yuants/utils';\n\nconst resolveSizeSign = (order_direction?: string): number => {\n switch (order_direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 1;\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return -1;\n default:\n throw new Error(`Unsupported order_direction: ${order_direction}`);\n }\n};\n\nconst resolveTif = (order_type?: string): string => {\n if (order_type === 'MARKET') return 'ioc';\n if (order_type === 'LIMIT' || order_type === 'MAKER') return 'gtc';\n throw new Error(`Unsupported order_type: ${order_type}`);\n};\n\nexport const submitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n if (!order.product_id) {\n throw new Error('Missing product_id');\n }\n if (!order.volume || order.volume <= 0) {\n throw new Error('Invalid order volume');\n }\n\n const size = order.volume * resolveSizeSign(order.order_direction);\n const tif = resolveTif(order.order_type);\n const reduce_only = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';\n const price =\n order.order_type === 'MARKET' ? '0' : order.price !== undefined ? `${order.price}` : undefined;\n if (price === undefined) {\n throw new Error('Limit/Maker order requires price');\n }\n const [, TYPE, contract] = decodePath(order.product_id);\n if (TYPE === 'FUTURE') {\n const res = await postFutureOrders(credential, 'usdt', {\n contract,\n size,\n price,\n tif,\n reduce_only,\n });\n\n if (res.label) {\n const detail = [res.label, res.message, res.detail].filter((v) => !!v).join(': ');\n throw new Error(detail);\n }\n return {\n order_id: `${res.id}`,\n };\n }\n throw new Error('Product type not support');\n};\n"]}
1
+ {"version":3,"file":"submitOrder.js","sourceRoot":"","sources":["../../../src/services/orders/submitOrder.ts"],"names":[],"mappings":";;;AACA,uDAAsE;AACtE,yCAA2C;AAC3C,2DAAwD;AAExD,MAAM,eAAe,GAAG,CAAC,eAAwB,EAAU,EAAE;IAC3D,QAAQ,eAAe,EAAE,CAAC;QACxB,KAAK,WAAW,CAAC;QACjB,KAAK,aAAa;YAChB,OAAO,CAAC,CAAC;QACX,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,CAAC,CAAC,CAAC;QACZ;YACE,MAAM,IAAI,KAAK,CAAC,gCAAgC,eAAe,EAAE,CAAC,CAAC;IACvE,CAAC;AACH,CAAC,CAAC;AAEK,MAAM,WAAW,GAA6C,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAA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C,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClF,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,GAAG,GAAG,CAAC,EAAE,EAAE;SACtB,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAC9C,CAAC,CAAC;AAnCW,QAAA,WAAW,eAmCtB","sourcesContent":["import { IActionHandlerOfSubmitOrder } from '@yuants/data-order';\nimport { ICredential, postFutureOrders } from '../../api/private-api';\nimport { decodePath } from '@yuants/utils';\nimport { mapOrderTypeToTif } from './mapOrderTypeToTif';\n\nconst resolveSizeSign = (order_direction?: string): number => {\n switch (order_direction) {\n case 'OPEN_LONG':\n case 'CLOSE_SHORT':\n return 1;\n case 'OPEN_SHORT':\n case 'CLOSE_LONG':\n return -1;\n default:\n throw new Error(`Unsupported order_direction: ${order_direction}`);\n }\n};\n\nexport const submitOrder: IActionHandlerOfSubmitOrder<ICredential> = async (credential, order) => {\n if (!order.product_id) {\n throw new Error('Missing product_id');\n }\n if (!order.volume || order.volume <= 0) {\n throw new Error('Invalid order volume');\n }\n\n const size = order.volume * resolveSizeSign(order.order_direction);\n const tif = mapOrderTypeToTif(order.order_type);\n const reduce_only = order.order_direction === 'CLOSE_LONG' || order.order_direction === 'CLOSE_SHORT';\n const price =\n order.order_type === 'MARKET' ? '0' : order.price !== undefined ? `${order.price}` : undefined;\n if (price === undefined) {\n throw new Error('Limit/Maker order requires price');\n }\n const [, TYPE, contract] = decodePath(order.product_id);\n if (TYPE === 'FUTURE') {\n const res = await postFutureOrders(credential, 'usdt', {\n contract,\n size,\n price,\n tif,\n reduce_only,\n });\n\n if (res.label) {\n const detail = [res.label, res.message, res.detail].filter((v) => !!v).join(': ');\n throw new Error(detail);\n }\n return {\n order_id: `${res.id}`,\n };\n }\n throw new Error('Product type not support');\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/vendor-gate",
3
- "version": "0.9.12",
3
+ "version": "0.9.13",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
6
  "lib",
@@ -14,16 +14,16 @@
14
14
  "@yuants/transfer": "0.2.52",
15
15
  "@yuants/data-account": "0.11.12",
16
16
  "@yuants/data-order": "0.7.13",
17
- "@yuants/data-ohlc": "0.6.8",
17
+ "@yuants/data-trade": "0.1.38",
18
18
  "@yuants/sql": "0.9.43",
19
+ "@yuants/data-ohlc": "0.6.8",
19
20
  "@yuants/data-product": "0.5.13",
20
21
  "@yuants/utils": "0.19.7",
21
- "@yuants/data-trade": "0.1.38",
22
22
  "@yuants/http-services": "0.5.3",
23
23
  "@yuants/data-interest-rate": "0.2.13",
24
24
  "@yuants/exchange": "0.8.23",
25
- "@yuants/data-quote": "0.4.12",
26
- "@yuants/data-series": "0.3.65"
25
+ "@yuants/data-series": "0.3.65",
26
+ "@yuants/data-quote": "0.4.12"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@microsoft/api-extractor": "~7.55.2",