Touch the sample v20-python-samples of the OANDA v20 REST API wrapper library for Python

This is a memo of v20-python-samples which is a sample of OANDA V20 python lib. You can use it like a command line tool that allows you to check the API.

https://github.com/oanda/v20-python-samples

Introduction

The installation procedure is basically based on the linux environment, but it can also be installed on windows. For the following commands in the procedure, manually do the same in the Windows environment below

linux


make bootstrap

windows_python3


virtualenv -p python3 env
env\Scripts\pip install -r requirements/base.txt

linux


source env/bin/activate

windows


env\Scripts\activate.bat

v20-account-details details will give you an account summary and a balance for each currency pair.

v20-account-details


Account xxx-xxx-xxxxxxx-xxx
===========================

===============================  ==============================
Account ID                       xxx-xxx-xxxxxxx-xxx
Alias                            Primary
Home Currency                    JPY
Balance                          374585.0125
Created by User ID               xxxxxxx
Create Time                      2020-07-09T03:27:35.393967207Z
Guaranteed Stop Loss Order Mode  DISABLED
Profit/Loss                      -72865.1901
Resettable Profit/Loss           -72865.1901
Profit/Loss Reset Time           0
Financing                        -2496.2074
Commission                       0.0
Guaranteed Execution Fees        0.0
Margin Rate                      0.04
Open Trade Count                 0
Open Position Count              0
Pending Order Count              0
Hedging Enabled                  False
Unrealized Profit/Loss           0.0
Net Asset Value                  374585.0125
Margin Used                      0.0
Margin Available                 374585.0125
Position Value                   0.0
Closeout UPL                     0.0
Closeout NAV                     374585.0125
Closeout Margin Used             0.0
Margin Closeout Percentage       0.0
Margin Closeout Position Value   0.0
Withdrawal Limit                 374585.0125
Last Transaction ID              6143
===============================  ==============================

13 Open Positions
=================

============  =========  ================  ==========  ==========
Instrument          P/L    Unrealized P/L  Long        Short
============  =========  ================  ==========  ==========
AUD_JPY        -4643.11                 0  0.0 @ None  0.0 @ None
AUD_USD       -13941.5                  0  0.0 @ None  0.0 @ None
EUR_AUD        -4197.54                 0  0.0 @ None  0.0 @ None
EUR_CAD         2187.31                 0  0.0 @ None  0.0 @ None
EUR_GBP        -4444.72                 0  0.0 @ None  0.0 @ None
EUR_JPY       -13217.7                  0  0.0 @ None  0.0 @ None
EUR_USD        13787.9                  0  0.0 @ None  0.0 @ None
GBP_AUD         6820.85                 0  0.0 @ None  0.0 @ None
GBP_JPY       -17401.3                  0  0.0 @ None  0.0 @ None
GBP_USD        -5079.87                 0  0.0 @ None  0.0 @ None
USD_CAD        -5946.91                 0  0.0 @ None  0.0 @ None
USD_CHF        -9440.97                 0  0.0 @ None  0.0 @ None
USD_JPY       -17347.7                  0  0.0 @ None  0.0 @ None
============  =========  ================  ==========  ==========

v20-account-instruments A list of currencies that can be handled and magnification etc. will be displayed

v20-account-instruments


71 Instruments
==============

