Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lbank exchange :Order failed: Invalid Trading Pair #23577

Closed
cqs10151 opened this issue Aug 29, 2024 · 8 comments
Closed

lbank exchange :Order failed: Invalid Trading Pair #23577

cqs10151 opened this issue Aug 29, 2024 · 8 comments
Assignees
Labels

Comments

@cqs10151
Copy link

Operating System

ubuntu 22.0.4

Programming Languages

Python

CCXT Version

4.3.90 and 4.3.88

Description

Use load_markets to check that there is a trade pair (doge/usdt), but place an order with the market price, and there is no trade pair
e

Code

  import ccxt
import time
from datetime import datetime, timedelta

# Function to validate the trading pair
def validate_pair(exchange, pair):
    markets = exchange.load_markets()
    return pair in markets

def check_balance(exchange, currency='USDT'):
    balance = exchange.fetch_balance()
    available_balance = balance['free'].get(currency, 0)
    return available_balance

# Example usage:
#available_usdt = check_balance(exchange)
#print(f"Available USDT balance: {available_usdt}")


# Function to place the order
def place_order(exchange, pair, usdt_amount):
    # Check the available balance first
    available_usdt = check_balance(exchange)
    if available_usdt < usdt_amount:
        print(f"Adjusting USDT amount to available balance: {available_usdt}")
        usdt_amount = available_usdt

    try:
        order = exchange.create_order(pair, 'market', 'buy', usdt_amount)
        print("Order placed successfully:", order)
        return True
    except Exception as e:
        print("Order failed:", str(e))
        return False

# Function to get the server time
def get_server_time(exchange):
    server_time = exchange.fetch_time()
    return datetime.utcfromtimestamp(server_time / 1000.0)

# Main script
def main():
    # Replace with your LBANK API credentials
    api_key = 'xxxxxx'
    secret = 'xxxxxx'


    # Initialize the exchange
    exchange = ccxt.lbank({
        'apiKey': api_key,
        'secret': secret,
        'enableRateLimit': True,
        'options': {
            'createMarketBuyOrderRequiresPrice': False,
        },
    })

    # Get and print the server time
    server_time = get_server_time(exchange)
    print(f"Server time: {server_time.strftime('%Y-%m-%d %H:%M:%S.%f')} UTC")

    # Step 1: Input and validate trading pair
    while True:
        pair = input("Enter the trading pair (e.g., BTC/USDT): ").upper()
        if validate_pair(exchange, pair):
            print(f"Trading pair {pair} is valid.")
            break
        else:
            print(f"Trading pair {pair} is invalid. Please try again.")

    # Step 2: Input USDT amount
    usdt_amount = float(input("Enter the total USDT amount to buy: "))

    # Step 3: Input time for order (including milliseconds)
    target_time_str = input("Enter the target time (HH:MM:SS.mmm): ")
    try:
        target_time = datetime.strptime(target_time_str, "%H:%M:%S.%f")
    except ValueError:
        print("Invalid time format! Please use the format HH:MM:SS.mmm (e.g., 16:49:50.100000)")
        return

    # Adjust target time to include the same date as the server time
    target_time = server_time.replace(hour=target_time.hour, minute=target_time.minute, second=target_time.second, microsecond=target_time.microsecond)

    # Countdown until target time with synchronized server time
    while True:
        server_time = get_server_time(exchange)
        if server_time >= target_time:
            print(f"\nTarget time reached: {target_time}. Starting order placement...")
            break
        else:
            remaining_time = (target_time - server_time).total_seconds()
            print(f"Server time: {server_time.strftime('%Y-%m-%d %H:%M:%S.%f')} UTC | Time remaining: {remaining_time:.3f} seconds", end='\r')
            time.sleep(0.001)  # Sleep for 1 millisecond to reduce CPU usage

    # Step 4: Attempt to place the order 5 times if necessary
    for attempt in range(10):
        print(f"\nAttempt {attempt   1} to place the order...")
        if place_order(exchange, pair, usdt_amount):
            break
        else:
            print(f"Retrying in 0.3 second...")
            time.sleep(0.3)

if __name__ == "__main__":
    main()



@carlosmiei
Copy link
Collaborator

Hello @cqs10151, the unified symbol is DOGE/USDT (uppercase) and not doge/usdt. You can also use the exchange-specific id, doge_usdt in this case

n lbank market "DOGE/USDT"
2024-08-29T13:56:40.027Z
Node.js: v18.18.0
CCXT v4.3.90
lbank.market (DOGE/USDT)
2024-08-29T13:56:40.984Z iteration 0 passed in 0 ms

{
  id: 'doge_usdt',
  symbol: 'DOGE/USDT',
  base: 'DOGE',
  quote: 'USDT',
  baseId: 'doge',
  quoteId: 'usdt',
  type: 'spot',
  spot: true,
  margin: false,
  swap: false,
  future: false,
  option: false,
  active: true,
  contract: false,
  taker: 0.001,
  maker: 0.001,
  precision: { amount: 1, price: 0.00001 },
  limits: { leverage: {}, amount: { min: 6 }, price: {}, cost: {} },
  info: {
    symbol: 'doge_usdt',
    quantityAccuracy: '0',
    minTranQua: '6',
    priceAccuracy: '5'
  }
}

@carlosmiei carlosmiei self-assigned this Aug 29, 2024
@cqs10151
Copy link
Author

Thanks for the answer, but it's still wrong

Server time: 2024-08-29 14:09:23.960000 UTC
Enter the trading pair (e.g., BTC/USDT): doge_usdt
Trading pair DOGE_USDT is invalid. Please try again.
Enter the trading pair (e.g., BTC/USDT): DOGE/USDT
Trading pair DOGE/USDT is valid.
Enter the total USDT amount to buy: 10
Enter the target time (HH:MM:SS.mmm): 14:10:00.000001

Target time reached: 2024-08-29 14:10:00.000001. Starting order placement...

Attempt 1 to place the order...
Order failed: Invalid Trading Pair
Retrying in 0.3 second...

Attempt 2 to place the order...
Order failed: Invalid Trading Pair
Retrying in 0.3 second...

@cqs10151
Copy link
Author

Is there anyone familiar with the LBANK API?

@carlosmiei
Copy link
Collaborator

@cqs10151 I think that means that the market is disabled for trading through the API

@cqs10151
Copy link
Author

Thank you all, it's the exchange's problem, today any code has not changed to run successfully once.

@behzadev
Copy link

This is happening for every trading pair other than LBK/USDT, I contacted their online support, it seems we need to whitelist our IPs for trading other pairs using their API. They asked me to send them an email, no reply yet. @cqs10151 is this the cause? I can place orders on lbk_usdt, but no other pairs. I get this response:

{"msg":"currency pair nonsupport","result":false,"error_code":10008,"ts":1726588243906}

@wisfern
Copy link

wisfern commented Nov 1, 2024

I also encountered this problem

@carlosmiei
Copy link
Collaborator

@wisfern Unfortunately, there's nothing ccxt can do about it because the exchange itself is disabling trading in most markets through the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants