Skip to content

Commit 2af4fb1

Browse files
Dan-krmcarlosmiei
andauthored
new method: fetchConvertQuote (ccxt#22055)
* feat(bitget): fetchConvertQuote ``` bitget.fetchConvertQuote (USDC, USDT, 3) 2024-04-05T10:15:14.774Z iteration 0 passed in 301 ms { info: { fromCoin: 'USDC', fromCoinSize: '3', cnvtPrice: '0.9989001', toCoin: 'USDT', toCoinSize: '2.9967003', traceId: '1160086588191326208', fee: '0' }, id: '1160086588191326208', fromCurrency: 'USDC', fromAmount: 3, toCurrency: 'USDT', toAmount: 2.9967003, price: 0.9989001, fee: 0 } ``` * test(bitget): static request, fetchConvertQuote * feat(woo): fetchConvertQuote ### Woo: ``` {"success":false,"code":-1027,"message":"java.net.SocketTimeoutException: connect timed out"} ``` * feat(okx): fetchConvertQuote ``` [ExchangeError] okx {"code":"52911","data":[],"msg":"RFQ service unavailable, please try again later"} ``` * set fetchConvertQuote to false on binance * feat(Manual): add fetchConvertQuote * Add Conversion type and fetchConvertQuote stubs * fix signature * fix eslint rules non used * fix syntax error, from variable name --------- Co-authored-by: carlosmiei <43336371+carlosmiei@users.noreply.github.com>
1 parent d14da7d commit 2af4fb1

File tree

15 files changed

+380
-9
lines changed

15 files changed

+380
-9
lines changed

build/export-exchanges.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ async function exportEverything () {
527527
const errorsExports = [...flat];
528528
flat.push ('error_hierarchy')
529529

530-
const typeExports = ['Market', 'Trade' , 'Fee', 'Ticker', 'OrderBook', 'Order', 'Transaction', 'Tickers', 'Currency', 'Balance', 'DepositAddress', 'WithdrawalResponse', 'DepositAddressResponse', 'OHLCV', 'Balances', 'PartialBalances', 'Dictionary', 'MinMax', 'Position', 'FundingRateHistory', 'Liquidation', 'FundingHistory', 'MarginMode', 'Greeks', 'Leverage', 'Leverages', 'Option', 'OptionChain' ]
530+
const typeExports = ['Market', 'Trade' , 'Fee', 'Ticker', 'OrderBook', 'Order', 'Transaction', 'Tickers', 'Currency', 'Balance', 'DepositAddress', 'WithdrawalResponse', 'DepositAddressResponse', 'OHLCV', 'Balances', 'PartialBalances', 'Dictionary', 'MinMax', 'Position', 'FundingRateHistory', 'Liquidation', 'FundingHistory', 'MarginMode', 'Greeks', 'Leverage', 'Leverages', 'Option', 'OptionChain', 'Conversion' ]
531531
const staticExports = ['version', 'Exchange', 'exchanges', 'pro', 'Precise', 'functions', 'errors'].concat(errorsExports).concat(typeExports)
532532

533533
const fullExports = staticExports.concat(ids)

build/transpile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ class Transpiler {
989989
'BalanceAccount': /-> BalanceAccount:/,
990990
'Balances': /-> Balances:/,
991991
'Bool': /: Bool =/,
992+
'Conversion': /-> Conversion:/,
992993
'Currencies': /-> Currencies:/,
993994
'Currency': /(-> Currency:|: Currency)/,
994995
'FundingHistory': /\[FundingHistory/,

cs/ccxt/base/Exchange.Types.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,35 @@ public Greeks(object greeks)
12561256
}
12571257

12581258

1259+
public struct Conversion
1260+
{
1261+
public Dictionary<string, object>? info;
1262+
public Int64? timestamp;
1263+
public string? datetime;
1264+
public string? id;
1265+
public string? fromCurrency;
1266+
public double? fromAmount;
1267+
public string? toCurrency;
1268+
public double? toAmount;
1269+
public double? price;
1270+
public double? fee;
1271+
1272+
public Conversion(object conversion)
1273+
{
1274+
info = Exchange.SafeValue(conversion, "info") != null ? (Dictionary<string, object>)Exchange.SafeValue(conversion, "info") : null;
1275+
timestamp = Exchange.SafeInteger(conversion, "timestamp");
1276+
datetime = Exchange.SafeString(conversion, "datetime"); ;
1277+
id = Exchange.SafeString(conversion, "id");
1278+
fromCurrency = Exchange.SafeString(conversion, "fromCurrency");
1279+
fromAmount = Exchange.SafeFloat(conversion, "fromAmount");
1280+
toCurrency = Exchange.SafeString(conversion, "toCurrency");
1281+
toAmount = Exchange.SafeFloat(conversion, "toAmount");
1282+
price = Exchange.SafeFloat(conversion, "price");
1283+
fee = Exchange.SafeFloat(conversion, "fee");
1284+
}
1285+
}
1286+
1287+
12591288
public struct MarketInterface
12601289
{
12611290

python/ccxt/async_support/base/exchange.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,9 @@ async def fetch_option_chain(self, code: str, params={}):
12801280

12811281
async def fetch_option(self, symbol: str, params={}):
12821282
raise NotSupported(self.id + ' fetchOption() is not supported yet')
1283+
1284+
async def fetch_convert_quote(self, fromCode: str, toCode: str, amount: float = None, params = {}):
1285+
raise NotSupported(self.id + ' fetch_convert_quote() is not supported yet')
12831286

12841287
async def fetch_deposits_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}):
12851288
"""

python/ccxt/base/types.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,19 @@ class Greeks(TypedDict):
311311
info: Dict[str, Any]
312312

313313

314+
class Conversion(TypedDict):
315+
info: Dict[str, Any]
316+
timestamp: Int
317+
datetime: Str
318+
id: Str
319+
fromCurrency: Str
320+
fromAmount: Num
321+
toCurrency: Str
322+
toAmount: Num
323+
price: Num
324+
fee: Num
325+
326+
314327
class Option(TypedDict):
315328
info: Dict[str, Any]
316329
currency: Str

ts/ccxt.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { Exchange } from './src/base/Exchange.js'
3333
import { Precise } from './src/base/Precise.js'
3434
import * as functions from './src/base/functions.js'
3535
import * as errors from './src/base/errors.js'
36-
import type { Market, Trade , Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks, Leverage, Leverages, Option, OptionChain } from './src/base/types.js'
36+
import type { Market, Trade , Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks, Leverage, Leverages, Option, OptionChain, Conversion } from './src/base/types.js'
3737
import {BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, ExchangeClosedByUser} from './src/base/errors.js'
3838

3939

@@ -477,6 +477,7 @@ export {
477477
Leverages,
478478
Option,
479479
OptionChain,
480+
Conversion,
480481
ace,
481482
alpaca,
482483
ascendex,

ts/src/.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"no-nested-ternary": "error",
4848
"eqeqeq": "error",
4949
"quotes": ["error", "single", { "avoidEscape": true }],
50-
"no-unused-vars": ["error", { "argsIgnorePattern": "^(exchange|headers|body|account|info|symbol|price|tag|side|since|limit|params|market|timeframe|api|path|code|currency|statusCode|statusText|url|method|response|requestHeaders|requestBody|bidsKey|asksKey|context|config|type|priceKey|amountKey|networkCode|marginMode|subscription|message|client|nonce|orderbook|bookside|deltas|delta|countOrIdKey)" }],
50+
"no-unused-vars": ["error", { "argsIgnorePattern": "^(exchange|headers|body|account|info|symbol|price|tag|side|since|limit|params|market|timeframe|api|path|code|currency|statusCode|statusText|url|method|response|requestHeaders|requestBody|bidsKey|asksKey|context|config|type|priceKey|amountKey|networkCode|marginMode|subscription|message|client|nonce|orderbook|bookside|deltas|delta|countOrIdKey|amount|fromCurrency|toCurrency)" }],
5151
"new-parens": "error",
5252
"new-cap": ["error"],
5353
"no-var": "error",

ts/src/base/Exchange.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ import { OrderBook as WsOrderBook, IndexedOrderBook, CountedOrderBook } from './
146146
//
147147
import { axolotl } from './functions/crypto.js';
148148
// import types
149-
import type { Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRate, DepositWithdrawFeeNetwork, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, BorrowRate, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, MarginModification, TradingFeeInterface, Currencies, TradingFees } from './types.js';
149+
import type { Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRate, DepositWithdrawFeeNetwork, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, BorrowRate, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion } from './types.js';
150150
// export {Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRateHistory, Liquidation, FundingHistory} from './types.js'
151151
// import { Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, FundingHistory, MarginMode, Tickers, Greeks, Str, Num, MarketInterface, CurrencyInterface, Account } from './types.js';
152-
export type { Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, BorrowRate, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings } from './types.js'
152+
export type { Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, BorrowRate, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, Conversion } from './types.js'
153153

154154
// ----------------------------------------------------------------------------
155155
// move this elsewhere.
@@ -531,6 +531,7 @@ export default class Exchange {
531531
'fetchClosedOrder': undefined,
532532
'fetchClosedOrders': undefined,
533533
'fetchClosedOrdersWs': undefined,
534+
'fetchConvertQuote': undefined,
534535
'fetchCrossBorrowRate': undefined,
535536
'fetchCrossBorrowRates': undefined,
536537
'fetchCurrencies': 'emulated',
@@ -5002,6 +5003,10 @@ export default class Exchange {
50025003
throw new NotSupported (this.id + ' fetchOption() is not supported yet');
50035004
}
50045005

5006+
async fetchConvertQuote (fromCode: string, toCode: string, amount: Num = undefined, params = {}): Promise<Conversion> {
5007+
throw new NotSupported (this.id + ' fetchConvertQuote() is not supported yet');
5008+
}
5009+
50055010
async fetchDepositsWithdrawals (code: Str = undefined, since: Int = undefined, limit: Int = undefined, params = {}): Promise<Transaction[]> {
50065011
/**
50075012
* @method
@@ -6317,7 +6322,11 @@ export default class Exchange {
63176322
}
63186323

63196324
parseLeverage (leverage, market: Market = undefined): Leverage {
6320-
throw new NotSupported (this.id + ' parseLeverage() is not supported yet');
6325+
throw new NotSupported (this.id + ' parseLeverage () is not supported yet');
6326+
}
6327+
6328+
parseConversion (conversion, fromCurrency: Currency = undefined, toCurrency: Currency = undefined): Conversion {
6329+
throw new NotSupported (this.id + ' parseConversion () is not supported yet');
63216330
}
63226331

63236332
convertExpireDate (date: string): string {

ts/src/base/types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,19 @@ export interface Greeks {
471471
info: any;
472472
}
473473

474+
export interface Conversion {
475+
info: any;
476+
timestamp?: number
477+
datetime?: string;
478+
id: string;
479+
fromCurrency: string;
480+
fromAmount: number;
481+
toCurrency: string;
482+
toAmount: number;
483+
price: number;
484+
fee: number;
485+
}
486+
474487
export interface Option {
475488
info: any;
476489
currency: string;

ts/src/binance.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export default class binance extends Exchange {
7373
'fetchCanceledOrders': 'emulated',
7474
'fetchClosedOrder': false,
7575
'fetchClosedOrders': 'emulated',
76+
'fetchConvertQuote': false,
7677
'fetchCrossBorrowRate': true,
7778
'fetchCrossBorrowRates': false,
7879
'fetchCurrencies': true,

0 commit comments

Comments
 (0)