=======  ========  ======  =============
Name     Type         Pip  Margin Rate
=======  ========  ======  =============
AUD_CAD  CURRENCY  0.0001  25:1 (0.04)
AUD_CHF  CURRENCY  0.0001  20:1 (0.05)
AUD_HKD  CURRENCY  0.0001  10:1 (0.1)
AUD_JPY  CURRENCY  0.01    25:1 (0.04)
AUD_NZD  CURRENCY  0.0001  25:1 (0.04)
AUD_SGD  CURRENCY  0.0001  20:1 (0.05)
AUD_USD  CURRENCY  0.0001  25:1 (0.04)
CAD_CHF  CURRENCY  0.0001  20:1 (0.05)
CAD_HKD  CURRENCY  0.0001  10:1 (0.1)
CAD_JPY  CURRENCY  0.01    25:1 (0.04)
CAD_SGD  CURRENCY  0.0001  20:1 (0.05)
CHF_HKD  CURRENCY  0.0001  10:1 (0.1)
CHF_JPY  CURRENCY  0.01    20:1 (0.05)
CHF_ZAR  CURRENCY  0.0001  10:1 (0.1)
EUR_AUD  CURRENCY  0.0001  25:1 (0.04)
EUR_CAD  CURRENCY  0.0001  25:1 (0.04)
EUR_CHF  CURRENCY  0.0001  20:1 (0.05)
EUR_CZK  CURRENCY  0.0001  20:1 (0.05)
EUR_DKK  CURRENCY  0.0001  10:1 (0.1)
EUR_GBP  CURRENCY  0.0001  20:1 (0.05)
EUR_HKD  CURRENCY  0.0001  10:1 (0.1)
EUR_HUF  CURRENCY  0.01    20:1 (0.05)
EUR_JPY  CURRENCY  0.01    25:1 (0.04)
EUR_NOK  CURRENCY  0.0001  25:1 (0.04)
EUR_NZD  CURRENCY  0.0001  25:1 (0.04)
EUR_PLN  CURRENCY  0.0001  20:1 (0.05)
EUR_SEK  CURRENCY  0.0001  25:1 (0.04)
EUR_SGD  CURRENCY  0.0001  20:1 (0.05)
EUR_TRY  CURRENCY  0.0001  10:1 (0.1)
EUR_USD  CURRENCY  0.0001  25:1 (0.04)
EUR_ZAR  CURRENCY  0.0001  10:1 (0.1)
GBP_AUD  CURRENCY  0.0001  20:1 (0.05)
GBP_CAD  CURRENCY  0.0001  20:1 (0.05)
GBP_CHF  CURRENCY  0.0001  20:1 (0.05)
GBP_HKD  CURRENCY  0.0001  10:1 (0.1)
GBP_JPY  CURRENCY  0.01    20:1 (0.05)
GBP_NZD  CURRENCY  0.0001  20:1 (0.05)
GBP_PLN  CURRENCY  0.0001  20:1 (0.05)
GBP_SGD  CURRENCY  0.0001  20:1 (0.05)
GBP_USD  CURRENCY  0.0001  20:1 (0.05)
GBP_ZAR  CURRENCY  0.0001  10:1 (0.1)
HKD_JPY  CURRENCY  0.0001  10:1 (0.1)
NZD_CAD  CURRENCY  0.0001  25:1 (0.04)
NZD_CHF  CURRENCY  0.0001  20:1 (0.05)
NZD_HKD  CURRENCY  0.0001  10:1 (0.1)
NZD_JPY  CURRENCY  0.01    25:1 (0.04)
NZD_SGD  CURRENCY  0.0001  20:1 (0.05)
NZD_USD  CURRENCY  0.0001  25:1 (0.04)
SGD_CHF  CURRENCY  0.0001  20:1 (0.05)
SGD_HKD  CURRENCY  0.0001  10:1 (0.1)
SGD_JPY  CURRENCY  0.01    20:1 (0.05)
TRY_JPY  CURRENCY  0.01    10:1 (0.1)
USD_CAD  CURRENCY  0.0001  25:1 (0.04)
USD_CHF  CURRENCY  0.0001  20:1 (0.05)
USD_CNH  CURRENCY  0.0001  20:1 (0.05)
USD_CZK  CURRENCY  0.0001  20:1 (0.05)
USD_DKK  CURRENCY  0.0001  25:1 (0.04)
USD_HKD  CURRENCY  0.0001  10:1 (0.1)
USD_HUF  CURRENCY  0.01    20:1 (0.05)
USD_INR  CURRENCY  0.01    20:1 (0.05)
USD_JPY  CURRENCY  0.01    25:1 (0.04)
USD_MXN  CURRENCY  0.0001  12:1 (0.08)
USD_NOK  CURRENCY  0.0001  25:1 (0.04)
USD_PLN  CURRENCY  0.0001  20:1 (0.05)
USD_SAR  CURRENCY  0.0001  20:1 (0.05)
USD_SEK  CURRENCY  0.0001  25:1 (0.04)
USD_SGD  CURRENCY  0.0001  20:1 (0.05)
USD_THB  CURRENCY  0.01    20:1 (0.05)
USD_TRY  CURRENCY  0.0001  10:1 (0.1)
USD_ZAR  CURRENCY  0.0001  10:1 (0.1)
ZAR_JPY  CURRENCY  0.01    10:1 (0.1)
=======  ========  ======  =============

v20-transaction-range Check the transaction history within the range of transaction IDs. Since there is no detailed information, it is a pity or troublesome to have to obtain detailed information separately Also, I want to take it within the date range, but this sample does not have it.

v20-transaction-range.exe 4000 9999




