@icgio/icg-exchanges-wrapper 1.14.254 → 1.14.255
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/README.md +129 -1
- package/middleware/account.js +3 -3
- package/middleware/orders.js +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1,129 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ICG Exchanges Wrapper
|
|
2
|
+
|
|
3
|
+
High-level wrapper functions for the ICG exchanges package, providing simplified interfaces for common trading operations across multiple exchanges.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Multi-Exchange Operations**: Execute operations across multiple exchanges in parallel
|
|
8
|
+
- **Unified Data Format**: Consistent response format regardless of exchange
|
|
9
|
+
- **Order Management Middleware**: Advanced order placement with retries and validation
|
|
10
|
+
- **WebSocket Data Client**: Real-time log streaming support
|
|
11
|
+
- **Rate Data Aggregation**: Combine orderbook data from multiple sources
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @icgio/icg-exchanges-wrapper
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Functions Module
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
const { functions } = require('@icgio/icg-exchanges-wrapper')
|
|
25
|
+
|
|
26
|
+
// Get rates (orderbook) from multiple exchanges
|
|
27
|
+
const rates = await functions.get_exchanges_rates(exchanges, pairs)
|
|
28
|
+
|
|
29
|
+
// Get balances from multiple exchanges
|
|
30
|
+
const balances = await functions.get_exchanges_balance(exchanges)
|
|
31
|
+
|
|
32
|
+
// Get trade history
|
|
33
|
+
const trades = await functions.get_exchanges_trades(exchanges, pairs)
|
|
34
|
+
|
|
35
|
+
// Get open orders
|
|
36
|
+
const open_orders = await functions.get_exchanges_open_orders(exchanges, pairs)
|
|
37
|
+
|
|
38
|
+
// Get deposit history
|
|
39
|
+
const deposits = await functions.get_exchanges_deposits(exchanges)
|
|
40
|
+
|
|
41
|
+
// Get withdrawal history
|
|
42
|
+
const withdrawals = await functions.get_exchanges_withdrawals(exchanges)
|
|
43
|
+
|
|
44
|
+
// Get OHLCV data
|
|
45
|
+
const ohlcv = await functions.get_exchanges_ohlcv(exchanges, pairs, interval)
|
|
46
|
+
|
|
47
|
+
// Get market history
|
|
48
|
+
const market_history = await functions.get_exchanges_market_history(exchanges, pairs)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Orders Middleware
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
const Orders = require('@icgio/icg-exchanges-wrapper').orders
|
|
55
|
+
|
|
56
|
+
// Create an order manager instance
|
|
57
|
+
const orders = new Orders(exchanges_config)
|
|
58
|
+
|
|
59
|
+
// Place orders with advanced features
|
|
60
|
+
await orders.place_order(exchange, pair, side, amount, price, options)
|
|
61
|
+
|
|
62
|
+
// Cancel orders
|
|
63
|
+
await orders.cancel_order(exchange, pair, order_id)
|
|
64
|
+
|
|
65
|
+
// Get order status
|
|
66
|
+
const status = await orders.get_order_status(exchange, pair, order_id)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### WebSocket Data Client
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
const { ws_data_client, send_log } = require('@icgio/icg-exchanges-wrapper')
|
|
73
|
+
|
|
74
|
+
// Send log messages via WebSocket
|
|
75
|
+
send_log('info', 'Operation completed successfully')
|
|
76
|
+
send_log('error', 'An error occurred')
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Project Structure
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
icg-exchanges-wrapper/
|
|
83
|
+
├── index.js # Main entry point
|
|
84
|
+
├── functions/
|
|
85
|
+
│ ├── get-exchanges-balance.js # Balance fetching
|
|
86
|
+
│ ├── get-exchanges-deposits.js # Deposit history
|
|
87
|
+
│ ├── get-exchanges-open-orders.js # Open orders
|
|
88
|
+
│ ├── get-exchanges-rates-market-history-ohlcv.js # Market data
|
|
89
|
+
│ ├── get-exchanges-trades.js # Trade history
|
|
90
|
+
│ └── get-exchanges-withdrawals.js # Withdrawal history
|
|
91
|
+
├── middleware/
|
|
92
|
+
│ ├── account.js # Account middleware
|
|
93
|
+
│ └── orders.js # Order management middleware
|
|
94
|
+
├── lib/
|
|
95
|
+
│ └── ws-data-client.js # WebSocket data client
|
|
96
|
+
└── package.json
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Available Functions
|
|
100
|
+
|
|
101
|
+
| Function | Description |
|
|
102
|
+
|----------|-------------|
|
|
103
|
+
| `get_exchanges_rates` | Fetch orderbook/rates from exchanges |
|
|
104
|
+
| `get_exchanges_market_history` | Fetch recent trade history |
|
|
105
|
+
| `get_exchanges_ohlcv` | Fetch OHLCV candlestick data |
|
|
106
|
+
| `get_exchanges_balance` | Fetch account balances |
|
|
107
|
+
| `get_exchanges_trades` | Fetch user trade history |
|
|
108
|
+
| `get_exchanges_open_orders` | Fetch open orders |
|
|
109
|
+
| `get_exchanges_deposits` | Fetch deposit history |
|
|
110
|
+
| `get_exchanges_withdrawals` | Fetch withdrawal history |
|
|
111
|
+
|
|
112
|
+
## Dependencies
|
|
113
|
+
|
|
114
|
+
| Package | Purpose |
|
|
115
|
+
|---------|---------|
|
|
116
|
+
| `@icgio/icg-exchanges` | Exchange implementations |
|
|
117
|
+
| `@icgio/icg-utils` | Utility functions |
|
|
118
|
+
| `lodash` | Utility library |
|
|
119
|
+
| `pg` | PostgreSQL client |
|
|
120
|
+
|
|
121
|
+
## Code Style
|
|
122
|
+
|
|
123
|
+
- CommonJS modules (`require()` / `module.exports`)
|
|
124
|
+
- Variable naming: `snake_case`
|
|
125
|
+
- Function naming: `snake_case`
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
ISC License
|
package/middleware/account.js
CHANGED
|
@@ -130,11 +130,11 @@ module.exports = class Account {
|
|
|
130
130
|
if (_.includes(constants.stablecoins, cur)) {
|
|
131
131
|
profit.USD += position
|
|
132
132
|
} else if (_.includes(['KRW'], cur)) {
|
|
133
|
-
profit.USD += position
|
|
133
|
+
profit.USD += position * this.forex_rates['KRWUSD']
|
|
134
134
|
} else if (_.includes(['HKD'], cur)) {
|
|
135
|
-
profit.USD += position
|
|
135
|
+
profit.USD += position * this.forex_rates['HKDUSD']
|
|
136
136
|
} else if (_.includes(['CNYT'], cur)) {
|
|
137
|
-
profit.USD += position
|
|
137
|
+
profit.USD += position * this.forex_rates['CNYUSD']
|
|
138
138
|
} else {
|
|
139
139
|
if (!cmc_rates[cur]) {
|
|
140
140
|
console.log('get_exchange_profit rates_cmc %s does not exist', cur)
|
package/middleware/orders.js
CHANGED