Пример #1
0
def get_positions():
    r = positions.PositionList(RUNNING_ENV.account.mt4)
    try:
        rv = RUNNING_ENV.api.request(r)
    except V20Error as err:
        logging.error(r.status_code, err)
    else:
        logging.info(json.dumps(rv, indent=2))
        return rv.get('positions')
Пример #2
0
 def test__positions_list(self, mock_get):
     """get the positions list for an account."""
     tid = "_v3_accounts_accountID_positions"
     resp, data = fetchTestData(responses, tid)
     r = positions.PositionList(accountID)
     mock_get.register_uri('GET',
                           "{}/{}".format(api.api_url, r),
                           text=json.dumps(resp))
     result = api.request(r)
     self.assertTrue(resp == result)
Пример #3
0
 def test__positions_list(self, mock_get):
     """get the positions list for an account."""
     uri = 'https://test.com/v3/accounts/{}/positions'.format(accountID)
     resp = responses["_v3_accounts_accountID_positions"]['response']
     text = json.dumps(resp)
     mock_get.register_uri('GET',
                           uri,
                           text=text)
     r = positions.PositionList(accountID)
     result = api.request(r)
     pos1 = result['positions'][1]
     self.assertTrue(pos1["instrument"] == "DE30_EUR" and
                     int(pos1["short"]["units"]) == -20 and
                     result["lastTransactionID"] == "2124")
Пример #4
0
    def positions(self):

        r = positions.PositionList(ACCOUNT_ID)
        position = []

        position.append([
            i['short'].get('tradeIDs') for i in api.request(r)['positions']
            if i['short'].get('tradeIDs') is not None
        ])
        position.append([
            i['long'].get('tradeIDs') for i in api.request(r)['positions']
            if i['long'].get('tradeIDs') is not None
        ])
        position = [item for sublist in position for item in sublist]
        position = [item for sublist in position for item in sublist]

        return position
Пример #5
0
# http://www.algo-fx-blog.com/fx-api-oanda-v20-python-positions-management/
import pandas as pd
import oandapyV20
import oandapyV20.endpoints.positions as positions
import os, sys
sys.path.append(os.getcwd())
from basic import accountID, access_token, api

# 講座のすべてのポジションをリストとして取得
r = positions.PositionList(accountID=accountID)
print(api.request(r))

# 通貨を指定してポジションを取得
r = positions.PositionDetails(accountID=accountID, instrument="EUR_GBP")
print(api.request(r))
# ポジションを保有していない場合はエラー

# すべてのポジションを決済する
data = {"longUnits": "ALL"}

# ドル円の買い注文全ての保有ポジションを決済する
r = positions.PositionClose(accountID=accountID,
                            data=data,
                            instrument="USD_JPY")
print(api.request(r))
Пример #6
0
 def GetPositions(self):
     return self.send_request(positions.PositionList(Oanda.accountID))
def position_list(accountID, token):
    client = oandapyV20.API(access_token=token)
    r = positions.PositionList(accountID=accountID)
    request = client.request(r)
    return request
Пример #8
0
 def list_positions(self):
     endpoint = positions.PositionList(self.account_id)
     op = self.send_request(endpoint)
     return op["positions"]
Пример #9
0
 def positions(self):
     r = positions.PositionList(self.account_id)
     return self.api.request(r)
Пример #10
0
     //   path       (str): Directory path to use.
    Returns:
        obj: json object
    """
    result = []
    try:
        with open(filename, "r") as entry:
            result = json.load(entry)
    except IOError as ex:
        print "I/O error({0}): {1}".format(ex.errno, ex.strerror)
    else:
        entry.close()
        return result


if __name__ == "__main__":

    # r = accounts.AccountDetails(accountID=config.get('fxpractice','active_account'))
    r = positions.PositionList(
        accountID=config.get('fxpractice', 'active_account'))
    client.request(r)
    print r.response

    with open(POSITIONS_FILE, 'w') as outfile:
        json.dump(r.response, outfile)

    jk = read_json_file(POSITIONS_FILE)
    print('jk=', jk)
    # print ('pause')

    json_to_csv()
Пример #11
0
def PositionsPositionList(access_token, accountID):  # check
    'List all Positions for an Account. The Positions returned are for every instrument that has had a position during the lifetime of the Account.'
    r = positions.PositionList(accountID=accountID)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)