示例#1
0
def API_Get_AccountInfo(recvWindow=5000):
    ValidateAPIKey()

    timeStamp = GetTimeStamp()
    # totalParams = "recvWindow=" + str(recvWindow) + "&timestamp=" + timeStamp
    totalParams = "timestamp=" + timeStamp
    # PrintAndLog("totalParams = " + totalParams)
    signature = GetBinanceSignature(totalParams)
    # PrintAndLog("signature = " + signature)

    url = URL_Binance_Base + "v3/account?" + totalParams + "&signature=" + signature
    PrintAndLog("url = " + url)

    response = requests.get(url,
                            headers=GetBinanceHeader(),
                            timeout=RequestTimeout_seconds)
    if response.ok:
        responseData = response.content
        jData = json.loads(responseData)

        # PrintAndLog("API_Get_AccountInfo_Binance jData = " + str(jData))
        return jData

    else:
        # If response code is not ok (200), print the resulting http error code with description
        PrintAndLog("response = " + str(response.content))
        response.raise_for_status()
示例#2
0
def API_Post_GetWithdrawHistory(recvWindow=5000):
    ValidateAPIKey()

    timeStamp = GetTimeStamp()
    totalParams = "recvWindow=" + str(recvWindow) + "&timestamp=" + timeStamp
    # PrintAndLog("totalParams = " + totalParams)
    signature = GetBinanceSignature(totalParams)
    # PrintAndLog("signature = " + signature)

    url = "https://www.binance.com/wapi/v1/getWithdrawHistory.html?" + totalParams + "&signature=" + signature  # returns me weird stuff
    PrintAndLog("url = " + url)

    response = requests.post(url,
                             headers=GetBinanceHeader(),
                             timeout=RequestTimeout_seconds)
    if response.ok:
        responseData = response.content
        jData = json.loads(responseData)

        PrintAndLog("API_Post_GetWithdrawHistory jData = " + str(jData))
        return jData

    else:
        # If response code is not ok (200), print the resulting http error code with description
        PrintAndLog("response = " + str(response.content))
        response.raise_for_status()
示例#3
0
def API_Delete_Order(symbol, orderId, recvWindow=5000):
    ValidateAPIKey()

    timeStamp = GetTimeStamp()
    totalParams = "symbol=" + symbol.upper() + "&orderId=" + str(
        orderId) + "&recvWindow=" + str(recvWindow) + "&timestamp=" + timeStamp
    # PrintAndLog("totalParams = " + totalParams)
    signature = GetBinanceSignature(totalParams)
    # PrintAndLog("signature = " + signature)

    url = URL_Binance_Base + "v3/order?" + totalParams + "&signature=" + signature
    PrintAndLog("url = " + url)

    response = requests.delete(url,
                               headers=GetBinanceHeader(),
                               timeout=RequestTimeout_seconds)
    if response.ok:
        responseData = response.content
        jData = json.loads(responseData)

        PrintAndLog("API_Delete_Order_Binance jData = " + str(jData))
        return jData

    else:
        # If response code is not ok (200), print the resulting http error code with description
        PrintAndLog("response = " + str(response.content))
        response.raise_for_status()
示例#4
0
def API_Post_MarketOrder(symbol,
                         side,
                         quantity,
                         icebergQty=None,
                         stopPrice=None,
                         recvWindow=5000):
    ValidateAPIKey()

    timeStamp = GetTimeStamp()

    if side.lower() == "buy" or side.lower() == "sell":
        side = side.upper()

    else:
        raise ValueError('side must be either buy or sell')

    # quantity must be rounded to two decimal places
    quantity = str(round(float(quantity), 0))

    totalParams = "symbol=" + symbol.upper(
    ) + "&side=" + side + "&type=MARKET&quantity=" + str(
        quantity) + "&recvWindow=" + str(
            recvWindow) + "&timestamp=" + timeStamp

    if icebergQty:
        totalParams += "&icebergQty=" + str(icebergQty)

    if stopPrice:
        totalParams += "&stopPrice=" + str(stopPrice)

    # PrintAndLog("totalParams = " + totalParams)
    signature = GetBinanceSignature(totalParams)
    # PrintAndLog("signature = " + signature)

    url = URL_Binance_Base + "v3/order?" + totalParams + "&signature=" + signature
    PrintAndLog("url = " + url)

    response = requests.post(url,
                             headers=GetBinanceHeader(),
                             timeout=RequestTimeout_seconds)
    if response.ok:
        responseData = response.content
        jData = json.loads(responseData)

        PrintAndLog("API_Post_MarketOrder_Binance jData = " + str(jData))
        return jData

    else:
        # If response code is not ok (200), print the resulting http error code with description
        PrintAndLog("response = " + str(response.content))
        response.raise_for_status()
