Interactive Brokers is this error? 10197 "No market data during competing live session" - interactive-brokers

I'm trying to get the price for stock option for the Japan "6503" stock, and I get the error:
Error code 10197 No market data during competing live session
I don't have subscription for Japan Market, but I still can see the "last price" for the option in TWS User Interface (not for all but for some option contracts, for some it's unavailable and displayed as "n/a").
Question - it seems like this error code - is not actually an error and could be ignored, is that true? The error doesn't make sense at all as I don't have any competing session or paper session.
I'm using the TWS Java API with the following code to get the price:
val contract = Contract()
contract.exchange("OSE.JPN")
contract.currency("JPY")
contract.conid(455178173)
contract.secType(Types.SecType.OPT)
client.reqMarketDataType(MarketDataType.DELAYED_FROZEN)
client.reqMktData(request_id, contract, "", false, false, null)
I'm using the conid 455178173 to get the price, if you need the full info about the option, here it is:
symbol: "6503",
right: "call",
expiration: "2021-01-07",
strike: 1200.0,
option_exchange: "OSE.JPN",
currency: "JPY",

This error happens when you have a "live" session thats competing for data. Which means you have a live TWS terminal thats showing the live data and you are requesting data from your Paper account via the API.
The API won't return the requested data (showing this error) because the same data is being sent to the live account.

Related

How to get membership badges for YouTube live chat messages?

