Exemplo n.º 1
0
def TransactionsTransactionDetails(access_token, accountID, transactionID):
    'Get the details of a single Account Transaction.'
    r = transactions.TransactionDetails(accountID=accountID,
                                        transactionID=transactionID)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
 def updateids(self, instrument, granularity):
     df = self.getids()
     csvID = self.getid(granularity, instrument)
     params = {"instrument": instrument}
     o = orders.OrderList(self.accountID, params=params)
     t = trades.TradesList(self.accountID, params=params)
     self.client.request(o)
     self.client.request(t)
     orderlist = [x['id'] for x in o.response['orders']]
     tradelist = [x['id'] for x in t.response['trades']]
     if csvID[0] in orderlist:
         return
     elif csvID[0] in tradelist:
         return
     else:
         for x in tradelist:
             p = {'id': x}
             t = trans.TransactionDetails(self.accountID, p['id'])
             self.client.request(t)
             orderID = t.response['transaction']['orderID']
             if orderID == csvID[0]:
                 if csvID[1] == 0:
                     df.loc[granularity, instrument]['Consolidating'] = x
                 elif csvID[1] == 1:
                     df.loc[granularity, instrument]['Trending'] = x
                 df.to_csv("Data/tradeid.csv",
                           sep=',',
                           encoding='utf-8',
                           index_label="Granularity")
                 return
Exemplo n.º 3
0
 def get_transaction_details(self, transactionID):
     """
     returns details of a transactionID
     """
     r = trans.TransactionDetails(accountID=self.__accountID,
                                  transactionID=transactionID)
     self.__clientAPI.request(r)
     return r.response
 def test__transactions_details(self, mock_get):
     """get the transactions details for a transaction."""
     tid = "_v3_accounts_transaction_details"
     resp, data = fetchTestData(responses, tid)
     transactionID = 2304
     r = transactions.TransactionDetails(accountID, transactionID)
     mock_get.register_uri('GET',
                           "{}/{}".format(api.api_url, r),
                           text=json.dumps(resp))
     result = api.request(r)
     self.assertTrue(resp == r.response)
Exemplo n.º 5
0
def get_trade_details(client, account_id, instrument):
    # Get last trade id
    trades_data = trades.TradesList(account_id, instrument)
    trades_data = client.request(trades_data)
    last_trade_id = trades_data['lastTransactionID']
    # Get last trade details
    trans_data = trans.TransactionDetails(account_id, last_trade_id)
    trans_data = client.request(trans_data)
    # Create variables
    instrument_traded = trans_data['transaction']['instrument']
    units_traded = trans_data['transaction']['units']
    price_traded = trans_data['transaction']['price']
    print("Traded " + units_traded + " " + instrument_traded +
          " at " + price_traded)
Exemplo n.º 6
0
def get_transaction_details(account_id, account_token, trade_id, debug=False):
    if debug:
        account_id, client = use_our_token()

    else:
        client = account_token

    try:

        r = transactions.TransactionDetails(account_id, trade_id)

        client.request(r)
        # print(r.response)

        transaction_reason = r.response['transaction']['reason']
        profit_loss = r.response['transaction']['pl']

        print(
            f'user order closed by : {transaction_reason}, Profit/Loss = {profit_loss}'
        )
        """
        ON_FILL
        MARKET_ORDER_TRADE_CLOSE
        TAKE_PROFIT_ORDER
        STOP_LOSS_ORDER
        CLIENT_ORDER
        CLIENT_REQUEST
        """

        return transaction_reason, profit_loss

    except V20Error as ex:
        error_msg = ex.msg.split('"errorMessage":')[1].split(',')[0]
        print(f"Error : {error_msg}")

        return False, error_msg
Exemplo n.º 7
0
def transaction_details(accountID, token, transactionID):
    client = oandapyV20.API(access_token=token)
    r = trans.TransactionDetails(accountID=accountID,
                                 transactionID=transactionID)
    request = client.request(r)
    return request
