Skip to content

Can I use this repo to call NODE.JS with NPM package from C# Winforms App? #97

@zydjohnHotmail

Description

@zydjohnHotmail

Hello:
I want to know if I can find how can I call some Node.js script from C#, which call a npm package called ccxt, and return the truncated strings to C#. And one step further, how can I call similar Node.js script and pass some parameter and get the results back to C#.
My OS: Window 10 Pro (version 21H2)
Node.js: version: 19.0.0
CCXT: version: 2.1.33

The following is node.js script:
D:\nodejs\CCXT_Exchanges>type ccxt_all_exchanges.js
'use strict';
const ccxt = require('ccxt');
console.log(ccxt.version);
var all_exchanges = ccxt.exchanges
console.log(all_exchanges)
D:\nodejs\CCXT_Exchanges>
The output for running the node.js script:
D:\nodejs\CCXT_Exchanges>node ccxt_all_exchanges.js
2.1.33
[
'aax', 'alpaca', 'ascendex',
'bequant', 'bibox', 'bigone',
'binance', 'binancecoinm', 'binanceus',
'binanceusdm', 'bit2c', 'bitbank',
'bitbay', 'bitbns', 'bitcoincom',
'bitfinex', 'bitfinex2', 'bitflyer',
'bitforex', 'bitget', 'bithumb',
'bitmart', 'bitmex', 'bitopro',
'bitpanda', 'bitrue', 'bitso',
'bitstamp', 'bitstamp1', 'bittrex',
'bitvavo', 'bkex', 'bl3p',
'blockchaincom', 'btcalpha', 'btcbox',
'btcex', 'btcmarkets', 'btctradeua',
'btcturk', 'buda', 'bw',
'bybit', 'bytetrade', 'cex',
'coinbase', 'coinbaseprime', 'coinbasepro',
'coincheck', 'coinex', 'coinfalcon',
'coinmate', 'coinone', 'coinspot',
'crex24', 'cryptocom', 'currencycom',
'delta', 'deribit', 'digifinex',
'exmo', 'flowbtc', 'fmfwio',
'ftx', 'ftxus', 'gate',
'gateio', 'gemini', 'hitbtc',
'hitbtc3', 'hollaex', 'huobi',
'huobijp', 'huobipro', 'idex',
'independentreserve', 'indodax', 'itbit',
'kraken', 'kucoin', 'kucoinfutures',
'kuna', 'latoken', 'lbank',
'lbank2', 'liquid', 'luno',
'lykke', 'mercado', 'mexc',
'mexc3', 'ndax', 'novadax',
'oceanex', 'okcoin', 'okex',
'okex5', 'okx', 'paymium',
'phemex',
... 20 more items
]

D:\nodejs\CCXT_Exchanges>
The issue here is that console.log only shows the first 100 items, there are 20 more items will be returned. I want to use ClearScript to run the above node.js script and return all 120 items to C#.
How can I do this?

One step further, can I pass variable to async function using CCXT?

D:\nodejs\CCXT_Binance>type Binance1PairOrderBook.js
const ccxt = require('ccxt');
console.log(ccxt.version);

if (process.argv.length != 3)
{
console.error('Usage: BTC/USDT');
console.error('Please try again!');
process.exit(1);
}
const [nodejs, script1, pair1] = process.argv;

let exchange = new ccxt.binance
({
'adjustForTimeDifference': true,
defaultType: 'spot',
'verbose': false
});

const pair1OrderBook = async (pair1) => {
try
{
await exchange.loadMarkets();
const orderbook1 = await exchange.fetchOrderBook(pair1);
if (typeof orderbook1 !== 'undefined')
{
const json_orderbook = JSON.stringify(orderbook1);
console.log(json_orderbook);
}
else
{
const obj_orderbook0 = ({ 'Symbol': pair1, 'Data': [] });
const json_orderbook0 = JSON.stringify(obj_orderbook0);
console.log(json_orderbook0);
}
}
catch (err)
{
console.error(err)
}
};
pair1OrderBook(pair1);

D:\nodejs\CCXT_Binance>

To use this code, call this with one cryptocurrency trading pair, the biggest pair is: BTC/USDT, but the output contains too many rows, so calling it with not very active pairs, like this:
D:\nodejs\CCXT_Binance>node Binance1PairOrderBook.js FXS/USDT

Or some pairs, which do exist, but no trade volume here: ETH/USDC, like the following:
D:\nodejs\CCXT_Binance>node Binance1PairOrderBook.js ETH/USDC
2.1.33
(node:22912) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use node --trace-warnings ... to show where the warning was created)
{"symbol":"ETH/USDC","bids":[],"asks":[],"nonce":2090539859}

D:\nodejs\CCXT_Binance>

Please advise on if I can use the repo to do the job: call Node.js from C# WinForms App?
Thanks,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions