pmxtjs 2.19.5 → 2.20.0
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.
- package/dist/esm/generated/src/apis/DefaultApi.d.ts +53 -1
- package/dist/esm/generated/src/apis/DefaultApi.js +83 -1
- package/dist/esm/generated/src/models/FetchBalanceRequest.d.ts +2 -2
- package/dist/esm/generated/src/models/FetchPositionsRequest.d.ts +2 -2
- package/dist/esm/generated/src/models/UnwatchAddressRequest.d.ts +39 -0
- package/dist/esm/generated/src/models/UnwatchAddressRequest.js +46 -0
- package/dist/esm/generated/src/models/WatchAddress200Response.d.ts +45 -0
- package/dist/esm/generated/src/models/WatchAddress200Response.js +46 -0
- package/dist/esm/generated/src/models/WatchAddressRequest.d.ts +40 -0
- package/dist/esm/generated/src/models/WatchAddressRequest.js +47 -0
- package/dist/esm/generated/src/models/WatchAddressRequestArgsInner.d.ts +21 -0
- package/dist/esm/generated/src/models/WatchAddressRequestArgsInner.js +37 -0
- package/dist/esm/generated/src/models/index.d.ts +4 -0
- package/dist/esm/generated/src/models/index.js +4 -0
- package/dist/esm/pmxt/args.d.ts +1 -0
- package/dist/esm/pmxt/args.js +3 -0
- package/dist/esm/pmxt/client.d.ts +94 -5
- package/dist/esm/pmxt/client.js +217 -33
- package/dist/esm/pmxt/models.d.ts +45 -0
- package/dist/generated/src/apis/DefaultApi.d.ts +53 -1
- package/dist/generated/src/apis/DefaultApi.js +83 -1
- package/dist/generated/src/models/FetchBalanceRequest.d.ts +2 -2
- package/dist/generated/src/models/FetchPositionsRequest.d.ts +2 -2
- package/dist/generated/src/models/UnwatchAddressRequest.d.ts +39 -0
- package/dist/generated/src/models/UnwatchAddressRequest.js +53 -0
- package/dist/generated/src/models/WatchAddress200Response.d.ts +45 -0
- package/dist/generated/src/models/WatchAddress200Response.js +53 -0
- package/dist/generated/src/models/WatchAddressRequest.d.ts +40 -0
- package/dist/generated/src/models/WatchAddressRequest.js +54 -0
- package/dist/generated/src/models/WatchAddressRequestArgsInner.d.ts +21 -0
- package/dist/generated/src/models/WatchAddressRequestArgsInner.js +43 -0
- package/dist/generated/src/models/index.d.ts +4 -0
- package/dist/generated/src/models/index.js +4 -0
- package/dist/pmxt/args.d.ts +1 -0
- package/dist/pmxt/args.js +6 -0
- package/dist/pmxt/client.d.ts +94 -5
- package/dist/pmxt/client.js +216 -32
- package/dist/pmxt/models.d.ts +45 -0
- package/generated/.openapi-generator/FILES +8 -0
- package/generated/docs/DefaultApi.md +142 -0
- package/generated/docs/FetchBalanceRequest.md +1 -1
- package/generated/docs/FetchPositionsRequest.md +1 -1
- package/generated/docs/UnwatchAddressRequest.md +36 -0
- package/generated/docs/WatchAddress200Response.md +38 -0
- package/generated/docs/WatchAddressRequest.md +36 -0
- package/generated/docs/WatchAddressRequestArgsInner.md +32 -0
- package/generated/package.json +1 -1
- package/generated/src/apis/DefaultApi.ts +127 -0
- package/generated/src/models/FetchBalanceRequest.ts +2 -2
- package/generated/src/models/FetchPositionsRequest.ts +2 -2
- package/generated/src/models/UnwatchAddressRequest.ts +82 -0
- package/generated/src/models/WatchAddress200Response.ts +89 -0
- package/generated/src/models/WatchAddressRequest.ts +89 -0
- package/generated/src/models/WatchAddressRequestArgsInner.ts +49 -0
- package/generated/src/models/index.ts +4 -0
- package/package.json +2 -2
- package/pmxt/args.ts +3 -0
- package/pmxt/client.ts +263 -39
- package/pmxt/models.ts +55 -1
package/pmxt/client.ts
CHANGED
|
@@ -6,37 +6,43 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
|
-
DefaultApi,
|
|
10
9
|
Configuration,
|
|
11
|
-
FetchOHLCVRequest,
|
|
12
|
-
FetchTradesRequest,
|
|
13
10
|
CreateOrderRequest,
|
|
11
|
+
DefaultApi,
|
|
14
12
|
ExchangeCredentials,
|
|
13
|
+
FetchOHLCVRequest,
|
|
14
|
+
FetchTradesRequest,
|
|
15
|
+
BuildOrderRequest,
|
|
16
|
+
SubmitOrderRequest,
|
|
15
17
|
} from "../generated/src/index.js";
|
|
16
18
|
|
|
17
19
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
Balance,
|
|
21
|
+
BuiltOrder,
|
|
22
|
+
CreateOrderParams,
|
|
23
|
+
EventFilterCriteria,
|
|
24
|
+
EventFilterFunction,
|
|
25
|
+
ExecutionPriceResult,
|
|
26
|
+
MarketFilterCriteria,
|
|
27
|
+
MarketFilterFunction,
|
|
20
28
|
MarketList,
|
|
21
|
-
|
|
29
|
+
MarketOutcome,
|
|
30
|
+
Order,
|
|
22
31
|
OrderBook,
|
|
23
32
|
OrderLevel,
|
|
24
|
-
|
|
25
|
-
UserTrade,
|
|
26
|
-
Order,
|
|
33
|
+
PaginatedMarketsResult,
|
|
27
34
|
Position,
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
PriceCandle,
|
|
36
|
+
SubscribedAddressSnapshot,
|
|
37
|
+
SubscriptionOption,
|
|
38
|
+
Trade,
|
|
30
39
|
UnifiedEvent,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
MarketFilterCriteria,
|
|
34
|
-
MarketFilterFunction,
|
|
35
|
-
EventFilterCriteria,
|
|
36
|
-
EventFilterFunction,
|
|
40
|
+
UnifiedMarket,
|
|
41
|
+
UserTrade,
|
|
37
42
|
} from "./models.js";
|
|
38
43
|
|
|
39
44
|
import { ServerManager } from "./server-manager.js";
|
|
45
|
+
import { buildArgsWithOptionalOptions } from "./args.js";
|
|
40
46
|
|
|
41
47
|
// Converter functions
|
|
42
48
|
function convertMarket(raw: any): UnifiedMarket {
|
|
@@ -190,6 +196,22 @@ function convertEvent(raw: any): UnifiedEvent {
|
|
|
190
196
|
return event;
|
|
191
197
|
}
|
|
192
198
|
|
|
199
|
+
|
|
200
|
+
function convertSubscriptionSnapshot(raw: any): SubscribedAddressSnapshot {
|
|
201
|
+
const trades = (raw.trades?? []).map(convertTrade);
|
|
202
|
+
const balances = (raw.balances?? []).map(convertBalance);
|
|
203
|
+
const positions = (raw.positions?? []).map(convertPosition);
|
|
204
|
+
|
|
205
|
+
const snapShot: SubscribedAddressSnapshot = {
|
|
206
|
+
address: raw.address,
|
|
207
|
+
trades,
|
|
208
|
+
balances,
|
|
209
|
+
positions,
|
|
210
|
+
timestamp: raw.timestamp,
|
|
211
|
+
};
|
|
212
|
+
return snapShot;
|
|
213
|
+
}
|
|
214
|
+
|
|
193
215
|
/**
|
|
194
216
|
* Base exchange client options.
|
|
195
217
|
*/
|
|
@@ -384,8 +406,7 @@ export abstract class Exchange {
|
|
|
384
406
|
async fetchMarkets(params?: any): Promise<UnifiedMarket[]> {
|
|
385
407
|
await this.initPromise;
|
|
386
408
|
try {
|
|
387
|
-
const args
|
|
388
|
-
if (params !== undefined) args.push(params);
|
|
409
|
+
const args = buildArgsWithOptionalOptions(params);
|
|
389
410
|
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarkets`, {
|
|
390
411
|
method: 'POST',
|
|
391
412
|
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
@@ -406,8 +427,7 @@ export abstract class Exchange {
|
|
|
406
427
|
async fetchMarketsPaginated(params?: any): Promise<PaginatedMarketsResult> {
|
|
407
428
|
await this.initPromise;
|
|
408
429
|
try {
|
|
409
|
-
const args
|
|
410
|
-
if (params !== undefined) args.push(params);
|
|
430
|
+
const args = buildArgsWithOptionalOptions(params);
|
|
411
431
|
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarketsPaginated`, {
|
|
412
432
|
method: 'POST',
|
|
413
433
|
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
@@ -432,8 +452,7 @@ export abstract class Exchange {
|
|
|
432
452
|
async fetchEvents(params?: any): Promise<UnifiedEvent[]> {
|
|
433
453
|
await this.initPromise;
|
|
434
454
|
try {
|
|
435
|
-
const args
|
|
436
|
-
if (params !== undefined) args.push(params);
|
|
455
|
+
const args = buildArgsWithOptionalOptions(params);
|
|
437
456
|
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvents`, {
|
|
438
457
|
method: 'POST',
|
|
439
458
|
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
@@ -454,8 +473,7 @@ export abstract class Exchange {
|
|
|
454
473
|
async fetchMarket(params?: any): Promise<UnifiedMarket> {
|
|
455
474
|
await this.initPromise;
|
|
456
475
|
try {
|
|
457
|
-
const args
|
|
458
|
-
if (params !== undefined) args.push(params);
|
|
476
|
+
const args = buildArgsWithOptionalOptions(params);
|
|
459
477
|
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarket`, {
|
|
460
478
|
method: 'POST',
|
|
461
479
|
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
@@ -476,8 +494,7 @@ export abstract class Exchange {
|
|
|
476
494
|
async fetchEvent(params?: any): Promise<UnifiedEvent> {
|
|
477
495
|
await this.initPromise;
|
|
478
496
|
try {
|
|
479
|
-
const args
|
|
480
|
-
if (params !== undefined) args.push(params);
|
|
497
|
+
const args = buildArgsWithOptionalOptions(params);
|
|
481
498
|
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvent`, {
|
|
482
499
|
method: 'POST',
|
|
483
500
|
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
@@ -517,6 +534,7 @@ export abstract class Exchange {
|
|
|
517
534
|
}
|
|
518
535
|
}
|
|
519
536
|
|
|
537
|
+
|
|
520
538
|
async cancelOrder(orderId: string): Promise<Order> {
|
|
521
539
|
await this.initPromise;
|
|
522
540
|
try {
|
|
@@ -564,8 +582,7 @@ export abstract class Exchange {
|
|
|
564
582
|
async fetchOpenOrders(marketId?: string): Promise<Order[]> {
|
|
565
583
|
await this.initPromise;
|
|
566
584
|
try {
|
|
567
|
-
const args
|
|
568
|
-
if (marketId !== undefined) args.push(marketId);
|
|
585
|
+
const args = buildArgsWithOptionalOptions(marketId);
|
|
569
586
|
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOpenOrders`, {
|
|
570
587
|
method: 'POST',
|
|
571
588
|
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
@@ -586,8 +603,7 @@ export abstract class Exchange {
|
|
|
586
603
|
async fetchMyTrades(params?: any): Promise<UserTrade[]> {
|
|
587
604
|
await this.initPromise;
|
|
588
605
|
try {
|
|
589
|
-
const args
|
|
590
|
-
if (params !== undefined) args.push(params);
|
|
606
|
+
const args = buildArgsWithOptionalOptions(params);
|
|
591
607
|
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMyTrades`, {
|
|
592
608
|
method: 'POST',
|
|
593
609
|
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
@@ -608,8 +624,7 @@ export abstract class Exchange {
|
|
|
608
624
|
async fetchClosedOrders(params?: any): Promise<Order[]> {
|
|
609
625
|
await this.initPromise;
|
|
610
626
|
try {
|
|
611
|
-
const args
|
|
612
|
-
if (params !== undefined) args.push(params);
|
|
627
|
+
const args = buildArgsWithOptionalOptions(params);
|
|
613
628
|
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchClosedOrders`, {
|
|
614
629
|
method: 'POST',
|
|
615
630
|
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
@@ -630,8 +645,7 @@ export abstract class Exchange {
|
|
|
630
645
|
async fetchAllOrders(params?: any): Promise<Order[]> {
|
|
631
646
|
await this.initPromise;
|
|
632
647
|
try {
|
|
633
|
-
const args
|
|
634
|
-
if (params !== undefined) args.push(params);
|
|
648
|
+
const args = buildArgsWithOptionalOptions(params);
|
|
635
649
|
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchAllOrders`, {
|
|
636
650
|
method: 'POST',
|
|
637
651
|
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
@@ -649,10 +663,10 @@ export abstract class Exchange {
|
|
|
649
663
|
}
|
|
650
664
|
}
|
|
651
665
|
|
|
652
|
-
async fetchPositions(): Promise<Position[]> {
|
|
666
|
+
async fetchPositions(address?: string): Promise<Position[]> {
|
|
653
667
|
await this.initPromise;
|
|
654
668
|
try {
|
|
655
|
-
const args: any[] = [];
|
|
669
|
+
const args: any[] = address? [address] : [];
|
|
656
670
|
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchPositions`, {
|
|
657
671
|
method: 'POST',
|
|
658
672
|
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
@@ -670,10 +684,10 @@ export abstract class Exchange {
|
|
|
670
684
|
}
|
|
671
685
|
}
|
|
672
686
|
|
|
673
|
-
async fetchBalance(): Promise<Balance[]> {
|
|
687
|
+
async fetchBalance(address?: string): Promise<Balance[]> {
|
|
674
688
|
await this.initPromise;
|
|
675
689
|
try {
|
|
676
|
-
const args: any[] = [];
|
|
690
|
+
const args: any[] = address? [address] : [];
|
|
677
691
|
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchBalance`, {
|
|
678
692
|
method: 'POST',
|
|
679
693
|
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
@@ -855,6 +869,7 @@ export abstract class Exchange {
|
|
|
855
869
|
* Call repeatedly in a loop to stream updates (CCXT Pro pattern).
|
|
856
870
|
*
|
|
857
871
|
* @param outcomeId - Outcome ID to watch
|
|
872
|
+
* @param address - Public wallet to be watched
|
|
858
873
|
* @param since - Optional timestamp to filter trades from
|
|
859
874
|
* @param limit - Optional limit for number of trades
|
|
860
875
|
* @returns Next trade update(s)
|
|
@@ -872,12 +887,16 @@ export abstract class Exchange {
|
|
|
872
887
|
*/
|
|
873
888
|
async watchTrades(
|
|
874
889
|
outcomeId: string,
|
|
890
|
+
address?: string,
|
|
875
891
|
since?: number,
|
|
876
892
|
limit?: number
|
|
877
893
|
): Promise<Trade[]> {
|
|
878
894
|
await this.initPromise;
|
|
879
895
|
try {
|
|
880
896
|
const args: any[] = [outcomeId];
|
|
897
|
+
if (address !== undefined) {
|
|
898
|
+
args.push(address);
|
|
899
|
+
}
|
|
881
900
|
if (since !== undefined) {
|
|
882
901
|
args.push(since);
|
|
883
902
|
}
|
|
@@ -902,8 +921,213 @@ export abstract class Exchange {
|
|
|
902
921
|
}
|
|
903
922
|
}
|
|
904
923
|
|
|
924
|
+
/**
|
|
925
|
+
* Watch real-time updates of a public wallet via WebSocket.
|
|
926
|
+
*
|
|
927
|
+
* Returns a promise that resolves with the next update(s).
|
|
928
|
+
* Call repeatedly in a loop to stream updates (CCXT Pro pattern).
|
|
929
|
+
*
|
|
930
|
+
* @param address - Public wallet to be watched
|
|
931
|
+
* @param types - Subscription options including 'trades', 'positions', and 'balances'
|
|
932
|
+
* @returns Next update(s)
|
|
933
|
+
*
|
|
934
|
+
* @example
|
|
935
|
+
* ```typescript
|
|
936
|
+
* // Stream updates of a public wallet address
|
|
937
|
+
* while (true) {
|
|
938
|
+
* const snapshots = await exchange.watchAddress(address, types);
|
|
939
|
+
* for (const snapshot of snapshots) {
|
|
940
|
+
* console.log(`Trade: ${snapshot.trades}`);
|
|
941
|
+
* }
|
|
942
|
+
* }
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
945
|
+
async watchAddress(
|
|
946
|
+
address: string,
|
|
947
|
+
types?: SubscriptionOption[],
|
|
948
|
+
): Promise<SubscribedAddressSnapshot> {
|
|
949
|
+
await this.initPromise;
|
|
950
|
+
try {
|
|
951
|
+
const args: any[] = [address];
|
|
952
|
+
if (types !== undefined) {
|
|
953
|
+
args.push(types);
|
|
954
|
+
}
|
|
955
|
+
const requestBody: any = {
|
|
956
|
+
args,
|
|
957
|
+
credentials: this.getCredentials()
|
|
958
|
+
};
|
|
959
|
+
|
|
960
|
+
const response = await this.api.watchAddress({
|
|
961
|
+
exchange: this.exchangeName as any,
|
|
962
|
+
watchAddressRequest: requestBody,
|
|
963
|
+
});
|
|
964
|
+
|
|
965
|
+
const data = this.handleResponse(response);
|
|
966
|
+
return convertSubscriptionSnapshot(data);
|
|
967
|
+
} catch (error) {
|
|
968
|
+
throw new Error(`Failed to watch address: ${error}`);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* Stop watching a previously registered wallet address and release its resource updates.
|
|
974
|
+
*
|
|
975
|
+
* @param address - Public wallet to be watched
|
|
976
|
+
* @returns
|
|
977
|
+
*/
|
|
978
|
+
async unwatchAddress(
|
|
979
|
+
address: string,
|
|
980
|
+
): Promise<Trade[]> {
|
|
981
|
+
await this.initPromise;
|
|
982
|
+
try {
|
|
983
|
+
const args: any[] = [address];
|
|
984
|
+
|
|
985
|
+
const requestBody: any = {
|
|
986
|
+
args,
|
|
987
|
+
credentials: this.getCredentials()
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
const response = await this.api.unwatchAddress({
|
|
991
|
+
exchange: this.exchangeName as any,
|
|
992
|
+
unwatchAddressRequest: requestBody,
|
|
993
|
+
});
|
|
994
|
+
|
|
995
|
+
return this.handleResponse(response);
|
|
996
|
+
} catch (error) {
|
|
997
|
+
throw new Error(`Failed to unwatch address: ${error}`);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
905
1001
|
// Trading Methods (require authentication)
|
|
906
1002
|
|
|
1003
|
+
/**
|
|
1004
|
+
* Build an order payload without submitting it to the exchange.
|
|
1005
|
+
* Returns the exchange-native signed order or transaction payload for
|
|
1006
|
+
* inspection, forwarding through a middleware layer, or deferred
|
|
1007
|
+
* submission via {@link submitOrder}.
|
|
1008
|
+
*
|
|
1009
|
+
* You can specify the market either with explicit marketId/outcomeId,
|
|
1010
|
+
* or by passing an outcome object directly (e.g., market.yes).
|
|
1011
|
+
*
|
|
1012
|
+
* @param params - Order parameters (same as createOrder)
|
|
1013
|
+
* @returns A BuiltOrder containing the exchange-native payload
|
|
1014
|
+
*
|
|
1015
|
+
* @example
|
|
1016
|
+
* ```typescript
|
|
1017
|
+
* // Build, inspect, then submit:
|
|
1018
|
+
* const built = await exchange.buildOrder({
|
|
1019
|
+
* marketId: "663583",
|
|
1020
|
+
* outcomeId: "10991849...",
|
|
1021
|
+
* side: "buy",
|
|
1022
|
+
* type: "limit",
|
|
1023
|
+
* amount: 10,
|
|
1024
|
+
* price: 0.55
|
|
1025
|
+
* });
|
|
1026
|
+
*
|
|
1027
|
+
* console.log(built.signedOrder); // inspect before submitting
|
|
1028
|
+
* const order = await exchange.submitOrder(built);
|
|
1029
|
+
*
|
|
1030
|
+
* // Using outcome shorthand:
|
|
1031
|
+
* const built2 = await exchange.buildOrder({
|
|
1032
|
+
* outcome: market.yes,
|
|
1033
|
+
* side: "buy",
|
|
1034
|
+
* type: "market",
|
|
1035
|
+
* amount: 10
|
|
1036
|
+
* });
|
|
1037
|
+
* ```
|
|
1038
|
+
*/
|
|
1039
|
+
async buildOrder(params: CreateOrderParams & { outcome?: MarketOutcome }): Promise<BuiltOrder> {
|
|
1040
|
+
await this.initPromise;
|
|
1041
|
+
try {
|
|
1042
|
+
let marketId = params.marketId;
|
|
1043
|
+
let outcomeId = params.outcomeId;
|
|
1044
|
+
|
|
1045
|
+
if (params.outcome) {
|
|
1046
|
+
if (marketId !== undefined || outcomeId !== undefined) {
|
|
1047
|
+
throw new Error(
|
|
1048
|
+
"Cannot specify both 'outcome' and 'marketId'/'outcomeId'. Use one or the other."
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
const outcome: MarketOutcome = params.outcome;
|
|
1052
|
+
if (!outcome.marketId) {
|
|
1053
|
+
throw new Error(
|
|
1054
|
+
"outcome.marketId is not set. Ensure the outcome comes from a fetched market."
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
marketId = outcome.marketId;
|
|
1058
|
+
outcomeId = outcome.outcomeId;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
const paramsDict: any = {
|
|
1062
|
+
marketId,
|
|
1063
|
+
outcomeId,
|
|
1064
|
+
side: params.side,
|
|
1065
|
+
type: params.type,
|
|
1066
|
+
amount: params.amount,
|
|
1067
|
+
};
|
|
1068
|
+
if (params.price !== undefined) {
|
|
1069
|
+
paramsDict.price = params.price;
|
|
1070
|
+
}
|
|
1071
|
+
if (params.fee !== undefined) {
|
|
1072
|
+
paramsDict.fee = params.fee;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
const requestBody: BuildOrderRequest = {
|
|
1076
|
+
args: [paramsDict],
|
|
1077
|
+
credentials: this.getCredentials()
|
|
1078
|
+
};
|
|
1079
|
+
|
|
1080
|
+
const response = await this.api.buildOrder({
|
|
1081
|
+
exchange: this.exchangeName as any,
|
|
1082
|
+
buildOrderRequest: requestBody,
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
const data = this.handleResponse(response);
|
|
1086
|
+
return data as BuiltOrder;
|
|
1087
|
+
} catch (error) {
|
|
1088
|
+
throw new Error(`Failed to build order: ${error}`);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
/**
|
|
1093
|
+
* Submit a pre-built order returned by {@link buildOrder}.
|
|
1094
|
+
*
|
|
1095
|
+
* @param built - The BuiltOrder payload from buildOrder()
|
|
1096
|
+
* @returns The submitted order
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* ```typescript
|
|
1100
|
+
* const built = await exchange.buildOrder({
|
|
1101
|
+
* outcome: market.yes,
|
|
1102
|
+
* side: "buy",
|
|
1103
|
+
* type: "limit",
|
|
1104
|
+
* amount: 10,
|
|
1105
|
+
* price: 0.55
|
|
1106
|
+
* });
|
|
1107
|
+
* const order = await exchange.submitOrder(built);
|
|
1108
|
+
* console.log(order.id, order.status);
|
|
1109
|
+
* ```
|
|
1110
|
+
*/
|
|
1111
|
+
async submitOrder(built: BuiltOrder): Promise<Order> {
|
|
1112
|
+
await this.initPromise;
|
|
1113
|
+
try {
|
|
1114
|
+
const requestBody: SubmitOrderRequest = {
|
|
1115
|
+
args: [built as any],
|
|
1116
|
+
credentials: this.getCredentials()
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
const response = await this.api.submitOrder({
|
|
1120
|
+
exchange: this.exchangeName as any,
|
|
1121
|
+
submitOrderRequest: requestBody,
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
const data = this.handleResponse(response);
|
|
1125
|
+
return convertOrder(data);
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
throw new Error(`Failed to submit order: ${error}`);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
|
|
907
1131
|
/**
|
|
908
1132
|
* Create a new order.
|
|
909
1133
|
*
|
package/pmxt/models.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Data models for PMXT TypeScript SDK.
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* These are clean TypeScript interfaces that provide a user-friendly API.
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -368,6 +368,29 @@ export interface CreateOrderParams {
|
|
|
368
368
|
/** Optional fee rate (e.g., 1000 for 0.1%) */
|
|
369
369
|
fee?: number;
|
|
370
370
|
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* An order payload built but not yet submitted to the exchange.
|
|
374
|
+
*/
|
|
375
|
+
export interface BuiltOrder {
|
|
376
|
+
/** The exchange name this order was built for. */
|
|
377
|
+
exchange: string;
|
|
378
|
+
/** The original params used to build this order. */
|
|
379
|
+
params: CreateOrderParams;
|
|
380
|
+
/** For CLOB exchanges (Polymarket): the EIP-712 signed order. */
|
|
381
|
+
signedOrder?: Record<string, unknown>;
|
|
382
|
+
/** For on-chain AMM exchanges: the EVM transaction payload. */
|
|
383
|
+
tx?: {
|
|
384
|
+
to: string;
|
|
385
|
+
data: string;
|
|
386
|
+
value: string;
|
|
387
|
+
chainId: number;
|
|
388
|
+
};
|
|
389
|
+
/** The raw, exchange-native payload. Always present. */
|
|
390
|
+
raw: unknown;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
|
|
371
394
|
/**
|
|
372
395
|
* A list of UnifiedMarket objects with a convenience match() method.
|
|
373
396
|
* Extends Array so all standard array operations work unchanged.
|
|
@@ -545,3 +568,34 @@ export interface EventFilterCriteria {
|
|
|
545
568
|
* Function type for custom event filtering logic.
|
|
546
569
|
*/
|
|
547
570
|
export type EventFilterFunction = (event: UnifiedEvent) => boolean;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Subscription options.
|
|
574
|
+
*/
|
|
575
|
+
export type SubscriptionOption = 'trades' | 'positions' | 'balances';
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Subscription snapshot of a watched public wallet address.
|
|
579
|
+
*/
|
|
580
|
+
export interface SubscribedAddressSnapshot {
|
|
581
|
+
/** The wallet address being watched */
|
|
582
|
+
address: string;
|
|
583
|
+
|
|
584
|
+
/** Recent trades for this address
|
|
585
|
+
* (if the above SubscriptionOption 'trades' option was requested)
|
|
586
|
+
*/
|
|
587
|
+
trades?: Trade[];
|
|
588
|
+
|
|
589
|
+
/** Current open positions for this address
|
|
590
|
+
* (if the above SubscriptionOption 'positions' option was requested)
|
|
591
|
+
*/
|
|
592
|
+
positions?: Position[];
|
|
593
|
+
|
|
594
|
+
/** Current balances for this address
|
|
595
|
+
* (if the above SubscriptionOption 'balances' option was requested)
|
|
596
|
+
*/
|
|
597
|
+
balances?: Balance[];
|
|
598
|
+
|
|
599
|
+
/** Unix timestamp (ms) of this snapshot */
|
|
600
|
+
timestamp: number;
|
|
601
|
+
}
|