Exemplo n.º 8
0
import pandas as pd
import oandapyV20
import oandapyV20.endpoints.transactions as trans
import configparser

config = configparser.ConfigParser()
config.read('./config/config_v20.ini')
accountID = config['oanda']['account_id']
access_token = config['oanda']['api_key']

client = oandapyV20.API(access_token=access_token)
"""
# 1 Get transaction list
"""
r = trans.TransactionList(accountID)
client.request(r)

params = {"type": "MARKET_ORDER"}
r = trans.TransactionList(accountID, params=params)
client.request(r)
"""
# 2 Get the details of a single transaction (they can be extracted individually as a pandas dataframe and stored in a database)
"""
r = trans.TransactionDetails(accountID=accountID, transactionID=49)
client.request(r)

# iterate through output of transactions
for oo in range(10, 20):
    r = trans.TransactionDetails(accountID=accountID, transactionID=oo)
    print(client.request(r))
 def longnotshort(self, instrument, granularity):
     getid = self.getid(granularity, instrument)
     csvID = getid[0]
     t = trans.TransactionDetails(self.accountID, csvID)
     self.client.request(t)
     return int(t.response['transaction']['units']) > 0
Exemplo n.º 10
0
    def get_TransactionDetails(self, transactionID):
        r = transactions.TransactionDetails(accountID=self.accountID,
                                            transactionID=transactionID)

        return self.client.request(r)
Exemplo n.º 11
0
 def initPosLog(self, broker, accountID):
     if broker == 'backtest':
         pass
     if broker == "oanda":
         client = oandapyV20.API(
             access_token=cfg.brokerList['oanda']['token'])
         r = trades.OpenTrades(
             accountID=cfg.brokerList['oanda']['accounts'][accountID]['ID'])
         client.request(r)
         reply = dict(r.response)
         tList = reply["trades"]
         tList.reverse()
         for T in tList:
             ro = trades.TradeDetails(accountID=cfg.brokerList['oanda']
                                      ['accounts'][accountID]['ID'],
                                      tradeID=T["id"])
             client.request(ro)
             reply = dict(ro.response)
             oT = reply["trade"]
             if not oT["instrument"] in cfg.pairList:
                 cfg.pairList.append(oT["instrument"])
                 cfg.pairList.sort()
             if float(oT["initialUnits"]) >= 0:
                 typePos = 'l'
             else:
                 typePos = 's'
             pList = [
                 cfg.posList.index(p) for p in cfg.posList
                 if p.broker == 'oanda' and p.account == accountID
                 and p.posID == oT["id"]
             ]
             if pList == []:
                 cfg.posList.append(
                     Position('oanda', accountID, oT["id"],
                              oT["instrument"], float(oT["price"]),
                              abs(float(oT["initialUnits"])), typePos,
                              pd.Timestamp(oT["openTime"])))
                 pInd = -1
             else:
                 pInd = pList[0]
             cfg.posList[pInd].status = 'o'
             if "closingTransactionIDs" in oT.keys():
                 for cT in oT["closingTransactionIDs"]:
                     rc = trans.TransactionDetails(
                         accountID=cfg.brokerList['oanda']['accounts']
                         [accountID]['ID'],
                         transactionID=cT)
                     client.request(rc)
                     replyt = dict(rc.response)
                     if "tradeReduced" in replyt["transaction"].keys():
                         oRe = replyt["transaction"]["tradeReduced"]
                         v = cfg.posList[pInd].log.iloc[-1, ].vol - abs(
                             float(oRe["units"]))
                         p = replyt["transaction"]["price"]
                         cp = float(oRe["realizedPL"])
                         comm = float(replyt["transaction"]["commission"])
                         t = pd.Timestamp(replyt["transaction"]["time"])
                         cfg.posList[pInd].log.loc[t] = {
                             'vol': v,
                             'price': p,
                             'closedprof': cp,
                             'commission': comm
                         }