This commit is contained in:
discountry
2025-10-03 15:28:16 +08:00
parent d5c4b04746
commit fcb83bd16b
925 changed files with 165721 additions and 4 deletions
@@ -0,0 +1,46 @@
<!DOCTYPE HTML>
<html>
<head>
<title>CCXT Basic example for the browser</title>
<script type="text/javascript" src="https://unpkg.com/ccxt"></script>
<script>
document.addEventListener ("DOMContentLoaded", function () {
alert ('ccxt version ' + ccxt.version);
const exchange = new ccxt.bittrex ({
'proxyUrl': 'https://cors-anywhere.herokuapp.com/'
})
const symbol = 'BTC/USDT'
exchange.fetchTicker (symbol).then (ticker => {
const text = [
exchange.id,
symbol,
JSON.stringify (ticker, undefined, '\n\t')
]
document.getElementById ('content').innerHTML = text.join (' ')
}).catch (e => {
const text = [
e.constructor.name,
e.message,
]
document.getElementById ('content').innerHTML = text.join (' ')
})
})
</script>
</head>
<body>
<h1>Hello, CCXT!</h1>
<pre id="content"></pre>
</body>
</html>
@@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<html>
<head>
<title>CCXT Basic example for the browser</title>
<script type="text/javascript" src="https://unpkg.com/ccxt"></script>
<style type="text/css">
#contentA { background-color: #ccccff; }
#contentB { background-color: #ffcccc; }
</style>
<script>'use strict'
class MyExchange extends ccxt.coinbasepro {
async fetchTicker (symbol, params = {}) {
alert ("I'm about to call the parent method from the overrided class, woohooo!")
// just call the parent method and that's it
return super.fetchTicker (symbol, params);
}
}
document.addEventListener ("DOMContentLoaded", function () {
const exchange = new MyExchange ()
const symbol = 'ETH/BTC'
const showFetchedTicker = function (ticker, elementId) {
const text = [
exchange.id,
symbol,
JSON.stringify (ticker, undefined, '\n\t')
]
document.getElementById (elementId).innerHTML = text.join (' ')
}
exchange.fetchTicker (symbol).then (ticker => showFetchedTicker (ticker, 'content'))
})
</script>
</head>
<body>
<h1>Hello, CCXT!</h1>
<pre id="content"></pre>
</body>
</html>
+52
View File
@@ -0,0 +1,52 @@
<!DOCTYPE HTML>
<html>
<head>
<title>CCXT Basic example for the browser</title>
<script type="text/javascript" src="https://unpkg.com/ccxt"></script>
<script>
document.addEventListener ("DOMContentLoaded", function () {
alert ('ccxt version ' + ccxt.version + ' supporting ');
const pollTickerContinuously = async function (exchange, symbol) {
while (true) {
try {
const ticker = await exchange.fetchTicker (symbol)
const text = [
exchange.id,
symbol,
JSON.stringify (ticker, undefined, '\n\t')
]
document.getElementById ('content').innerHTML = text.join (' ');
} catch (e) {
const text = [
e.constructor.name,
e.message,
]
document.getElementById ('content').innerHTML = text.join (' ');
}
}
}
const exchange = new ccxt.binance ({ enableRateLimit: true })
const symbol = 'ETH/BTC'
pollTickerContinuously (exchange, symbol)
})
</script>
</head>
<body>
<h1>Hello, CCXT!</h1>
<pre id="content"></pre>
</body>
</html>
@@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<html>
<head>
<title>CCXT Basic example for the browser</title>
<script type="text/javascript" src="https://unpkg.com/ccxt"></script>
<script>
document.addEventListener ("DOMContentLoaded", async function () {
alert ('ccxt version ' + ccxt.version);
const enableRateLimit = true
const exchange = new ccxt.poloniex ({ enableRateLimit })
const symbol = 'ETH/BTC'
while (true) {
let text = []
try {
const ticker = await exchange.fetchTicker (symbol)
text = [
exchange.id,
symbol,
JSON.stringify (exchange.omit (ticker, 'info'), undefined, '\t')
]
} catch (e) {
text = [
e.constructor.name,
e.message,
]
}
document.getElementById ('content').innerHTML = text.join (' ')
}
})
</script>
</head>
<body>
<h1>Hello, CCXT!</h1>
<pre id="content"></pre>
</body>
</html>
+43
View File
@@ -0,0 +1,43 @@
<!DOCTYPE HTML>
<html>
<head>
<title>CCXT Basic example for the browser</title>
<script type="text/javascript" src="https://unpkg.com/ccxt"></script>
<script>
document.addEventListener ("DOMContentLoaded", function () {
alert ('CCXT' + (ccxt.isBrowser ? ' browser' : '') + ' version ' + ccxt.version);
const exchange = new ccxt.coinbasepro ({ enableRateLimit: true })
const symbol = 'ETH/BTC'
exchange.fetchTicker (symbol).then (ticker => {
const text = [
exchange.id,
symbol,
JSON.stringify (ticker, undefined, '\n\t')
]
document.getElementById ('content').innerHTML = text.join (' ')
}).catch (e => {
const text = [
e.constructor.name,
e.message,
]
document.getElementById ('content').innerHTML = text.join (' ')
})
})
</script>
</head>
<body>
<h1>Hello, CCXT!</h1>
<pre id="content"></pre>
</body>
</html>
@@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html>
<head>
<title>CCXT Basic example for the browser</title>
<script type="text/javascript" src="https://unpkg.com/ccxt"></script>
<script>
document.addEventListener ("DOMContentLoaded", function () {
async function main () {
const exchange = new ccxt.binance ({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_API_SECRET',
'proxyUrl': 'https://cors-anywhere.herokuapp.com/',
})
const response = await exchange.fetchBalance ()
console.log (response)
}
main ()
})
</script>
</head>
<body>
<h1>Hello, CCXT!</h1>
<pre id="content"></pre>
</body>
</html>
@@ -0,0 +1,7 @@
// JavaScript CORS Proxy
// Save this in a file like cors.js and run with `node cors [port]`
// It will listen for your requests on the port you pass in command line or port 8080 by default
const port = (process.argv.length > 2) ? parseInt (process.argv[2]) : 8080 // default
require ('cors-anywhere').createServer ({
setHeaders: { 'origin': 'https://www.bitmex.com' }
}).listen (port, '0.0.0.0')
+46
View File
@@ -0,0 +1,46 @@
<!DOCTYPE HTML>
<html>
<head>
<title>CCXT Basic example for the browser</title>
<script type="text/javascript" src="https://unpkg.com/ccxt"></script>
<script>
document.addEventListener ("DOMContentLoaded", function () {
alert ('ccxt version ' + ccxt.version);
const exchange = new ccxt.bitmex ({
'proxyUrl': 'http://127.0.0.1:8080/',
})
const symbol = 'BTC/USDT'
exchange.fetchTicker (symbol).then (ticker => {
const text = [
exchange.id,
symbol,
JSON.stringify (ticker, undefined, '\n\t')
]
document.getElementById ('content').innerHTML = text.join (' ')
}).catch (e => {
const text = [
e.constructor.name,
e.message,
]
document.getElementById ('content').innerHTML = text.join (' ')
})
})
</script>
</head>
<body>
<h1>Hello, CCXT!</h1>
<pre id="content"></pre>
</body>
</html>
@@ -0,0 +1,61 @@
<!DOCTYPE HTML>
<html>
<head>
<title>CCXT Basic example for the browser</title>
<script type="text/javascript" src="https://unpkg.com/ccxt"></script>
<script type="text/javascript" src="https://unpkg.com/lightweight-charts@3.4.0/dist/lightweight-charts.standalone.production.js"></script>
<script>
document.addEventListener ("DOMContentLoaded", async function () {
try {
const exchange = new ccxt.coinbasepro ({ enableRateLimit: true });
const symbol = 'ETH/BTC';
const timeframe = '1d';
const since = undefined;
const limit = 600;
const config = {
width: 600,
height: 300,
priceScale: {
position: 'left',
mode: 1,
autoScale: true,
invertScale: false,
},
timeScale: {
fixLeftEdge: true,
lockVisibleTimeRangeOnResize: true,
rightBarStaysOnScroll: true,
visible: true,
timeVisible: true,
secondsVisible: true,
},
crosshair: {
mode: window.LightweightCharts.CrosshairMode.Normal,
},
};
const chart = window.LightweightCharts.createChart(document.body, config);
const candleSeries = chart.addCandlestickSeries();
while (true) {
try {
const response = await exchange.fetchOHLCV(symbol, timeframe, since, limit);
const last = response[response.length - 1]
const [ timestamp, open, high, low, close ] = last;
const data = response.map (([ timestamp, open, high, low, close ]) => ({ time: exchange.iso8601 (timestamp), open, high, low, close }));
candleSeries.setData(data);
} catch (e) {
console.log (e.constructor.name, e.message);
}
await exchange.sleep (1000);
}
} catch (e) {
alert (e.constructor.name + ' ' + e.message);
}
})
</script>
</head>
<body>
</body>
</html>
@@ -0,0 +1,97 @@
<!DOCTYPE html>
<html>
<body>
<h2>CCXT running on a Webworker example</h2>
<p>This example uses a web worker to continuously call <b>fetchTicker</b> on a user-defined exchange, symbol and interval. Then, the web worker reaches back with the results.</p>
<h3>Parameters</h3>
<label for="exchange">Exchange:</label>
<input type="text" id="exchange" name="exchange" ><br><br>
<label for="symbol">Symbol: </label>
<input type="text" id="symbol" name="symbol"><br><br>
<label for="interval">Interval (ms): </label>
<input type="text" id="interval" name="interval"><br><br>
<button onclick="startWorker()">Start CCXT worker</button>
<button onclick="stopWorker()">Stop CCXT worker</button>
<h3> Received Results:</h3>
<output id="result"></output>
<table id="resultsTable" style="left:300px;width:400px; border:1px solid black;" >
<thead>
<tr>
<th>Symbol</th>
<th>Last Price</th>
<th>Base Volume</th>
<th>Exchange Ts</th>
<th>Local Ts</th>
</tr>
</thead>
<tbody id="tbody">
</tbody>
</table>
</body>
<script>
// fill in default values
document.addEventListener('DOMContentLoaded', function(event) {
document.getElementById('exchange').value = 'coinbasepro';
document.getElementById('symbol').value = 'BTC/USDT';
document.getElementById('interval').value = '1000';
});
var ccxtWorker;
function startWorker() {
if (typeof(Worker) !== "undefined") {
// if the worker does not exist yet, creates it
if (typeof(ccxtWorker) == "undefined") {
ccxtWorker = new Worker("worker.js");
}
// reads user-defined parameters
var exchange = document.getElementById('exchange').value
var symbol = document.getElementById('symbol').value
var interval = document.getElementById('interval').value
// send a message with those values
ccxtWorker.postMessage([exchange,symbol, interval]);
ccxtWorker.onmessage = function(event) {
// every time the ccxtworker posts a message
// this handler will be invoked
handleReceivedData(event.data)
};
} else {
document.getElementById("result").innerHTML = "Sorry! No Web Worker support.";
}
}
function handleReceivedData(data) {
var [symbol, last, baseVolume, timestamp, ourTimestamp] = data;
var tableRef = document.getElementById('resultsTable');
var tbody = document.getElementById('tbody');
row = tbody.insertRow(0);
cellSymbol = row.insertCell();
cellSymbol.innerHTML = symbol;
cellPrice = row.insertCell();
cellPrice.innerHTML = last;
cellPrice = row.insertCell();
cellPrice.innerHTML = baseVolume;
cellTimestamp = row.insertCell();
cellTimestamp.innerHTML = timestamp;
cellOurtimestamp = row.insertCell();
cellOurtimestamp.innerHTML = ourTimestamp;
}
function stopWorker() {
if (ccxtWorker !== undefined) {
ccxtWorker.terminate();
ccxtWorker = undefined;
}
}
</script>
</body>
</html>
@@ -0,0 +1,43 @@
self.importScripts('https://unpkg.com/ccxt@1.79.2/dist/ccxt.browser.js');
console.log("Loaded ccxt version:", self.ccxt.version);
var exchangeInstance = undefined;
// handler of received messages
self.onmessage = async function handler(msg) {
await handleMessageFromMain(msg)
}
// get messages from the main script
async function handleMessageFromMain(msg) {
console.log(msg.data);
var [exchange, symbol, interval] = msg.data;
console.log('Worker received:', symbol,exchange, interval)
interval = parseInt(interval)
await processTicker(symbol, exchange)
// schedule process ticker execution
setInterval (async () => {
await processTicker(symbol, exchange)
}, interval)
}
async function processTicker(symbol, exchangeId) {
if (exchangeInstance === undefined) {
exchangeInstance = new ccxt[exchangeId]
}
var result = await fetchTicker(symbol)
var symbol = result['symbol']
var last = result['last']
var timestamp = result['timestamp']
var baseVolume = result['baseVolume']
var ourTimestamp = Date.now()
// send the data back to the main script
postMessage([symbol, last, baseVolume, timestamp, ourTimestamp]);
}
async function fetchTicker(symbol){
// use ccxt to fetch ticker info
var result = await exchangeInstance.fetchTicker(symbol)
return result;
}