Skip to content

Commit

Permalink
bitmart: updated the fetchTickers spot endpoint (#22680)
Browse files Browse the repository at this point in the history
* refactor(bitmart): update spot fetchTickers endpoint

```
node examples/js/cli bitmart fetchTickers '["BTC/USDT","ETH/USDT"]'

bitmart.fetchTickers (BTC/USDT,ETH/USDT)
2024-05-31T04:38:48.799Z iteration 0 passed in 1006 ms

{
  'BTC/USDT': {
    symbol: 'BTC/USDT',
    timestamp: 1717130327808,
    datetime: '2024-05-31T04:38:47.808Z',
    high: 69499.99,
    low: 67132.4,
    bid: 68508.59,
    bidVolume: 0.00627,
    ask: 68508.61,
    askVolume: 0.01234,
    vwap: 68354.4118269248,
    open: 68303.27,
    close: 68508.6,
    last: 68508.6,
    change: 0.00301,
    percentage: 0.301,
    average: 68405.935,
    baseVolume: 10533.01836,
    quoteVolume: 719978274.76,
    info: [
      'BTC_USDT',      '68508.60',
      '10533.01836',   '719978274.76',
      '68303.27',      '69499.99',
      '67132.40',      '0.00301',
      '68508.59',      '0.00627',
      '68508.61',      '0.01234',
      '1717130327808'
    ]
  },
  'ETH/USDT': {
    symbol: 'ETH/USDT',
    timestamp: 1717130327783,
    datetime: '2024-05-31T04:38:47.783Z',
    high: 3825.35,
    low: 3702.6,
    bid: 3759.99,
    bidVolume: 0.00532,
    ask: 3760,
    askVolume: 0.02055,
    vwap: 3758.4100324692363,
    open: 3794.82,
    close: 3760,
    last: 3760,
    change: -0.00918,
    percentage: 0.918,
    average: 3777.41,
    baseVolume: 113844.1009,
    quoteVolume: 427872810.96,
    info: [
      'ETH_USDT',      '3760.00',
      '113844.10090',  '427872810.96',
      '3794.82',       '3825.35',
      '3702.60',       '-0.00918',
      '3759.99',       '0.00532',
      '3760',          '0.02055',
      '1717130327783'
    ]
  }
}
```

* test(bitmart): static request, update spot fetchTickers

* refactor(bitmart): update fetchTicker endpoint

```
bitmart.fetchTicker (BTC/USDT)
2024-05-31T05:12:04.737Z iteration 0 passed in 475 ms

{
  symbol: 'BTC/USDT',
  timestamp: 1717132325396,
  datetime: '2024-05-31T05:12:05.396Z',
  high: 69499.99,
  low: 67132.4,
  bid: 68479.98,
  bidVolume: 0.05972,
  ask: 68480,
  askVolume: 0.00058,
  vwap: 68360.17033443128,
  open: 68078.42,
  close: 68479.99,
  last: 68479.99,
  change: 0.0059,
  percentage: 0.59,
  average: 68279.205,
  baseVolume: 10530.35952,
  quoteVolume: 719857170.47,
  info: {
    symbol: 'BTC_USDT',
    last: '68479.99',
    v_24h: '10530.35952',
    qv_24h: '719857170.47',
    open_24h: '68078.42',
    high_24h: '69499.99',
    low_24h: '67132.40',
    fluctuation: '0.00590',
    bid_px: '68479.98',
    bid_sz: '0.05972',
    ask_px: '68480',
    ask_sz: '0.00058',
    ts: '1717132325396'
  }
}
```

* test(bitmart): static request, update fetchTicker tests

* fix build

* update responsetest

* create dict wrapper for fetchTickers result

* test(bitmart): static response, fetchTicker fix test failure

* change empty array check

* adjusted list check to if marketId is defined

---------

Co-authored-by: carlosmiei <43336371+carlosmiei@users.noreply.github.com>

[ci skip]
  • Loading branch information
Travis CI committed Jun 7, 2024
1 parent 6291cce commit 45e4075
Show file tree
Hide file tree
Showing 24 changed files with 1,607 additions and 891 deletions.
209 changes: 109 additions & 100 deletions cs/ccxt/exchanges/bitmart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,27 +1068,46 @@ public async override Task<object> fetchDepositWithdrawFee(object code, object p
public override object parseTicker(object ticker, object market = null)
{
//
// spot (REST)
// spot (REST) fetchTickers
//
// {
// "symbol": "SOLAR_USDT",
// "last_price": "0.020342",
// "quote_volume_24h": "56817.811802",
// "base_volume_24h": "2172060",
// "high_24h": "0.256000",
// "low_24h": "0.016980",
// "open_24h": "0.022309",
// "close_24h": "0.020342",
// "best_ask": "0.020389",
// "best_ask_size": "339.000000000000000000000000000000",
// "best_bid": "0.020342",
// "best_bid_size": "3369.000000000000000000000000000000",
// "fluctuation": "-0.0882",
// "url": "https://www.bitmart.com/trade?symbol=SOLAR_USDT",
// "timestamp": 1667403439367
// }
// {
// 'result': [
// "AFIN_USDT", // symbol
// "0.001047", // last
// "11110", // v_24h
// "11.632170", // qv_24h
// "0.001048", // open_24h
// "0.001048", // high_24h
// "0.001047", // low_24h
// "-0.00095", // price_change_24h
// "0.001029", // bid_px
// "5555", // bid_sz
// "0.001041", // ask_px
// "5297", // ask_sz
// "1717122550482" // timestamp
// ]
// }
//
// spot (REST) fetchTicker
//
// {
// "symbol": "BTC_USDT",
// "last": "68500.00",
// "v_24h": "10491.65490",
// "qv_24h": "717178990.42",
// "open_24h": "68149.75",
// "high_24h": "69499.99",
// "low_24h": "67132.40",
// "fluctuation": "0.00514",
// "bid_px": "68500",
// "bid_sz": "0.00162",
// "ask_px": "68500.01",
// "ask_sz": "0.01722",
// "ts": "1717131391671"
// }
//
// spot (WS)
//
// {
// "symbol":"BTC_USDT",
// "last_price":"146.24",
Expand All @@ -1114,23 +1133,50 @@ public override object parseTicker(object ticker, object market = null)
// "legal_coin_price":"0.1302699"
// }
//
object timestamp = this.safeInteger(ticker, "timestamp");
object result = this.safeList(ticker, "result", new List<object>() {});
object average = this.safeString2(ticker, "avg_price", "index_price");
object marketId = this.safeString2(ticker, "symbol", "contract_symbol");
object timestamp = this.safeInteger2(ticker, "timestamp", "ts");
object last = this.safeString2(ticker, "last_price", "last");
object percentage = this.safeString(ticker, "price_change_percent_24h");
object change = this.safeString(ticker, "fluctuation");
object high = this.safeString2(ticker, "high_24h", "high_price");
object low = this.safeString2(ticker, "low_24h", "low_price");
object bid = this.safeString2(ticker, "best_bid", "bid_px");
object bidVolume = this.safeString2(ticker, "best_bid_size", "bid_sz");
object ask = this.safeString2(ticker, "best_ask", "ask_px");
object askVolume = this.safeString2(ticker, "best_ask_size", "ask_sz");
object open = this.safeString(ticker, "open_24h");
object baseVolume = this.safeString2(ticker, "base_volume_24h", "v_24h");
object quoteVolume = this.safeStringLower2(ticker, "quote_volume_24h", "qv_24h");
object listMarketId = this.safeString(result, 0);
if (isTrue(!isEqual(listMarketId, null)))
{
marketId = listMarketId;
timestamp = this.safeInteger(result, 12);
high = this.safeString(result, 5);
low = this.safeString(result, 6);
bid = this.safeString(result, 8);
bidVolume = this.safeString(result, 9);
ask = this.safeString(result, 10);
askVolume = this.safeString(result, 11);
open = this.safeString(result, 4);
last = this.safeString(result, 1);
change = this.safeString(result, 7);
baseVolume = this.safeString(result, 2);
quoteVolume = this.safeStringLower(result, 3);
}
market = this.safeMarket(marketId, market);
object symbol = getValue(market, "symbol");
if (isTrue(isEqual(timestamp, null)))
{
// ticker from WS has a different field (in seconds)
timestamp = this.safeIntegerProduct(ticker, "s_t", 1000);
}
object marketId = this.safeString2(ticker, "symbol", "contract_symbol");
market = this.safeMarket(marketId, market);
object symbol = getValue(market, "symbol");
object last = this.safeString2(ticker, "close_24h", "last_price");
object percentage = this.safeString(ticker, "price_change_percent_24h");
if (isTrue(isEqual(percentage, null)))
{
percentage = Precise.stringMul(this.safeString(ticker, "fluctuation"), "100");
percentage = Precise.stringMul(change, "100");
}
object baseVolume = this.safeString(ticker, "base_volume_24h");
object quoteVolume = this.safeString(ticker, "quote_volume_24h");
if (isTrue(isEqual(quoteVolume, null)))
{
if (isTrue(isEqual(baseVolume, null)))
Expand All @@ -1145,25 +1191,22 @@ public override object parseTicker(object ticker, object market = null)
baseVolume = null;
}
}
object average = this.safeString2(ticker, "avg_price", "index_price");
object high = this.safeString2(ticker, "high_24h", "high_price");
object low = this.safeString2(ticker, "low_24h", "low_price");
return this.safeTicker(new Dictionary<string, object>() {
{ "symbol", symbol },
{ "timestamp", timestamp },
{ "datetime", this.iso8601(timestamp) },
{ "high", high },
{ "low", low },
{ "bid", this.safeString(ticker, "best_bid") },
{ "bidVolume", this.safeString(ticker, "best_bid_size") },
{ "ask", this.safeString(ticker, "best_ask") },
{ "askVolume", this.safeString(ticker, "best_ask_size") },
{ "bid", bid },
{ "bidVolume", bidVolume },
{ "ask", ask },
{ "askVolume", askVolume },
{ "vwap", null },
{ "open", this.safeString(ticker, "open_24h") },
{ "open", open },
{ "close", last },
{ "last", last },
{ "previousClose", null },
{ "change", null },
{ "change", change },
{ "percentage", percentage },
{ "average", average },
{ "baseVolume", baseVolume },
Expand All @@ -1178,6 +1221,7 @@ public async override Task<object> fetchTicker(object symbol, object parameters
* @method
* @name bitmart#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://developer-pro.bitmart.com/en/spot/#get-ticker-of-a-trading-pair-v3
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
Expand All @@ -1194,76 +1238,25 @@ public async override Task<object> fetchTicker(object symbol, object parameters
} else if (isTrue(getValue(market, "spot")))
{
((IDictionary<string,object>)request)["symbol"] = getValue(market, "id");
response = await this.publicGetSpotV1Ticker(this.extend(request, parameters));
response = await this.publicGetSpotQuotationV3Ticker(this.extend(request, parameters));
} else
{
throw new NotSupported ((string)add(add(add(this.id, " fetchTicker() does not support "), getValue(market, "type")), " markets, only spot and swap markets are accepted")) ;
}
//
// spot
//
// {
// "message":"OK",
// "code":1000,
// "trace":"6aa5b923-2f57-46e3-876d-feca190e0b82",
// "data":{
// "tickers":[
// {
// "symbol":"ETH_BTC",
// "last_price":"0.036037",
// "quote_volume_24h":"4380.6660000000",
// "base_volume_24h":"159.3582006712",
// "high_24h":"0.036972",
// "low_24h":"0.035524",
// "open_24h":"0.036561",
// "close_24h":"0.036037",
// "best_ask":"0.036077",
// "best_ask_size":"9.9500",
// "best_bid":"0.035983",
// "best_bid_size":"4.2792",
// "fluctuation":"-0.0143",
// "url":"https://www.bitmart.com/trade?symbol=ETH_BTC"
// }
// ]
// }
// }
//
// swap
//
// {
// "message":"OK",
// "code":1000,
// "trace":"4a0ebceb-d3f7-45a3-8feb-f61e230e24cd",
// "data":{
// "tickers":[
// {
// "contract_symbol":"DOGEUSDT",
// "last_price":"0.130180",
// "index_price":"0.13028635",
// "last_funding_rate":"0.00002025",
// "price_change_percent_24h":"-2.326",
// "volume_24h":"116789313.01797258",
// "url":"https://futures.bitmart.com/en?symbol=DOGEUSDT",
// "high_price":"0.134520",
// "low_price":"0.128570",
// "legal_coin_price":"0.13017401"
// }
// ]
// }
// }
//
object data = this.safeValue(response, "data", new Dictionary<string, object>() {});
object tickers = this.safeValue(data, "tickers", new List<object>() {});
// fails in naming for contract tickers 'contract_symbol'
object tickersById = null;
object tickers = new List<object>() {};
object ticker = new Dictionary<string, object>() {};
if (isTrue(getValue(market, "spot")))
{
tickersById = this.indexBy(tickers, "symbol");
} else if (isTrue(getValue(market, "swap")))
ticker = this.safeDict(response, "data", new Dictionary<string, object>() {});
} else
{
object data = this.safeDict(response, "data", new Dictionary<string, object>() {});
tickers = this.safeList(data, "tickers", new List<object>() {});
tickersById = this.indexBy(tickers, "contract_symbol");
ticker = this.safeDict(tickersById, getValue(market, "id"));
}
object ticker = this.safeDict(tickersById, getValue(market, "id"));
return this.parseTicker(ticker, market);
}

Expand All @@ -1273,7 +1266,7 @@ public async override Task<object> fetchTickers(object symbols = null, object pa
* @method
* @name bitmart#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://developer-pro.bitmart.com/en/spot/#get-ticker-of-all-pairs-v2
* @see https://developer-pro.bitmart.com/en/spot/#get-ticker-of-all-pairs-v3
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
Expand All @@ -1294,20 +1287,36 @@ public async override Task<object> fetchTickers(object symbols = null, object pa
object response = null;
if (isTrue(isEqual(type, "spot")))
{
response = await this.publicGetSpotV2Ticker(parameters);
response = await this.publicGetSpotQuotationV3Tickers(parameters);
} else if (isTrue(isEqual(type, "swap")))
{
response = await this.publicGetContractV1Tickers(parameters);
} else
{
throw new NotSupported ((string)add(add(add(this.id, " fetchTickers() does not support "), type), " markets, only spot and swap markets are accepted")) ;
}
object data = this.safeValue(response, "data", new Dictionary<string, object>() {});
object tickers = this.safeValue(data, "tickers", new List<object>() {});
object tickers = new List<object>() {};
if (isTrue(isEqual(type, "spot")))
{
tickers = this.safeList(response, "data", new List<object>() {});
} else
{
object data = this.safeDict(response, "data", new Dictionary<string, object>() {});
tickers = this.safeList(data, "tickers", new List<object>() {});
}
object result = new Dictionary<string, object>() {};
for (object i = 0; isLessThan(i, getArrayLength(tickers)); postFixIncrement(ref i))
{
object ticker = this.parseTicker(getValue(tickers, i));
object ticker = new Dictionary<string, object>() {};
if (isTrue(isEqual(type, "spot")))
{
ticker = this.parseTicker(new Dictionary<string, object>() {
{ "result", getValue(tickers, i) },
});
} else
{
ticker = this.parseTicker(getValue(tickers, i));
}
object symbol = getValue(ticker, "symbol");
((IDictionary<string,object>)result)[(string)symbol] = ticker;
}
Expand Down
16 changes: 9 additions & 7 deletions cs/ccxt/exchanges/blockchaincom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,10 @@ public async override Task<object> cancelOrder(object id, object symbol = null,
{ "orderId", id },
};
object response = await this.privateDeleteOrdersOrderId(this.extend(request, parameters));
return new Dictionary<string, object>() {
return this.safeOrder(new Dictionary<string, object>() {
{ "id", id },
{ "info", response },
};
});
}

public async override Task<object> cancelAllOrders(object symbol = null, object parameters = null)
Expand All @@ -624,7 +624,7 @@ public async override Task<object> cancelAllOrders(object symbol = null, object
* @method
* @name blockchaincom#cancelAllOrders
* @description cancel all open orders
* @see https://api.blockchain.com/v3/#/trading/deleteAllOrders
* @see https://api.blockchain.com/v3/#deleteallorders
* @param {string} symbol unified market symbol of the market to cancel orders in, all markets are used if undefined, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
Expand All @@ -640,10 +640,12 @@ public async override Task<object> cancelAllOrders(object symbol = null, object
((IDictionary<string,object>)request)["symbol"] = marketId;
}
object response = await this.privateDeleteOrders(this.extend(request, parameters));
return new Dictionary<string, object>() {
{ "symbol", symbol },
{ "info", response },
};
//
// {}
//
return new List<object> {this.safeOrder(new Dictionary<string, object>() {
{ "info", response },
})};
}

public async override Task<object> fetchTradingFees(object parameters = null)
Expand Down
12 changes: 8 additions & 4 deletions cs/ccxt/exchanges/pro/upbit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,22 @@ public async virtual Task<object> authenticate(object parameters = null)
{
parameters ??= new Dictionary<string, object>();
this.checkRequiredCredentials();
object authenticated = getValue(getValue(this.options, "ws"), "token");
object wsOptions = this.safeDict(this.options, "ws", new Dictionary<string, object>() {});
object authenticated = this.safeString(wsOptions, "token");
if (isTrue(isEqual(authenticated, null)))
{
object auth = new Dictionary<string, object>() {
{ "access_key", this.apiKey },
{ "nonce", this.uuid() },
};
object token = jwt(auth, this.encode(this.secret), sha256, false);
((IDictionary<string,object>)getValue(this.options, "ws"))["token"] = token;
((IDictionary<string,object>)getValue(getValue(this.options, "ws"), "options"))["headers"] = new Dictionary<string, object>() {
{ "authorization", add("Bearer ", token) },
((IDictionary<string,object>)wsOptions)["token"] = token;
((IDictionary<string,object>)wsOptions)["options"] = new Dictionary<string, object>() {
{ "headers", new Dictionary<string, object>() {
{ "authorization", add("Bearer ", token) },
} },
};
((IDictionary<string,object>)this.options)["ws"] = wsOptions;
}
object url = add(getValue(getValue(this.urls, "api"), "ws"), "/private");
var client = this.client(url);
Expand Down
3 changes: 2 additions & 1 deletion cs/ccxt/wrappers/bitmart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public async Task<Dictionary<string, object>> FetchDepositWithdrawFee(string cod
/// fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
/// </summary>
/// <remarks>
/// See <see href="https://developer-pro.bitmart.com/en/spot/#get-ticker-of-a-trading-pair-v3"/> <br/>
/// <list type="table">
/// <item>
/// <term>params</term>
Expand All @@ -134,7 +135,7 @@ public async Task<Ticker> FetchTicker(string symbol, Dictionary<string, object>
/// fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
/// </summary>
/// <remarks>
/// See <see href="https://developer-pro.bitmart.com/en/spot/#get-ticker-of-all-pairs-v2"/> <br/>
/// See <see href="https://developer-pro.bitmart.com/en/spot/#get-ticker-of-all-pairs-v3"/> <br/>
/// <list type="table">
/// <item>
/// <term>params</term>
Expand Down
Loading

0 comments on commit 45e4075

Please sign in to comment.