I used this code: import time from binance.client import Client from binance.enums…
- User
I used this code: `import time from binance.client import Client from binance.enums import * from binance.exceptions import BinanceAPIException import pandas as pd import requests import json import numpy as np import pytz import datetime as dt import asyncio
date = dt.datetime.now().strftime("%m/%d/%Y %H:%M:%S") print(date)
url = "https://api.binance.com/api/v1/time" t = time.time()*1000 r = requests.get(url) result = json.loads(r.content)
API keys and other configuration
API_KEY = '' API_SECRET = ''
client = Client(API_KEY, API_SECRET)
STOP_LOSS_PERCENTAGE = -50 TAKE_PROFIT_PERCENTAGE = 100 MAX_TRADE_QUANTITY_PERCENTAGE = 100 POSITION_SIDE_SHORT = 'SELL' POSITION_SIDE_LONG = 'BUY' symbol = 'BTCUSDT' quantity = 1 order_type = 'MARKET' leverage = 125 max_trade_quantity_percentage = 1
client = Client(API_KEY, API_SECRET)
async def getminutedata(symbol, interval, lookback): klines = client.futures_historical_trades(symbol=symbol,interval=interval, limit=lookback, endTime=int(time.time()*1000)) # Cast tuples to lists klines = [list(map(str, kline)) for kline in klines] frame = pd.DataFrame(klines, columns=['Open time', 'Price', 'Qty', 'QuoteQty', 'Time', 'Buyer Maker', 'Best Match']) frame = frame[['Open time', 'Price', 'Qty']] frame['Open time'] = pd.to_datetime(frame['Open time'], unit='ms').dt.tz_localize('UTC').dt.tz_convert('Etc/GMT+3') frame.set_index('Open time', inplace=True) frame.drop(frame.tail(1).index, inplace=True) # Drop the last candle we fetched return frame
df = getminutedata('BTCUSDT', '1m', 44640)
def signal_generator(df): open = df.Price.iloc[-1] close = df.Price.iloc[-1] previous_open = df.Price.iloc[-2] previous_close = df.Price.iloc[-2]
code# Bearish pattern if (open>close and previous_open<previous_close and close<previous_open and open>=previous_close): return 'sell' # Bullish pattern elif (open<close and previous_open>previous_close and close>previous_open and open<=previous_close): return 'buy' # No clear pattern else: return ''def order_execution(symbol, signal, max_trade_quantity_percentage, leverage): signal = signal_generator(df) max_trade_quantity = None account_balance = client.futures_account_balance() usdt_balance = float([x['balance'] for x in account_balance if x['asset'] == 'USDT'][0]) max_trade_quantity = usdt_balance * max_trade_quantity_percentage/100
code - Assistant
- User
When I wrighting df = await getminutedata('BTCUSDT', '1m', 44640) , what I need to do ?
- Assistant
When you write
df = await getminutedata('BTCUSDT', '1m', 44640), you are calling thegetminutedatafunction asynchronously using theawaitkeyword. This means that the function will run in the background and the program will continue executing other statements while it's waiting for the function to complete.Once the function completes and returns a value, it will be assigned to the
dfvariable, which you can then use in the rest of your program.In the example code I provided, the
getminutedatafunction is being called inside theorder_executionandtrading_loopfunctions, which are both asynchronous functions. So, you need theawaitkeyword in front of the function call to ensure that the program waits for the function to complete before moving on to the next statement.