#### **`v20-transaction-range`**
```consoe

Transaction 4000: Create Take Profit Order 4000 (ON_FILL): Close Trade 3999 @ 71.693
Transaction 4001: Create Stop Loss Order 4001 (ON_FILL): Close Trade 3999 @ 68.745
Transaction 4002: Cancel Order 4000
Transaction 4003: Create Take Profit Order 4003 (REPLACEMENT): Close Trade 3999 @ 71.693
Transaction 4004: Cancel Order 4001
Transaction 4005: Create Stop Loss Order 4005 (REPLACEMENT): Close Trade 3999 @ 68.736
Transaction 4006: Fill Order 3998 (STOP_LOSS_ORDER): -14604.0 of GBP_USD @ 1.24422
Transaction 4007: Fill Order 4005 (STOP_LOSS_ORDER): -17552.0 of AUD_JPY @ 68.736
Transaction 4008: Cancel Order 4003
Transaction 4009: Fill Order 3995 (STOP_LOSS_ORDER): -18483.0 of AUD_USD @ 0.64342
Transaction 4010: Create Market Order 4010 (CLIENT_ORDER): -8925.0 of AUD_JPY
Transaction 4011: Fill Order 4010 (MARKET_ORDER): -8925.0 of AUD_JPY @ 68.308
Transaction 4012: Create Take Profit Order 4012 (ON_FILL): Close Trade 4011 @ 65.534
Transaction 4013: Create Stop Loss Order 4013 (ON_FILL): Close Trade 4011 @ 68.64
Transaction 4014: Create Market Order 4014 (CLIENT_ORDER): 8405.0 of EUR_GBP
Transaction 4015: Fill Order 4014 (MARKET_ORDER): 8405.0 of EUR_GBP @ 0.87327

You can narrow down the transaction type by specifying the type.

v20-transaction-range.exe --type ORDER_FILL 4000 9999



```consoe
Transaction 4006: Fill Order 3998 (STOP_LOSS_ORDER): -14604.0 of GBP_USD @ 1.24422
Transaction 4007: Fill Order 4005 (STOP_LOSS_ORDER): -17552.0 of AUD_JPY @ 68.736
Transaction 4009: Fill Order 3995 (STOP_LOSS_ORDER): -18483.0 of AUD_USD @ 0.64342
Transaction 4011: Fill Order 4010 (MARKET_ORDER): -8925.0 of AUD_JPY @ 68.308
Transaction 4015: Fill Order 4014 (MARKET_ORDER): 8405.0 of EUR_GBP @ 0.87327
Transaction 4025: Fill Order 4024 (MARKET_ORDER_TRADE_CLOSE): -8405.0 of EUR_GBP @ 0.8733
Transaction 4029: Fill Order 4028 (MARKET_ORDER_TRADE_CLOSE): 8925.0 of AUD_JPY @ 68.372

v20-transaction-get Check the transaction ID for details.

v20-transaction-get



id: '4100'
time: '2020-04-19T14:17:16.552497903Z'
userID: 2202754
accountID: xxx-xxx-xxxxxxx-xxx
batchID: '4100'
type: ORDER_FILL
orderID: '4099'
instrument: USD_CAD
units: 16311.0
gainQuoteHomeConversionFactor: 77.674
lossQuoteHomeConversionFactor: 77.693
price: 1.38913
fullVWAP: 1.38913
fullPrice:
  type: PRICE
  bids:
  - price: 1.38894
    liquidity: '10000000'
  asks:
  - price: 1.38913
    liquidity: '10000000'
  closeoutBid: 1.38894
  closeoutAsk: 1.38913
reason: STOP_LOSS_ORDER
pl: -1406.6481
financing: 0.0
commission: 0.0
guaranteedExecutionFee: 0.0
accountBalance: 278334.8247
tradesClosed:
- tradeID: '4098'
  units: 16311.0
  price: 1.38913
  realizedPL: -1406.6481
  financing: 0.0
  guaranteedExecutionFee: 0.0
  halfSpreadCost: 120.3749
halfSpreadCost: 120.3749

Annotation

I inadvertently posted extra information, so I deleted it and reposted it ...

Recommended Posts

Touch the sample v20-python-samples of the OANDA v20 REST API wrapper library for Python
Implemented Python wrapper for Qiita API v2
Created a Python wrapper for the Qiita API
kabu StationĀ® API-I made a Python wrapper for REST API
Sample image of Python API server for EC2 (public AMI)
Let's touch the API of Netatmo Weather Station with Python. #Python #Netatmo
Wrap (part of) the AtCoder Library in Cython for use in Python
Let's touch Google's Vision API from Python for the time being
I made a Python wrapper library for docomo image recognition API.
[Python] REST API essential, convenient library summary
Pandas of the beginner, by the beginner, for the beginner [Python]
Install the Python API of the autonomous driving simulator LGSVL and execute the sample program
Put the exchange rate obtained from Oanda REST API in Python into MongoDB
I checked the library for using the Gracenote API
The story of low learning costs for Python
I tried to touch the API of ebay
Tips for hitting the ATND API in Python
Image processing? The story of starting Python for
A memorandum about the Python tesseract wrapper library
Code for checking the operation of Python Matplotlib
[WP REST API v2] Upload images in Python
kabu StationĀ® API --Updated Python wrapper for PUSH API
A python script that generates a sample dataset for checking the operation of a classification tree
Build API server for checking the operation of front implementation with python3 and Flask
[Python] Get the text of the law from the e-GOV Law API
List of sample program distribution sites for python books
Examine the close processing of Python dataset (SQLAlchemy wrapper)
Let's use the Python version of the Confluence API module.
[Python] Get the list of ExifTags names of Pillow library
[Introduction to Python] Basic usage of the library matplotlib
the zen of Python
Library "apywrapper" to easily develop a wrapper for RESTful API
I just changed the sample source of Python a little.
Check the operation of Python for .NET in each environment
[python] How to use the library Matplotlib for drawing graphs
The first API to make with python Djnago REST framework
Run the intellisense of your own python library with VScode.
Consideration for Python decorators of the type that passes variables
Qiita API Python wrapper for batch processing to grab Qiita posts
A sample for drawing points with PIL (Python Imaging Library).
[Python] The biggest weakness / disadvantage of Google Colaboratory [For beginners]
Google search for the last line of the file in Python