You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to get all the trades in Kucoin SINCE a timestamp.
I have tried my code with Binance and it works perfectly, but when I try with Kucoin, it gets only the last trades, and it ignores the SiNCE param.
I am using this function to get the number of trades made in each on of the last 10 candlestick in a 1 minute timeframe.
In my code, I show you the execution os this idea twice, first one for Binance exchange (it works ok, using SINCE param), and the second one for Kucoin exchange (it only get 100 trades, ignoring SINCE param).
NOTE: For Binance you must use a valid APIKEY and APISECRET
For Kucoin, this both vars can be empty
If there is another approach to get the same information for kucoin exchange, any help will be appreciated.
Thanks in advance
Code
import ccxt
import os
import sys
from datetime import datetime
from pandas import to_datetime
from pprint import pprint
import APIS
def calculaNTrades10Velas (trades, trades_per_candle1):
j = 1
for trade in trades:
candle_timestamp = minutosYMicrosegundosACero(trade['timestamp'])
if candle_timestamp in trades_per_candle1:
trades_per_candle1[candle_timestamp] += 1
else:
trades_per_candle1[candle_timestamp] = 1
j += 1
return
def minutosYMicrosegundosACero(tiempo1):
tiempo1dt = to_datetime(tiempo1, unit='ms').replace(second=0, microsecond=0) #Quitamos segundos y quitamos ms
t2 = tiempo1dt.timestamp() * 1000
return t2
def tiempoTiempoEnHHMMSSMS(timestamp1):
t1dt = datetime.fromtimestamp(timestamp1/1000)
t1dt_format = t1dt.strftime('%H:%M:%S.%f')
return t1dt_format
def mainLoop(exchangeNombre):
#exchangeNombre = 'K' # If exchangeNombre = 'K' it doesn´t work
#exchangeNombre = 'B' # If exchangeNombre = 'B' it works OK
# exchangeNombre Will be a parameter so in Main, this function will be executed twice:
# - once with param exchangeNombre = 'B' for Binance, it WORKS
# - once with param exchangeNombre = 'K' for Kucoin, it DOESN't WORK
if (exchangeNombre == 'K'):
print('EXCHANGE: Kucoin')
exchange_name = 'kucoin'
apiKey = APIS.apiKey_K # Use your APIKEY for Kucoin
apiSecret = APIS.apiSecret_K # Use your APISECRET for Kucoin
symbol = 'BTC/USDT' # change for your symbol
elif (exchangeNombre == 'B'):
print('EXCHANGE: Binance')
exchange_name = 'binance'
apiKey = APIS.apiKey_B # Use your APIKEY for Binance
apiSecret = APIS.apiSecret_B # Use your APISECRET for Binance
symbol = 'BTC/USDT' # change for your symbol
exchange = getattr (ccxt, exchange_name) ({
'apiKey': apiKey,
'secret': apiSecret,
'enableRateLimit': True,
'options': {
'fetchTradesMethod': 'publicGetHistoricalTrades',
},
})
all_trades = []
tiempoExchange = exchange.milliseconds ()
since = tiempoExchange - (10 * 60 * 1000) # TIme to Begin the Candles: 10 minutes before now
last_trade = {}
nIteracion = 1
while since < tiempoExchange:
#print('Tiempo Since: ', to_datetime(since, unit='ms'), ' NO (UTC)')
limit = 1000 # change for your limit
trades = exchange.fetch_trades(symbol, since, limit)
# HERE IS THE FAIL WITH THE SINCE PARAMETER for KUCOIN
if len(trades):
since = trades[len(trades) - 1]['timestamp'] + 1
all_trades += trades
else:
# No more trades, we go out of the while loop
break
nIteracion += 1
#Calculate number of trades for each one of the 10 candlesticks before now
trades_per_candle = {}
calculaNTrades10Velas(all_trades, trades_per_candle)
sorted_candles = sorted(trades_per_candle.items())
j = 1
for candle_timestamp, num_trades in sorted_candles:
print(f'Candle ({j}) - TimeStamp: ', tiempoTiempoEnHHMMSSMS(candle_timestamp), ' - Nº Trades: ', num_trades)
j += 1
def main():
print ('First Exchange: BINANCE')
mainLoop('B')
print('\n\n')
print ('Second Exchange: KUCOIN')
mainLoop('K')
main()
The text was updated successfully, but these errors were encountered:
germanrp1
changed the title
Kucoin fetch_trades ignores SINCE param
Kucoin fetch_trades ignores SINCE param, but it works for BINANCE
Apr 17, 2024
Operating System
windows
Programming Languages
Python
CCXT Version
4.2.86
Description
I am trying to get all the trades in Kucoin SINCE a timestamp.
I have tried my code with Binance and it works perfectly, but when I try with Kucoin, it gets only the last trades, and it ignores the SiNCE param.
I am using this function to get the number of trades made in each on of the last 10 candlestick in a 1 minute timeframe.
In my code, I show you the execution os this idea twice, first one for Binance exchange (it works ok, using SINCE param), and the second one for Kucoin exchange (it only get 100 trades, ignoring SINCE param).
NOTE: For Binance you must use a valid APIKEY and APISECRET
For Kucoin, this both vars can be empty
If there is another approach to get the same information for kucoin exchange, any help will be appreciated.
Thanks in advance
Code
The text was updated successfully, but these errors were encountered: