Beispiel #1
0
def fetchBuyOrderList():
    filename = InitService.getBuyOrderFileLocation()
    if commonService.checkIfFileExists(filename):
        with open(filename) as json_file:
            JSONFromFile = json.load(json_file)
            buyOrderList = ConvertToList(JSONFromFile)
            return buyOrderList
Beispiel #2
0
def checkBuyOrdersForExecution(quoteResponseList):
    print(
        datetime.datetime.now().isoformat() +
        " ##### BuyOrderService: Checking if virtual buy orders to swap #####")
    # Validate if an outstanding virtual buy order is greater then recent quote
    for quoteResponse in quoteResponseList:
        for buyOrderListPair in fetchBuyOrderList():
            for pair, buyOrderList in buyOrderListPair.items(
            ):  # pair = key; buyOrderList = value
                modifiedBuyOrderlist = []
                for index, buyOrder in enumerate(buyOrderList):
                    if float(buyOrder.buyprice) > float(
                            quoteResponse.toAmount):
                        print(
                            datetime.datetime.now().isoformat() +
                            " ##### BuyOrderService: !!HIT!! Quote price [[" +
                            str(quoteResponse.toAmount) +
                            "]] is below Virtual Buy Order price [[" +
                            str(buyOrder.buyprice) + "]] for pair <" + pair +
                            ">. #####")
                        #SellOrderService.swapToSellOrder(buyOrder, quoteResponse)
                        swapService.swapBuyOrder(buyOrder, quoteResponse)
                    else:
                        print(datetime.datetime.now().isoformat() +
                              " ##### BuyOrderService: Quote price [[" +
                              str(quoteResponse.toAmount) +
                              "]] is above Virtual Buy Order price [[" +
                              str(buyOrder.buyprice) + "]] for pair <" + pair +
                              ">. #####")
                        # BuyOrder remains valid therefore appended to the ModifiedBuyOrderList
                        # for testing only swapService.swapBuyOrder(buyOrder, quoteResponse)
                        modifiedBuyOrderlist.append(buyOrder)
                # Now replace the buyOrderList with the modifiedBuyOrderList
                buyOrderListPair[pair] = modifiedBuyOrderlist
            newOutStandingBuyOrderList = []
            newOutStandingBuyOrderList.append(buyOrderListPair)
        commonService.writeJson(InitService.getBuyOrderFileLocation(),
                                newOutStandingBuyOrderList)
Beispiel #3
0
def placeVirtualBuyorders():
    print(datetime.datetime.now().isoformat() +
          " ##### BuyOrderService: Actualising BuyOrderList #####")
    # Fetch a list of trading pairs for which quotes should be fetched
    tradingPairList = tradingPairService.FetchTradingPairs()
    # now loop trough the list of tradingPair objects
    outStandingBuyOrderList = []
    for tradingPair in tradingPairList:
        lastQuoteResponses = quoteService.fetchRecentQuotes(1)
        buyOrderPairList = calculateBuyOrderList(lastQuoteResponses,
                                                 tradingPair)
        pair = tradingPair.swapToken + tradingPair.baseToken
        pairToAdd = {}
        pairToAdd[pair] = {}
        pairToAdd[pair] = buyOrderPairList
        outStandingBuyOrderList.append(pairToAdd)
    # Now actualise the buyOrderList JSON file
    commonService.writeJson(InitService.getBuyOrderFileLocation(),
                            outStandingBuyOrderList)
    print(datetime.datetime.now().isoformat() +
          " ##### BuyOrderService: BuyOrderList actualised #####")
    # TODO: Return full list, not only actualised ones but also ones for which no pair is active
    return outStandingBuyOrderList