I've been poking around at the YouTube live chat API to render out a custom chat feed, and was wondering how I can show membership/sponsorship badges next to users like the YouTube site itself does?
Looking at a response from the API, I can see that YouTube does tell me the user is a member/sponsor, but it doesn't include at what level/duration nor what badge image should be shown:
{
"kind": "youtube#liveChatMessage",
"etag": "MHpDf4piJnYR2X3lP-7mwBavfWM",
"id": "LCC.CjgKDQoLd1VwYUIzYTdkVW8qJwoYVUNEWExPVjNTMEdUd21EOFY4R1A2dzlREgt3VXBhQjNhN2RVbxI7ChpDSVRodDQzS292VUNGZVV0clFZZHNJRUwzZxIdQ1B1VHJiYV9vdlVDRllhRGdnb2RaUE1LanctMjY",
"snippet": {
"type": "textMessageEvent",
"liveChatId": "Cg0KC3dVcGFCM2E3ZFVvKicKGFVDRFhMT1YzUzBHVHdtRDhWOEdQNnc5URILd1VwYUIzYTdkVW8",
"authorChannelId": "UCYC1zf9Dznp-xpe9rwEopLQ",
"publishedAt": "2022-01-08T16:31:12.317Z",
"hasDisplayContent": true,
"displayMessage": "Instead of waiting 30 seconds you had to spam facecam now you get a 5 minute timeout",
"textMessageDetails": {
"messageText": "Instead of waiting 30 seconds you had to spam facecam now you get a 5 minute timeout"
}
},
"authorDetails": {
"channelId": "UCYC1zf9Dznp-xpe9rwEopLQ",
"channelUrl": "http://www.youtube.com/channel/UCYC1zf9Dznp-xpe9rwEopLQ",
"displayName": "Cody Kerley",
"profileImageUrl": "https://yt3.ggpht.com/ytc/AKedOLQFiwv-x6ukfTOh7pD7WlCe7Ss1AB5wH7QAF53uiQ=s88-c-k-c0x00ffffff-no-rj",
"isVerified": false,
"isChatOwner": false,
"isChatSponsor": true,
"isChatModerator": true
}
}
But if I look at how this message was shown in the YouTube chat itself, the user has the correct membership badge for their level/duration, specific to this channel, and the tooltip also shows you the level/duration of the membership/sponsorship:
How can I get this information from the API for each chat message so that I can render the badge correctly myself?
Cheers.
As you said there doesn't seem to be any official YouTube Data API v3 endpoint providing membership badges for YouTube live chat messages.
However I reverse-engineered YouTube live chat messages and here is the solution:
Get a continuation token starting with 0ofMyAO (there seems to be 2 that both work) by executing (don't forget to change VIDEO_ID with your YouTube live video id):
curl -s 'https://www.youtube.com/live_chat?v=VIDEO_ID' -H 'User-Agent: Firefox/99'
Use this continuation token to fetch all pieces of information about current YouTube live chat messages by executing (don't forget to change CONTINUATION_TOKEN with the continuation token you grab at step 1., note: don't care about the key it's not a YouTube Data API v3 key):
curl -s 'https://www.youtube.com/youtubei/v1/live_chat/get_live_chat?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8' -H 'Content-Type: application/json' --data-raw '{"context":{"client":{"clientName":"WEB","clientVersion":"2.9999099"}},"continuation":"CONTINUATION_TOKEN"}'
Likewise you'll get all pieces of information about current YouTube live chat messages since the moment you grab the continuation token at step 1. however continuation token seems to expire every 5 minutes so grab a new one from the response of step 2. or by doing step 1. once again.
Note 0: during the 5 minutes window, you can execute step 2. as many time as you want to get messages in real time
Note 1: I recommend you to change the continuation token every 4 minutes in order not to miss any message
I let you understand the JSON response that contain the pieces of information you are looking for
Note: at step 1. you retrieve recent message sent before your request but it's in HTML format and not JSON this time

When i terminate app MUC group chat members are getting removed

When i terminate app MUC group chat members are getting removed, i have to join them again while coming back to app from bookmarks? We do not want to rejoin again and again. Can someone please suggest way how to avoid rejoining.
In Android smack there is provision for auto-rejoin.
Even from Openfire back end we have managed code to do not remove.
So Android is working fine, iOS is removing users.
Please do suggest.
Instead of rejoining the room every time, do set the presence of the group when the user relaunches the app.
Set presence with below code function iterate through all your groups name and set presence:
for group in chatListModel ?? []{
if(group.opponent_type == "2"){
print("Group Name: \(group.opponent_uuid ?? "")")
XMPPGlobal.sharedIntanceXMPP.xmppController.updatePresence(roomJID: XMPPJID(string: "\(group.opponent_uuid ?? "")#\(groupServerName)"))
}
}
Define below function in your XMPPController class:
func updatePresence(roomJID : XMPPJID?) {
let presence = XMPPPresence(type: "presence")
presence.addAttribute(withName: "from", stringValue: self.xmppStream.myJID?.user ?? "")
presence.addAttribute(withName: "to", stringValue: "\(roomJID?.full ?? "")/\(self.xmppStream.myJID?.user ?? "")")
let element = DDXMLElement.init(name: "x", xmlns: XMPPMUCNamespace)
presence.addChild(element)
self.xmppStream.send(presence)
}
Hope it will works for you.
In spite of the fact that there is the answer.
I would like to elaborate a little bit :)
In case of MUC rooms: there is an affiliation, i.e. long-lasting role (admin, owner, etc) and "subscription" role (visitor, member etc).
What you are asking is per se described in XMPP MUC. 7.1 Order of Events
You send your presence to join the room, and receive presence from other other participants, you can also get some cached messages if your XMPP backend was configured properly.
For instance for ejabberd (process-one): mod_muc: history_size settings defines in-memory cache.
You might don't want to get set of room events, as described in 7.1 above.
There might be some server's extensions. In case of ejabberd there is MUCPubSub you send your subscription (not presence) and get the following messages, plus you can get list of members or track its changes, and etc:
<subscribe xmlns='urn:xmpp:mucsub:0'
nick='mynick'
password='roompassword'>
<event node='urn:xmpp:mucsub:nodes:messages' />

How to handle payment success in stripe?

After a user visits the payments page and successfully makes a payment, Stripe will redirect the customer to whatever url is provided to success_url
Stripe.api_key = 'sk_test_51HYHSFGtUKse83O9J4QeAib3cp8sHzGaOQRrn7sba92Hd8dCHE3AIHe5ModevMK7TVAUCyJU0ADSwIUoX00qxZmBI9r'
session = Stripe::Checkout::Session.create({
payment_method_types: ['card'],
line_items: [{
name: 'Kavholm rental',
amount: 1000,
currency: 'aud',
quantity: 1,
}],
payment_intent_data: {
application_fee_amount: 123,
transfer_data: {
destination: '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
},
},
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/failure',
})
Now the app/platform must arrange 'fulfillment':
After the payment is completed, you’ll need to handle any fulfillment necessary on your end. A home-rental company that requires payment upfront, for instance, would connect the homeowner with the renter after a successful payment.
Also (bold from me):
Do not rely on the redirect to the success_url param alone for fulfilling purchases as:
Malicious users could directly access the success_url without paying and gain access to your goods or services.
Customers may not always reach the success_url after a successful payment. It is possible they close their browser tab before the redirect occurs.
Up to this point, everything is very well explained in the stripe docs and very understandable.
But I want to know: what is the best thing to do next, noting that:
a payment may not go through immediately, so simply loading the success_url might be premature
a webhook can be (easily) configured to listen for events, however if the success_url is loaded even 1 second before the webhook receives a success message, then it won't know that the payment went through successfully (so, for example, displaying "Congrats, your product will be shipped!" message could be presumptuous
Question
So, finally, the question: what is best practice for the flow on from success_url? I am just confused as to what is the best pattern..
Ideas
Here are some things I've considered:
Upon routing to success_url, simply use sleep(5) and then check the webhook in the controller for the success_url so it takes 5 extra seconds to load giving the webhook a chance to receive incoming events, so you can display either "Congrats your product will be shipped!" or "Oh, no, something went wrong with your payment, please try again or contact your bank".
Routing directly to success_url, but then having a message saying "please refresh in a moment" (then listening for a webhook indicating the payment was successful, and then conditionally showing the "Congrats your product will be shipped!" message)
The documentation for fulfilling orders has this in an info box under the code snippet:
Your webhook endpoint redirects your customer to the success_url when you acknowledge you received the event. In scenarios where your endpoint is down or the event isn’t acknowledged properly, your handler redirects the customer to the success_url 10 seconds after a successful payment.
The event referenced above is the checkout.session.completed event sent to your webhook endpoint. The delay is designed to let you confirm the payment is successful and customize the success page based on the result of the Checkout Session's outcome.
In other words, Checkout won't send someone to your success_url until you've responded to the checkout.session.completed event request from your webhook endpoint with a successful (2xx) response, giving you time to customize the success page based on the outcome.
You can, for example, default to a "your payment is being processed" success page, but if you confirm the Checkout Session and payment succeeded after receiving the checkout.session.completed event, you can instead change the page to read "congrats your product will be shipped".
This approach means you can reliably present a success page that always has displays accurate information.

Why my GPX uploads don't show up on my Strava dashboard?

I'm developing a mobile app which is able to record GPS data of an indoor ride like the athlete would circle around a velodrome. It is relatively easy to calculate the GPS points based on the speed measurements the spinning bike provides (compared to an arbitrary GPS route).
The app is uploading my recorded activities in GPX format (gpx.gz to be more precise to speed up things) using the Strava API. The app obtains OAuth token with "activity:write" scope. The Upload POST returns 201 and the upload finishes as well shortly with 200 success code. However after I look at my Strava user dashboard no activity shows up. When I try to view the said activities through Strava's Swagger API play ground it tells me "Record Not Found".
curl -X GET "https://www.strava.com/api/v3/activities/4381960409" -H "accept: application/json" -H "authorization: Bearer zzzzzzzzzzzzzzzzzzzzzzzzzzzz"
https://www.strava.com/api/v3/activities/4381960409
{
"message": "Record Not Found",
"errors": [
{
"resource": "Activity",
"field": "id",
"code": "invalid"
}
]
}
Example activity ids which "got lost in the ether": 4381670165, 4381744693, 4381960409.
My problem is that I don't have any debug information about what could be wrong. I receive success codes, but then the activities just never really materialize. Furthermore I cannot check the Upload's status through their Swagger, because the OAuth token there only has read privileges.
Since I'm generating the GPX files I tested them by manually uploading them. The first one as a Virtual Ride (https://www.strava.com/activities/4094942758) and the second one as a Ride tagged as Indoor cycling (https://www.strava.com/activities/4094974788). Neither of them shows any GPS data whatsoever. However the file contains the data.
So maybe the GPX files have some problem? Here are the two: https://drive.google.com/drive/folders/1dkUvrLxW2r3tvQqvoqAkOB9998N9uLn7?usp=sharing
The app is written in Flutter and uses my derivatives of strava_flutter and rw_tcx.
final stravaService = Get.find<StravaService>();
await stravaService.login();
final records = await _database.recordDao.findAllActivityRecords(activity.id);
final statusCode = await stravaService.upload(activity, records);
if (statusCode == statusOk) {
activity.uploaded = true;
await _database.activityDao.updateActivity(activity);
}
As I mention, it completes successfully, both the Upload POST and then it gets back 200, this is in the guts of strava_flutter.
I made multiple mistakes:
I was dealing with multiple file formats (FIT, GPX, TCX) and the actual file I uploaded was TCX. Kudos to Strava developers the system was able to gracefully swallow that and extract the info from the TCX, didn't return an error code. That's smooth.
The main reason why the GPS didn't show: I swapped the lat-lon coordinates. Unfortunately that can be confusing as well, especially if someone is tired. https://macwright.com/lonlat/ After some additional corrections the GPS now shows: https://www.strava.com/activities/4104607928

How can a Slack bot detect a direct message vs a message in a channel?

TL;DR: Via the Slack APIs, how can I differentiate between a message in a channel vs a direct message?
I have a working Slack bot using the RTM API, let's call it Edi. And it works great as long as all commands start with "#edi"; e.g. "#edi help". It currently responses to any channel it's a member of and direct messages. However, I'd like to update the bot so that when it's a direct message, there won't be a need to start a command with "#edi"; e.g. "#edi help" in a channel, but "help" in a direct message. I don't see anything specific to differentiate between the two, but I did try using the channel.info endpoint and counting the number of people in "members"; however, this method only works on public channel. For private channels and direct messages, the endpoint returns an "channel_not_found" error.
Thanks in advance.
I talked to James at Slack and he gave me a simply way to determine if a message is a DM or not; if a channel ID begins with a:
C, it's a public channel
D, it's a DM with the user
G, it's either a private channel or multi-person DM
However, these values aren't set in stone and could change at some point, or be added to.
So if that syntax goes away, another way to detect a DM to use both channels.info and groups.info. If they both return “false” for the “ok” field, then you know it’s a DM.
Note:
channels.info is for public channels only
groups.info is for private channels and multi-person DMs only
Bonus info:
Once you detect a that a message is a DM, use either the user ID or channel ID and search for it in the results of im.list; if you find it, then you’ll know it’s a DM to the bot.
“id” from im.list is the channel ID
“user” from im.list is the user ID from the person DM’ing with the bot
You don’t pass in the bot’s user ID, because it’s extracted from the token
FYI as of July 2017, for "message.im" events (via your app's Event Subscriptions), the event payload seems to now return additional fields to detect if the message is coming from your own bot (pasted in here from my logs):
INFO[0012] got Slack message: (bot.SlackMessage) {
SlackEvent: (bot.SlackEvent) {
Type: (string) (len=7) "message",
EventTs: (string) (len=17) "1501076832.063834",
User: (string) ""
},
SubType: (string) (len=11) "bot_message",
Channel: (string) (len=9) "D6CJWD132",
Text: (string) (len=20) "this is my bot reply",
Username: (string) (len=15) "Myapp Local",
BotID: (string) (len=9) "B6DAZKTGG",
Ts: (string) (len=17) "1501076832.063834"
}
Slack have added Conversations API some time ago. You should use it to differentiate between PM/channel instead of relying on prefix.
From Conversations API documentation:
Each channel has a unique-to-the-team ID that begins with a single letter prefix, either C, G, or D. When a channel is shared across teams (see Developing for Shared Channels), the prefix of the channel ID may be changed, e.g. a private channel with ID G0987654321 may become ID C0987654321.
This is one reason you should use the conversations methods instead of the previous API methods! You cannot rely on a private shared channel's unique ID remaining constant during its entire lifetime.
Get conversation info using conversations.info method and check is_im flag. is_im == true means that the conversation is a direct message between two distinguished individuals or a user and a bot.
The info function is also available for private channels with the Slack API method groups.info. This works also for direct message channels with multiple participants, since they are a special form of private channels.
You can use groups.list to get the IDs of all private channels incl. direct message channels with multiple participants.
Note that groups.list will only return private channels, that the user or bot that the access token belongs to has been invited to.

Resources