概要
OandaFXで注文済み通貨ペアのポジション情報を返す.
引数
- OandaのアカウントID(str型)
- api※
- 通貨ペア(***_***の形式,str型)
※次のように定義:
api= API(access_token=*****, environment=”practiceまたはlive”)
戻り値
-
- 買いポジションの注文量(float型)
- 買いポジションの平均レート(円,float型)
- 買いポジションの損益(円,float型)
- 売りポジションの注文量(float型)
- 売りポジションの平均レート(円,float型)
- 売りポジションの損益(円,float型)
コード
import oandapyV20.endpoints.instruments as instruments
import oandapyV20.endpoints.positions as positions
#201119 OandaFXで注文済み通貨ペアのポジション情報を返す
def PosiCheck_Oanda_ver0(accountID,api,CurrencyPair):
p = positions.PositionDetails(accountID=accountID, instrument=CurrencyPair)
#print(api.request(p))
Posi_Long = int(api.request(p)["position"]["long"]["units"])
Posi_Short = int(api.request(p)["position"]["short"]["units"])
if Posi_Long==0:
PriceAve_Long=0
PL_Long =0
else:
PriceAve_Long = float(api.request(p)["position"]["long"]["averagePrice"])
PL_Long = float(api.request(p)["position"]["long"]["unrealizedPL"])
if Posi_Short ==0:
PriceAve_Short=0
PL_Short = 0
else:
PriceAve_Short = float(api.request(p)["position"]["short"]["averagePrice"])
PL_Short = float(api.request(p)["position"]["short"]["unrealizedPL"])
#print(Posi_Long,PriceAve_Long,PL_Long,Posi_Short,PriceAve_Short,PL_Short)
return(Posi_Long,PriceAve_Long,PL_Long,Posi_Short,PriceAve_Short,PL_Short)
python用ライブラリ”oandapyV20”をインストール,インポートして使う.
どうやら,売買履歴が1回はないと,エラーで止まるっぽい…



コメント