ccxt icon indicating copy to clipboard operation
ccxt copied to clipboard

Following orderbook top asks/bids book with limit order (Bitfinex)(Python)

Open 4budab1 opened this issue 8 years ago • 1 comments

  • OS: Windows 10 x64 Pro
  • Programming Language version: Python 3.6.4
  • CCXT version: 1.12.176
  • Exchange: Bitfinex
  • Method:

Following code Going Long only with Limit post only orders with amount depends on "Target_of_coinsUSDT"

In first while loop my code place a order, this part work ok

second while loop checks if our limit order price. This code worked on Bitmex correctly, but on Bitfinex it gives error File "C:\Users\DMMaxim\Desktop\BITFINEX_ETHUSD_1H.py", line 155, in trader bitfinex.edit_order(resultLong['id'],market,'limit',resultLong['side'],price = BestBid) TypeError: edit_order() got an unexpected keyword argument 'price'

#LONG SIDE BITFINEX issue with edit_order
        if (Target_of_coinsUSDT > 10):
                while True:
                        print('bitfinex Going LONG with USDT and coins amount:',Target_of_coinsUSDT,'$ ',Target_of_coins,market)
                        try:
                                bitfinex.privatePostOrderCancelAll()
                                orderbookLong = bitfinex.fetch_order_book(market)
                                BasicBid = orderbookLong['bids'][0][0] if len (orderbook['bids']) > 0 else None
                                resultLong = bitfinex.create_order(symbol=market, type='limit', side='buy', amount=Target_of_coins, price = BasicBid, params = paramsBitfinex)
                                break
                        except (ccxt.ExchangeError, ccxt.NetworkError) as error:
                                print('Got an error placing Long', type(error).__name__, error.args)
                                time.sleep(1)
                                continue
                        
                while(Target_of_coinsUSDT > 10):
                        print('bitfinex amending LONG with:', Target_of_coins)
                        try:
                                while True:
                                        CurrentOpenOrderPrice = bitfinex.fetchOpenOrders()[0]['price']
                                        print('CurrentOpenOrderPrice:',CurrentOpenOrderPrice)
                                        orderbookLong = bitfinex.fetch_order_book (market)
                                        BestBid = orderbookLong['bids'][0][0] if len (orderbook['bids']) > 0 else None
                                        print('BestBid:',BestBid)
                                        if (BestBid != CurrentOpenOrderPrice):
                                                #bitfinex.private_post_order_cancel_replace(id = resultLong['id'], symbol = 'market', amount = 'Target_of_coins', price = 'BestBid', exchange = 'bitfinex', type = 'limit', side = 'buy', is_hidden = 'false', is_postonly = 'true', use_remaining = 'true')
                                                bitfinex.edit_order(resultLong['id'],market,'limit',resultLong['side'],price = BestBid)
                                                print('======Price changed to', BestBid)
                                                time.sleep(2)
                                        tempLongID = resultLong['id']
                                        print('resultLong id',resultLong['id'])
                                        time.sleep(1)
                                if (resultLong['id'] != tempLongID):
                                                break
                        except (ccxt.ExchangeError, ccxt.NetworkError) as error:
                                print('Got an error in amending price Long:', type(error).__name__, error.args)
                                time.sleep(1)
                                continue
                        except (IndexError) as error:
                                print('Order Long filled', type(error).__name__, error.args)
                                break
        #LONG SIDE BITMEX -- this code working fine
        if (contracts_amount > 100):
                while True:
                        try:
                                #bitmex.privateDeleteOrderAll ()
                                orderbookLong = bitmex.fetch_order_book (market)
                                BasicBid = orderbookLong['bids'][0][0] if len (orderbook['bids']) > 0 else None
                                resultLong = bitmex.create_order(symbol='BTC/USD', type='limit', side='buy', amount=contracts_amount, price=BasicBid, params = post_only)
                                break
                        except (ccxt.ExchangeError, ccxt.NetworkError) as error:
                                print('Got an error placing Long', type(error).__name__, error.args)
                                time.sleep(1)
                                continue
                        
                while(contracts_amount > 100):
                        print("BITMEX Goind LONG with:", contracts_amount)
                        try:
                                while True:
                                        CurrentOpenOrderPrice = bitmex.fetchOpenOrders()[0]['price']
                                        print('CurrentOpenOrderPrice:',CurrentOpenOrderPrice)
                                        orderbookLong = bitmex.fetch_order_book (market)
                                        BestBid = orderbookLong['bids'][0][0] if len (orderbook['bids']) > 0 else None
                                        print('BestBid:',BestBid)
                                        if (BestBid != CurrentOpenOrderPrice):
                                                bitmex.edit_order(resultLong['id'],'BTC/USD','limit',resultLong['side'],price=BestBid)
                                                print('======Price changed to', BestBid)
                                                time.sleep(0.5)
                                        tempLongID = resultLong['id']
                                        print('resultLong id',resultLong['id'])
                                        time.sleep(1)
                                if (resultLong['id'] != tempLongID):
                                                break
                        except (ccxt.ExchangeError, ccxt.NetworkError) as error:
                                print('Got an error in amending price Long:', type(error).__name__, error.args)
                                time.sleep(1)
                                continue
                        except (IndexError) as error:
                                print('Order Long filled', type(error).__name__, error.args)
                                break

4budab1 avatar Apr 16 '18 20:04 4budab1

# change to this and read more about positional arguments vs named arguments (kwargs) in Python
bitmex.edit_order(resultLong['id'],'BTC/USD','limit',resultLong['side'],BestBid)

Let us know if it does not help.

kroitor avatar Apr 17 '18 01:04 kroitor