-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
watchPositions many exchanges continuosly
github-actions[bot] edited this page Jun 11, 2026
·
1 revision
using ccxt;
using ccxt.pro;
using Newtonsoft.Json;
namespace examples;
partial class Examples
{
async public Task<List<Position>> watchPositionsContinuously(Exchange exchange)
{
while (true)
{
try
{
var positions = await exchange.WatchPositions();
Console.WriteLine("Fetched " + exchange.id + " - Positions: " + JsonConvert.SerializeObject(positions));
return positions;
}
catch (Exception e)
{
Console.WriteLine(e);
break;
}
}
return null;
}
// start exchanges and fetch OHLCV loop
async public Task initializeExchange(string exchangeName, object config)
{
var ex = Exchange.DynamicallyCreateInstance("ccxt.pro." + exchangeName, config);
var promises = new List<Task<List<Position>>>() { };
(promises).Add(watchPositionsContinuously(ex));
await Task.WhenAll(promises);
await ex.Close();
}
// main function
async public Task watchPositionsManyExchangesContinuosly()
{
var exchanges = new Dictionary<string, object>()
{
{
"binanceusdm", new Dictionary<string, object>()
{
{ "apiKey", "YOUR_API_KEY" },
{ "secret", "YOUR_API_SECRET" },
}
},
{
"okx", new Dictionary<string, object>()
{
{ "apiKey", "YOUR_API_KEY" },
{ "secret", "YOUR_API_SECRET" },
}
},
{
"huobi", new Dictionary<string, object>()
{
{ "apiKey", "YOUR_API_KEY" },
{ "secret", "YOUR_API_SECRET" },
}
},
};
var promises = new List<Task>() { };
var exchangeIds = exchanges.Keys.ToList();
for (var i = 0; i < exchangeIds.Count; i++)
{
var exchangeName = exchangeIds[i];
var config = exchanges[exchangeName];
promises.Add(initializeExchange(exchangeName, config));
}
await Task.WhenAll(promises);
}
}(If the page is not being rendered for you, you can refer to the mirror at https://docs.ccxt.com/)
- Install
- Examples
- Manual
- CCXT Pro
- Contributing
- Supported Exchanges
- Exchanges By Country
- API Spec By Method
- FAQ
- Changelog
- Awesome
- API Spec by Exchange
- fetchCurrencies
- alpaca
- apex
- ascendex
- aster
- backpack
- bigone
- binance
- bingx
- bit2c
- bitbank
- bitbns
- bitfinex
- bitflyer
- bitget
- bithumb
- bitmart
- bitmex
- bitopro
- bitrue
- bitso
- bitstamp
- bitteam
- bittrade
- bitvavo
- blockchaincom
- blofin
- btcbox
- btcmarkets
- btcturk
- bullish
- bybit
- bydfi
- cex
- coinbase
- coinbaseexchange
- coinbaseinternational
- coincheck
- coinex
- coinmate
- coinmetro
- coinone
- coinsph
- coinspot
- cryptocom
- cryptomus
- deepcoin
- delta
- deribit
- derive
- digifinex
- dydx
- exmo
- extended
- foxbit
- gate
- gemini
- grvt
- hashkey
- hibachi
- hitbtc
- hollaex
- htx
- hyperliquid
- independentreserve
- indodax
- kraken
- krakenfutures
- kucoin
- fetchBidsAsks
- latoken
- lbank
- lighter
- luno
- mercado
- mexc
- modetrade
- ndax
- novadax
- okx
- onetrading
- p2b
- pacifica
- paradex
- paymium
- phemex
- poloniex
- tokocrypto
- toobit
- upbit
- weex
- whitebit
- woo
- woofipro
- xt
- zaif
- fetchStatus