I am trying to convert my old SOAP based BOT to the new API.
Having a few issues such as being able to get account funds, cancelling bets and getting bet details but first off I would like to know why (using the core BDP code they supplied for c# which has almost identical classes for both JSON libraries why I can login with my API Key, Session and URL to the JsonRpcClient but not the RescriptClient?
I am passing the same URL, AppKey and Session to both classes but the RescriptClient won't let me create a client object whilst the JsonRpcClient will.
I have a Login method where I set the preferred login method either Rescript or JsonRpc and then I set the backup to the opposite.
If the preferred login fails I then try the other one.
I am trying to use rescript as my preferred login but it just won't let me login. I don't know if the end point URL is different between the two e.g for the JsonRescript Client I am currently using https://beta-api.betfair.com
If I try and change this to https://api.betfair.com
I get the following error in the Newton.Json DLL which I cannot check as it's compiled
Unhandled Exception: Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue() in c:\Dev\Releases\Working\Netonsoft.Json\Src\Newtons oft.Json\JsonTextReader.cs:line 996
at Newtonsoft.Json.JsonTextReader.ReadInternal() in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newton soft.Json\JsonTextReader.cs:line 476
Anyway I can login into the JsonRpcClient with that endpoint, my appkey and session okay but when I try with the RescriptLogin I don't get any errors (it's in a try/catch) but I just get an empty client object returned which then makes me move on to the next JSON object.
Some example debug (with sessions/appkeys changed) is below
Debug code:
The code in both classes is pretty similar e.g for the one I cannot use it's
and the one I can login in
So the end points are different at the end of the URL.
Both classes extend the same objects e.g
Rescript
and JsonRpc
You can get all the C# Api code from their examples page API-ING it's called for C# > https://github.com/betfair/API-NG-sa...sample-code/TO
Any clues?
Also whilst I am bitching n moaning I am trying to write my own code for the cancelOrders method.
I have a test where I set a LAY bet up for £10 at a price of 1.10 so it won't get snapped up. Then I get the BetID from the result of the placeOrders method and try to cancel the full bet.
I am not sure whether to cancel the full bet I am supposed to supply NOTHING or the value 0 for SizeReduction if I want to cancel the FULL bet. Also if I had a bet of £10 and I wanted to cancel £4 would I supply 6.00 or 4.00 for this? Is the size I want it reduced TO or the amount to deduct from the current bet size?
https://api.developer.betfair.com/services/webapps/docs/display/1smk3cen4v3lu3yomq5qye0ni/Betting+TypeDefinitions#BettingTypeDefinitions-CancelInstruction
At the moment I am getting errors when I try and cancel the bet. The bet is placed okay and I can see it in Betfairs website even though the placeOrders method seems to show some errors in it (see debug) but the cancelOrders code just returns errors and doesn't cancel anything at all.
Notice the code at the end with the response from my call to cancel the bet it says BET_ACTION_ERROR and INVALID_BET_SIZE - I have no idea why.
If someone could give me the Request URL I should be using that would be great!
Any help on either of these matters would be great. Thanks!
Having a few issues such as being able to get account funds, cancelling bets and getting bet details but first off I would like to know why (using the core BDP code they supplied for c# which has almost identical classes for both JSON libraries why I can login with my API Key, Session and URL to the JsonRpcClient but not the RescriptClient?
I am passing the same URL, AppKey and Session to both classes but the RescriptClient won't let me create a client object whilst the JsonRpcClient will.
I have a Login method where I set the preferred login method either Rescript or JsonRpc and then I set the backup to the opposite.
If the preferred login fails I then try the other one.
I am trying to use rescript as my preferred login but it just won't let me login. I don't know if the end point URL is different between the two e.g for the JsonRescript Client I am currently using https://beta-api.betfair.com
If I try and change this to https://api.betfair.com
I get the following error in the Newton.Json DLL which I cannot check as it's compiled
Unhandled Exception: Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue() in c:\Dev\Releases\Working\Netonsoft.Json\Src\Newtons oft.Json\JsonTextReader.cs:line 996
at Newtonsoft.Json.JsonTextReader.ReadInternal() in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newton soft.Json\JsonTextReader.cs:line 476
Anyway I can login into the JsonRpcClient with that endpoint, my appkey and session okay but when I try with the RescriptLogin I don't get any errors (it's in a try/catch) but I just get an empty client object returned which then makes me move on to the next JSON object.
Some example debug (with sessions/appkeys changed) is below
Debug code:
The session from the path is urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
Prefered Login Method = rescript
BackUp Login Method = JsonRpcClient
In RescriptLogin
Try Logging in with RescriptLogin = https://beta-api.betfair.com, BjdUERmcEcTrGnis, urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
In RescriptClient endPoint = https://beta-api.betfair.com appKey = BjdUERmcEcTrGnis sessionToken = urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
this.Client should be populated
Couldnt get a client object with RescriptClient!
RETURN False
Rescript Login Failed so try JsonRpcClientLogin
In JsonRpcClientLogin
In RescriptClient endPoint = https://beta-api.betfair.com appKey = BjdUERmcEcTrGnis sessionToken = urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
RETURN True
We can login with this session and AppKey so return session: urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
Our sessionID is urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
we have logged in and our sessionID is urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
Prefered Login Method = rescript
BackUp Login Method = JsonRpcClient
In RescriptLogin
Try Logging in with RescriptLogin = https://beta-api.betfair.com, BjdUERmcEcTrGnis, urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
In RescriptClient endPoint = https://beta-api.betfair.com appKey = BjdUERmcEcTrGnis sessionToken = urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
this.Client should be populated
Couldnt get a client object with RescriptClient!
RETURN False
Rescript Login Failed so try JsonRpcClientLogin
In JsonRpcClientLogin
In RescriptClient endPoint = https://beta-api.betfair.com appKey = BjdUERmcEcTrGnis sessionToken = urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
RETURN True
We can login with this session and AppKey so return session: urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
Our sessionID is urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
we have logged in and our sessionID is urT4kc39f2pciMW3PmlUg+ZsR/Zsz83bjy6uy9MSN9I=
The code in both classes is pretty similar e.g for the one I cannot use it's
Code:
public RescriptClient(string endPoint, string appKey, string sessionToken) { this.EndPoint = endPoint + "/rest/v1/"; CustomHeaders = new NameValueCollection(); if (appKey != null) { CustomHeaders[APPKEY_HEADER] = appKey; } if (sessionToken != null) { CustomHeaders[SESSION_TOKEN_HEADER] = sessionToken; } }
and the one I can login in
Code:
public JsonRpcClient(string endPoint, string appKey, string sessionToken) { this.EndPoint = endPoint + "/json-rpc"; CustomHeaders = new NameValueCollection(); if (appKey != null) { CustomHeaders[APPKEY_HEADER] = appKey; } if (sessionToken != null) { CustomHeaders[SESSION_TOKEN_HEADER] = sessionToken; } }
Both classes extend the same objects e.g
Rescript
Code:
namespace Api_ng_sample_code { public class RescriptClient : HttpWebClientProtocol, IClient {
Code:
namespace Api_ng_sample_code { public class JsonRpcClient : HttpWebClientProtocol, IClient {
Any clues?
Also whilst I am bitching n moaning I am trying to write my own code for the cancelOrders method.
I have a test where I set a LAY bet up for £10 at a price of 1.10 so it won't get snapped up. Then I get the BetID from the result of the placeOrders method and try to cancel the full bet.
I am not sure whether to cancel the full bet I am supposed to supply NOTHING or the value 0 for SizeReduction if I want to cancel the FULL bet. Also if I had a bet of £10 and I wanted to cancel £4 would I supply 6.00 or 4.00 for this? Is the size I want it reduced TO or the amount to deduct from the current bet size?
https://api.developer.betfair.com/services/webapps/docs/display/1smk3cen4v3lu3yomq5qye0ni/Betting+TypeDefinitions#BettingTypeDefinitions-CancelInstruction
At the moment I am getting errors when I try and cancel the bet. The bet is placed okay and I can see it in Betfairs website even though the placeOrders method seems to show some errors in it (see debug) but the cancelOrders code just returns errors and doesn't cancel anything at all.
Notice the code at the end with the response from my call to cancel the bet it says BET_ACTION_ERROR and INVALID_BET_SIZE - I have no idea why.
If someone could give me the Request URL I should be using that would be great!
PlaceOrder: 1088797 - LAY - 10 - NONE
look at Bet Object
LAY
NONE
1.1
10
5866287
111836561
Instruction SelectionID: 5866287
Instruction OrderType: LIMIT
Instruction Side: LAY
EndPoint = https://beta-api.betfair.com/json-rpc
Calling: SportsAPING/v1.0/placeOrders With args: {"marketId":"1.111836561","instructions":[{"orderType":"LIMIT","selectionId":5866287,"handic ap":0.0,"side":"LAY","limitOrder":{"size":10.0,"pr ice":1.1,"persistenceType":"LAPSE"}}],"customerRef":"PlaceOrder_BetPK-1088797","locale":null}
Got Response: {"jsonrpc":"2.0","result":{"status":"SUCCESS","err orCode":"ERROR_IN_MATCHER","marketId":"1.111836561 ","instructionReports":[{"status":"SUCCESS","errorCode":"INVALID_BET_SIZE" ,"instruction":{"orderType":"LIMIT","selectionId": 5866287,"handicap":0.0,"side":"LAY","limitOrder":{ "size":10.0,"price":1.1,"persistenceType":"LAPSE"} },"betId":"31644002430","placedDate":"2013-11-12T10:11:54Z","averagePriceMatched":0.0,"sizeMatch ed":0.0}],"customerRef":"PlaceOrder_BetPK-1088797"},"id":1}
PlaceOrder Status = SUCCESS
PlaceOrder Success
BetID is 31644002430
This Bet could not be fully matched at this point in time; Bet UnMatched; Any matched amount was £0; Current Match Status: U; Bet ID: 31644002430
Bet Message = Bet UnMatched
Bet was placed was okay; BetPK: 1088797; BetID: 31644002430
Now Cancel it!
CancelBet - BetID: 31644002430 - SizeReducton: 0;
IN CancelOrder
Instruction BetID: 31644002430
Instruction SizeReduction: 0
EndPoint = https://beta-api.betfair.com/json-rpc
Calling: SportsAPING/v1.0/cancelOrders With args: {"marketId":"1.111836561","instructions":[{"betId":"31644002430","sizeReduction":0.0}],"customerRef":"CancelOrder_BetPK-1088797"}
Got Response: {"jsonrpc":"2.0","result":{"status":"FAILURE","err orCode":"BET_ACTION_ERROR","marketId":"1.111836561 ","instructionReports":[{"status":"FAILURE","errorCode":"INVALID_BET_SIZE" ,"instruction":{"betId":"31644002430","sizeReducti on":0.0}}],"customerRef":"CancelOrder_BetPK-1088797"},"id":1}
Status = FAILURE
CancelOrder Failure - error = INVALID_BET_SIZE
Cancel Remaining Amount = 0
Cancel Status =
Cancel Message = INVALID_BET_SIZE
Bet was not cancelled INVALID_BET_SIZE
look at Bet Object
LAY
NONE
1.1
10
5866287
111836561
Instruction SelectionID: 5866287
Instruction OrderType: LIMIT
Instruction Side: LAY
EndPoint = https://beta-api.betfair.com/json-rpc
Calling: SportsAPING/v1.0/placeOrders With args: {"marketId":"1.111836561","instructions":[{"orderType":"LIMIT","selectionId":5866287,"handic ap":0.0,"side":"LAY","limitOrder":{"size":10.0,"pr ice":1.1,"persistenceType":"LAPSE"}}],"customerRef":"PlaceOrder_BetPK-1088797","locale":null}
Got Response: {"jsonrpc":"2.0","result":{"status":"SUCCESS","err orCode":"ERROR_IN_MATCHER","marketId":"1.111836561 ","instructionReports":[{"status":"SUCCESS","errorCode":"INVALID_BET_SIZE" ,"instruction":{"orderType":"LIMIT","selectionId": 5866287,"handicap":0.0,"side":"LAY","limitOrder":{ "size":10.0,"price":1.1,"persistenceType":"LAPSE"} },"betId":"31644002430","placedDate":"2013-11-12T10:11:54Z","averagePriceMatched":0.0,"sizeMatch ed":0.0}],"customerRef":"PlaceOrder_BetPK-1088797"},"id":1}
PlaceOrder Status = SUCCESS
PlaceOrder Success
BetID is 31644002430
This Bet could not be fully matched at this point in time; Bet UnMatched; Any matched amount was £0; Current Match Status: U; Bet ID: 31644002430
Bet Message = Bet UnMatched
Bet was placed was okay; BetPK: 1088797; BetID: 31644002430
Now Cancel it!
CancelBet - BetID: 31644002430 - SizeReducton: 0;
IN CancelOrder
Instruction BetID: 31644002430
Instruction SizeReduction: 0
EndPoint = https://beta-api.betfair.com/json-rpc
Calling: SportsAPING/v1.0/cancelOrders With args: {"marketId":"1.111836561","instructions":[{"betId":"31644002430","sizeReduction":0.0}],"customerRef":"CancelOrder_BetPK-1088797"}
Got Response: {"jsonrpc":"2.0","result":{"status":"FAILURE","err orCode":"BET_ACTION_ERROR","marketId":"1.111836561 ","instructionReports":[{"status":"FAILURE","errorCode":"INVALID_BET_SIZE" ,"instruction":{"betId":"31644002430","sizeReducti on":0.0}}],"customerRef":"CancelOrder_BetPK-1088797"},"id":1}
Status = FAILURE
CancelOrder Failure - error = INVALID_BET_SIZE
Cancel Remaining Amount = 0
Cancel Status =
Cancel Message = INVALID_BET_SIZE
Bet was not cancelled INVALID_BET_SIZE
Comment