-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It seems no document about the v20.functions #44
Comments
I found some description of v20.functions.How to use them? import v20.Context |
Orders were placed with the following codes. OANDA does not seem to have much power to devote to this wrapper. (It's a machine translation.) import v20
# define url and others
api = v20.Context(url, port, token=token)
response = api.pricing.get(account_id, instruments='USD_JPY')
prices = response.body['prices']
bid = prices[0].bids[0].price
kwargs = {
'order': {
'units': 1,
'instrument': 'USD_JPY',
'type': 'MARKET',
'takeProfitOnFill': {
'price': round(bid + 1.0, 2),
'timeInForce': 'GTC',
},
'stopLossOnFill': {
'price': round(bid - 1.0, 2),
'timeInForce': 'GTC',
},
}
}
response = api.order.create(account_id, **kwargs)
print(response)
# Method = POST
# Path = https://api-fxtrade.oanda.com:443/v3/accounts/***-***-******-***/orders
# Status = 201
# Reason = Created
# Content-Type = application/json |
Hi,
I’m glad to get your mail.
You’re the first people I contact with using Oanda API,too.
I use Oanda many years.But it’s the first time to trade by API.
Hope to learn more from you.
I am going to finish my Oanda API beside some difficulties.
As you said, the v20 repository with some error,
Do you suggest to still use it,
Or change to RESTful API by cURL instructions?
At last,is it free when I use Oanda v20 API in live account?
I didn’t see about the charge program.
Best Regards,
David Liao
… たーごいる ***@***.***> 於 2022年11月22日 下午12:35 寫道:
Orders were placed with the following codes.
Buy or sell, can be changed by plus or minus a number of units.
OANDA does not seem to have much power to devote to this wrapper.
This repository has some parts that do not work due to some mistakes in the code.
(It's a machine translation.)
import v20
# define url and others
api = v20.Context(url, port, token=token)
response = api.pricing.get(account_id, instruments='USD_JPY')
prices = response.body['prices']
bid = prices[0].bids[0].price
kwargs = {
'order': {
'units': 1,
'instrument': 'USD_JPY',
'type': 'MARKET',
'takeProfitOnFill': {
'price': round(bid + 1.0, 2),
'timeInForce': 'GTC',
},
'stopLossOnFill': {
'price': round(bid - 1.0, 2),
'timeInForce': 'GTC',
},
}
}
response = api.order.create(account_id, **kwargs)
print(response)
# Method = POST
# Path = https://api-fxtrade.oanda.com:443/v3/accounts/***-***-******-***/orders
# Status = 201
# Reason = Created
# Content-Type = application/json
—
Reply to this email directly, view it on GitHub <#44 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AOBLZ3HYVGBTVP577AJKLELWJRESVANCNFSM6AAAAAASHKKWOA>.
You are receiving this because you authored the thread.
|
I cannot find the v20.functions documents beside cURL RESTful endpoints.But I preferred use v20.functions to trade.If I were wrong, please tell me.
I trial and error to summarize some:
import v20
#Place a market order:Market BUY EURUSD 10000 with stop loss 0.99332 and take profit 1.04718
ctx=v20.Context(
account_id, #just like 101-011-8XXXXX6-001
token='xxxxxxxxxxxxxxxxxxxxx', # get from Oanda website
)
response=ctx.order.market(
account_id,
instrument='EUR_USD',
units=10000,
type='MARKET',
side='BUY',
stopLossOnFill=v20.transaction.StopLossDetails(price=0.99332), # stop loss price
takeProfitOnFill=v20.transaction.TakeProfitDetails(price=1.04718). # take profit price
)
if response.status==201 and response.reason=='Created': # if success to place order
print(response.body['orderFillTransaction']) # check the response.body['orderFillTransaction']
print('id:',response.body['orderFillTransaction'].id) # print the order id
beside id, there's some information of order fulfillment.
print('instrument:',response.body['orderFillTransaction'].instrument)
print('type:',response.body['orderFillTransaction'].type)
print('price:',response.body['orderFillTransaction'].price)
print('orderID:',response.body['orderFillTransaction'].orderID)
print('batchID:',response.body['orderFillTransaction'].batchID)
print('requestID:',response.body['orderFillTransaction'].requestID)
print('units:',response.body['orderFillTransaction'].units)
print('requestedUnits:',response.body['orderFillTransaction'].requestedUnits)
print('commission:',response.body['orderFillTransaction'].commission)
print('accountBalance:',response.body['orderFillTransaction'].accountBalance)
print('time:',response.body['orderFillTransaction'].time)
print('reason:',response.body['orderFillTransaction'].reason)
Hope to know more who trade by Oanda v20 API.
And hope more details of documents about the v20.
The text was updated successfully, but these errors were encountered: