-
Notifications
You must be signed in to change notification settings - Fork 1
/
getOrder.ts
98 lines (90 loc) · 1.75 KB
/
getOrder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import {invariant} from '@spinfi/shared';
import {nearErrorMessage, contractIdErrorMessage} from './messages';
import {createView} from '../../utils/createView';
/**
* @category getOrder
*/
export interface Order {
/**
* Order ID
*/
id: string;
/**
* Account ID of the order owner
*/
acc: string;
/**
* Price of a order
*/
price: string;
/**
* Average price of a order
*/
average_price: string;
/**
* Quantity of items in order
*/
quantity: string;
/**
* Remaining quantity
*/
remaining: string;
/**
* Timestamp of the last modification of the order
*/
updated_at: string;
/**
* Timestamp of the order creation
*/
created_at: string;
/**
* The timestamp of the order expiration
*/
expiration_time: string;
/**
* Order type
*/
o_type: 'Ask' | 'Bid';
/**
* Optional non-unique client order ID
*/
client_order_id: number;
}
/**
* @category getOrder
*/
export type GetOrderResponse = Order;
/**
* @category getOrder
*/
export interface GetOrderRequest {
/**
* Account ID
*/
accountId: string;
/**
* Market ID
*/
marketId: number;
/**
* Order ID
*/
orderId: string;
}
const METHOD_NAME = 'get_order';
export const getOrder = createView<GetOrderRequest, GetOrderResponse>(({methodify}) => {
const createMethod = methodify((config) => {
return async (request) => {
invariant(config.near, nearErrorMessage('getOrder'));
invariant(config.contractId, contractIdErrorMessage('getOrder'));
return await config.near.view(config.contractId, METHOD_NAME, {
market_id: request.marketId,
order_id: request.orderId,
account_id: request.accountId,
});
};
});
return {
createMethod,
};
});