示例#5
0
def API_Get_Ping():
    url = URL_Binance_Base + "v1/ping"
    PrintAndLog("url = " + url)

    response = requests.get(url, timeout=RequestTimeout_seconds)
    if response.ok:
        responseData = response.content
        jData = json.loads(responseData)

        PrintAndLog("API_Get_Ping_Binance jData = " + str(jData))
        return jData

    else:
        # If response code is not ok (200), print the resulting http error code with description
        response.raise_for_status()
示例#6
0
 def run(*args):
     for i in range(60):
         time.sleep(1)
         # ws.send("Hello %d" % i)
     time.sleep(1)
     ws.close()
     PrintAndLog("thread terminating...")
示例#7
0
def API_Get_AggregateTrades(symbol, recvWindow=5000):
    url = URL_Binance_Base + "v1/aggTrades?symbol=" + str(symbol)

    PrintAndLog("url = " + url)

    response = requests.get(url, timeout=RequestTimeout_seconds)
    if response.ok:
        responseData = response.content
        jData = json.loads(responseData)

        PrintAndLog("API_Get_AggregateTrades_Binance jData = " + str(jData))
        return jData

    else:
        #  If response code is not ok (200), print the resulting http error code with description
        PrintAndLog("response = " + str(response.content))
        response.raise_for_status()
示例#8
0
def API_Get_KlineCandlestick(symbol, interval):
    url = URL_Binance_Base + "v1/klines?symbol=" + str(
        symbol) + "&interval=" + str(interval)
    PrintAndLog("url = " + url)

    response = requests.get(url, timeout=RequestTimeout_seconds)
    if response.ok:
        responseData = response.content
        jData = json.loads(responseData)

        PrintAndLog("API_Get_KlineCandlestick_Binance jData = " + str(jData))
        return jData

    else:
        # If response code is not ok (200), print the resulting http error code with description
        PrintAndLog("response = " + str(response.content))
        response.raise_for_status()
示例#9
0
def API_Get_24TickerPriceChange(symbol):
    url = URL_Binance_Base + "v1/ticker/24hr?symbol=" + str(symbol)
    PrintAndLog("url = " + url)

    response = requests.get(url, timeout=RequestTimeout_seconds)
    if response.ok:
        responseData = response.content
        jData = json.loads(responseData)

        PrintAndLog("API_Get_24TickerPriceChange_Binance jData = " +
                    str(jData))
        return jData

    else:
        # If response code is not ok (200), print the resulting http error code with description
        PrintAndLog("response = " + str(response.content))
        response.raise_for_status()
示例#10
0
def API_Get_Markets():
    url = URL_Binance_Base + "v1/ticker/allPrices"
    PrintAndLog("url = " + url)
    # headers_local = {'content-type': 'application/json'}

    # response = requests.get(url, headers=headers_local, timeout=RequestTimeout_seconds)
    response = requests.get(url, timeout=RequestTimeout_seconds)
    if response.ok:
        responseData = response.content
        jData = json.loads(responseData)

        # PrintAndLog("API_Get_Markets_Binance jData = " + str(jData))
        return jData

    else:
        # If response code is not ok (200), print the resulting http error code with description
        response.raise_for_status()
示例#11
0
def on_close(ws):
    PrintAndLog("### closed ###")
示例#12
0
def on_error(ws, error):
    PrintAndLog(str(error))
示例#13
0
def on_message(ws, message):
    PrintAndLog(str(message))
示例#14
0
# Get current Time
binance.API_Get_Time()

# TODO, Comment things in below as you'd like to test them

# Get orders for a symbol
# orders = binance.API_Get_Orders("BNBETH")
# PrintAndLog("orders = " + str(orders))

# Get the top n bid/ask orders for a symbol
topNBids = binance.API_Get_TopNOrders("BNBETH", 10, "bids")
topNAsks = binance.API_Get_TopNOrders("BNBETH", 10, "asks")
# Or get the top n bid/ask in one call
topNBids, topNAsks = binance.API_Get_TopNOrders("BNBETH", 10, "both")
PrintAndLog("topNBids = " + str(topNBids))
PrintAndLog("topNAsks = " + str(topNAsks))

# Get account info, free/locked balances, etc
# allInfo = binance.API_Get_AccountInfo()
# PrintAndLog("allInfo = " + str(allInfo))

# Get free/locked balances for an asset
# balance_bnb = binance.API_Get_Balance("bnb")
# balance_eth = binance.API_Get_Balance("eth")
# PrintAndLog("balance_bnb = " + str(balance_bnb))
# PrintAndLog("balance_eth = " + str(balance_eth))

# # Get all prices
# markets = binance.API_Get_Markets()
# PrintAndLog("markets = " + str(markets))