from pybit.unified_trading import WebSocket
from pybit.unified_trading import HTTP
from time import sleep
session = HTTP(testnet=False)
info = session.get_instruments_info(category="spot")
symbol_infos = info["result"]["list"]
websockets = []
def handle_message(message):
print(message)
def subscribe(websockets, symbols):
print(f'Subscribing to {symbols}')
ws = WebSocket(
testnet=False,
channel_type="spot",
)
ws.trade_stream(symbol=symbols, callback=handle_message)
websockets += [ws]
Category Archives: Programming languages
Subscribing to all ByBit trade streams in Python
Subscribing to ByBit WebSocket streams in Python
Spot is limited to 10 symbols:
from pybit.unified_trading import WebSocket
from time import sleep
ws = WebSocket(
testnet=True,
channel_type="spot",
)
def handle_message(message):
print(message)
#ws.orderbook_stream(50, "BTCUSDT", handle_message)
ws.ticker_stream(symbol=["BTCUSDT", "ETHUSDT"], callback=handle_message)
while True:
sleep(1)
An example of using base iterator in C++
The code below demonstrates how to access underlying range iterator by transformed iterator:
struct A
{
int x;
};
struct B
{
A* a;
};
std::vector<B> v;
int main()
{
auto a_range = v | std::views::transform(std::mem_fn(&B::a));
auto i = std::ranges::find(a_range, 5, std::mem_fn(&A::x));
A* a = *i;
B& b = *(i.base());
}
Migrating a WordPress website from PHP 7.4 to PHP 8.3.6
After updated my WordPress to 6.7.1 and added the following to wp-config.php
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
and got the following error message:
Fatal error: Uncaught Error: Call to undefined function wp_kses() in /home/devnote/www/wp-includes/functions.php:6098 Stack trace:
#0 /home/devnote/www/wp-includes/functions.php(5579): wp_trigger_error()
#1 /home/devnote/www/wp-includes/class-wpdb.php(1333): _deprecated_function()
#2 /home/devnote/www/wp-content/sunrise.php(11): wpdb->escape()
#3 /home/devnote/www/wp-includes/ms-settings.php(47): include_once('...')
#4 /home/devnote/www/wp-settings.php(156): require('...')
#5 /home/devnote/www/wp-config.php(107): require_once('...')
#6 /home/devnote/www/wp-load.php(50): require_once('...')
#7 /home/devnote/www/wp-blog-header.php(13): require_once('...')
#8 /home/devnote/www/index.php(17): require('...')
#9 {main} thrown in /home/devnote/www/wp-includes/functions.php on line 6098
How I fixed wrong colors in my QML app on Android
I removed android:theme
from AndroidManifest.xml:
<activity android:name="net.geographx.MainActivity"
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:exported="true">
<!-- Splash screen -->
<meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/splash"/>
<!-- Splash screen -->
Sending XRP with JavaScript
const read = require('read').read;
const send = require('./send');
async function asyncMain()
{
const amount = await read({
prompt: "Amount: "
});
const password = await read({
prompt: "Password: ",
silent: true,
replace: "*" //optional, will print out an asterisk for every typed character
});
// console.log("Amount: " + amount);
// console.log("Your password: " + password);
Make QML menu width fit the content
Found an implementation here and added two pixels:
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Menu {
width: {
var result = 0;
var padding = 0;
for (var i = 0; i < count; ++i) {
var item = itemAt(i);
result = Math.max(item.contentItem.implicitWidth, result);
padding = Math.max(item.padding, padding);
}
// It looks like two pixels are missing to remove the ellipsis.
// My first idea was that it is leftInset + rightInset, but it does not work.
var missing = 2;
return result + padding * 2 + missing;
}
}
Move assignment operator in C++
Implicitly-declared move assignment operator
If no user-defined move assignment operators are provided for a class type, and all of the following is true:
- there are no user-declared copy constructors;
- there are no user-declared move constructors;
- there are no user-declared copy assignment operators;
- there is no user-declared destructor,
(more…)
Examples of C++/Objective-C interop
From QT’s Purchasing:
//SKProductsRequestDelegate
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSArray<SKProduct *> *products = response.products;
SKProduct *product = [products count] == 1 ? [[products firstObject] retain] : nil;
if (product == nil) {
//Invalid product ID
NSString *invalidId = [response.invalidProductIdentifiers firstObject];
QMetaObject::invokeMethod(backend, "registerQueryFailure", Qt::AutoConnection, Q_ARG(QString, QString::fromNSString(invalidId)));
} else {
//Valid product query
//Create a IosInAppPurchaseProduct
IosInAppPurchaseProduct *validProduct = new IosInAppPurchaseProduct(product, backend->productTypeForProductId(QString::fromNSString([product productIdentifier])));
if (validProduct->thread() != backend->thread()) {
validProduct->moveToThread(backend->thread());
QMetaObject::invokeMethod(backend, "setParentToBackend", Qt::AutoConnection, Q_ARG(QObject*, validProduct));
}
QMetaObject::invokeMethod(backend, "registerProduct", Qt::AutoConnection, Q_ARG(IosInAppPurchaseProduct*, validProduct));
}
[request release];
}