3Commas API
3Commas trading-bot WebSocket and REST client for Delphi — DMC streams plus account, deal and bot endpoints.
3Commas trading-bot WebSocket and REST client for Delphi — DMC streams plus account, deal and bot endpoints.
The websocket feed provides real-time market data updates for Trades and Deals
TsgcWSAPI_ThreeCommas| Standards & specs | 3Commas API documentation |
| Component class | TsgcWSAPI_ThreeCommas (unit sgcWebSocket_API_ThreeCommas) |
| Frameworks | VCL, FireMonkey, Lazarus / FPC, .NET |
| Platforms | Windows, macOS, Linux, iOS, Android |
The principal published / public properties used to configure and drive the component. Consult the online help for the full list.
Client | Published or public property used to configure or query the component. |
OnConnect | Published or public property used to configure or query the component. |
OnThreeCommasConnect | Published or public property used to configure or query the component. |
OnThreeCommasConfirmSubscription | Published or public property used to configure or query the component. |
OnThreeCommasRejectSubscription | Published or public property used to configure or query the component. |
OnThreeCommasMessage | Published or public property used to configure or query the component. |
OnThreeCommasPing | Published or public property used to configure or query the component. |
OnThreeCommasHTTPException | Published or public property used to configure or query the component. |
OnDisconnect | Published or public property used to configure or query the component. |
ThreeCommas | Published or public property used to configure or query the component. |
The principal public methods exposed by the component.
SubscribeSmartTrades() | Public procedure exposed by the component. |
SubscribeDeals() | Public procedure exposed by the component. |
Drop the component on a form, configure the properties below and activate it. The snippet that follows shows the typical Send Commands configuration sourced from the online help.
oRCON := TsgcLib_RCON.Create(nil); oRCON.RCON_Options.Host := '127.0.0.1'; oRCON.RCON_Options.Port := 25575; oRCON.RCON_Options.Password := 'test'; oRCON.Active := True; <br/> procedure OnAuthenticate(Sender: TObject; Authenticated: Boolean; const aPacket: TsgcRCON_Packet); begin if Authenticated then DoLog('#authenticated') else DoLog('#not authenticated'); end; <br/> procedure OnResponse(Sender: TObject; const aResponse: string; const aPacket: TsgcRCON_Packet); begin DoLog(aResponse); end;
TsgcLib_RCON oRCON = new TsgcLib_RCON(); oRCON->RCON_Options->Host = "127.0.0.1"; oRCON->RCON_Options->Port = 25575; oRCON->RCON_Options->Password = "test"; oRCON->Active = true; <br/> void OnAuthenticate(TObject *Sender, bool Authenticated, const TsgcRCON_Packet *aPacket) { if (Authenticated == true) { DoLog("#authenticated"); } else { DoLog("#not authenticated"); } } <br/> void OnResponse(Object *Sender, const string aResponse, const TsgcRCON_Packet *aPacket) { DoLog(aResponse); }
TsgcLib_RCON oRCON = new TsgcLib_RCON(); oRCON.RCON_Options.Host = "127.0.0.1"; oRCON.RCON_Options.Port = 25575; oRCON.RCON_Options.Password = "test"; oRCON.Active = true; <br/> void OnAuthenticate(TObject Sender, bool Authenticated, const TsgcRCON_Packet aPacket) { if (Authenticated == true) { DoLog("#authenticated"); } else { DoLog("#not authenticated"); } } <br/> void OnResponse(Object Sender, const string aResponse, const TsgcRCON_Packet aPacket) { DoLog(aResponse); }
The following scenarios are lifted verbatim from the online help. Each shows the configuration and method calls needed to drive the component through a specific real-world flow.
Telegram API allows you to send messages with buttons to request data from the user (this option is only available for bots).
oReplyMarkup := TsgcTelegramReplyMarkupShowKeyboard.Create; Try oReplyMarkup.AddButtonTypeRequestPhoneNumber('Give me your phone'); sgcTelegram.SendTextMessage('123456', 'Please provide the information below', nil, oReplyMarkup); Finally oReplyMarkup.Free; End;
oReplyMarkup = new TsgcTelegramReplyMarkupShowKeyboard(); oReplyMarkup->AddButtonTypeRequestPhoneNumber("Give me your phone"); sgcTelegram->SendTextMessage("123456", "Please provide the information below", null, oReplyMarkup); oReplyMarkup->Free();
oReplyMarkup = new TsgcTelegramReplyMarkupShowKeyboard(); oReplyMarkup.AddButtonTypeRequestPhoneNumber("Give me your phone"); sgcTelegram.SendTextMessage("123456", "Please provide the information below", null, oReplyMarkup);
If your bot supports inline mode, users can also send invoices to other chats via the bot, including to one-on-one chats with other users.
procedure SendInvoice; var oInvoice: TsgcTelegramSendInvoice; begin oInvoice := TsgcTelegramSendInvoice.Create; Try oInvoice.Title := 'Invoice Title Test'; oInvoice.Description := 'Description Invoice Test'; oInvoice.Invoice.Currency := 'EUR'; oInvoice.Invoice.Total := 800; oInvoice.Invoice.IsTest := True; oInvoice.Invoice.Payload := 'payload'; oInvoice.Invoice.ProviderToken := 'provider_token'; oInvoice.Invoice.ProviderData := 'provider_data'; sgcTelegram.SendInvoiceMessage('3284239872', oInvoice); Finally oInvoice.Free; End; end;
private void SendInvoice() { TsgcTelegramSendInvoice *oInvoice = new TsgcTelegramSendInvoice(); Try { oInvoice->Title = "Invoice Title Test"; oInvoice->Description = "Description Invoice Test"; oInvoice->Invoice->Currency = 'EUR'; oInvoice->Invoice->Total = 800; oInvoice->Invoice->IsTest = True; oInvoice->Invoice->Payload := "payload"; oInvoice->Invoice->ProviderToken := "provider_token"; oInvoice->Invoice->ProviderData := "provider_data"; sgcTelegram->SendInvoiceMessage("3284239872", oInvoice); __finally { oInvoice->Free(); } }
private void SendInvoice() { TsgcTelegramSendInvoice oInvoice = new TsgcTelegramSendInvoice(); oInvoice.Title = 'Invoice Title Test'; oInvoice.Description = 'Description Invoice Test'; oInvoice.Invoice.Currency = 'EUR'; oInvoice.Invoice.Total = 800; oInvoice.Invoice.IsTest = True; oInvoice.Invoice.Payload := "payload"; oInvoice.Invoice.ProviderToken := "provider_token"; oInvoice.Invoice.ProviderData := "provider_data"; sgcTelegram.SendInvoiceMessage("3284239872", oInvoice); }
Telegram API allows you to send messages with inline buttons to select options as an answer (this option is only available for bots).
oReplyMarkup := TsgcTelegramReplyMarkupInlineKeyboard.Create; Try oReplyMarkup.AddButtonTypeCallback('Yes', 'I like it'); oReplyMarkup.AddButtonTypeCallback('No', 'I hate it'); oReplyMarkup.AddButtonTypeUrl('Poll', 'https://www.yoursite.com/telegram/poll'); sgcTelegram.SendTextMessage('123456', 'Do you like the message?', oReplyMarkup); Finally oReplyMarkup.Free; End; procedure OnNewCallbackQuery(Sender: TObject; CallbackQuery: TsgcTelegramCallbackQuery); begin if CallbackQuery.PayloadData.Data = 'I like it' then ShowMessage('yes') else ShowMessage('no'); end;
TsgcTelegramReplyMarkupInlineKeyboard *oReplyMarkup = new TsgcTelegramReplyMarkupInlineKeyboard(); try { oReplyMarkup->AddButtonTypeCallback("Yes", "I like it"); oReplyMarkup->AddButtonTypeCallback("No", "I hate it"); oReplyMarkup->AddButtonTypeUrl("Poll", "https://www.yoursite.com/telegram/poll"); sgcTelegram->SendTextMessage("123456", "Do you like the message?", oReplyMarkup); } __finally { oReplyMarkup->Free(); } void OnNewCallbackQuery(TObject *Sender, TsgcTelegramCallbackQuery *CallbackQuery) { if (CallbackQuery->PayloadData->Data == "I like it") then { ShowMessage("yes") } else { ShowMessage("no"); } }
TsgcTelegramReplyMarkupInlineKeyboard oReplyMarkup = new TsgcTelegramReplyMarkupInlineKeyboard(); oReplyMarkup.AddButtonTypeCallback("Yes", "I like it"); oReplyMarkup.AddButtonTypeCallback("No", "I hate it"); oReplyMarkup.AddButtonTypeUrl("Poll", "https://www.yoursite.com/telegram/poll"); sgcTelegram.SendTextMessage("123456", "Do you like the message?", oReplyMarkup); void OnNewCallbackQuery(TObject Sender, TsgcTelegramCallbackQuery CallbackQuery) { if (CallbackQuery.PayloadData.Data == "I like it") then { MessageBox.Show("yes") } else { MessageBox.Show("no"); } }
To send and receive a first message using a test number, complete the following steps:
oClient := TsgcWhatsapp_Client.Create(nil); oClient.WhatsappOptions.PhoneNumberId := '107809351952205'; oClient.WhatsappOptions.Token := 'EAAO4OpgZAs98BAGj3nCFGr...ZB2t8mmLB2LRXJkte2Y5PMNh2'; oClient.SendTest('34605889421');
TsgcWhatsapp_Client oClient = new TsgcWhatsapp_Client(); oClient->WhatsappOptions->PhoneNumberId = "107809351952205"; oClient->WhatsappOptions->Token = "EAAO4OpgZAs98BAGj3nCFGr...ZB2t8mmLB2LRXJkte2Y5PMNh2"; oClient->SendTest("34605889421");
TsgcWhatsapp_Client oClient = new TsgcWhatsapp_Client(); oClient.WhatsappOptions.PhoneNumberId = "107809351952205"; oClient.WhatsappOptions.Token = "EAAO4OpgZAs98BAGj3nCFGr...ZB2t8mmLB2LRXJkte2Y5PMNh2"; oClient.SendTest("34605889421");
Every time a new message is received the event OnMessageReceived is called, where you can access to the content of the Message and mark the message as read.
procedure OnWhatsAppMessageReceived(Sender: TObject; const aMessage: TsgcWhatsApp_Receive_Message; var aMarkAsRead: Boolean); var vText: string; vTo: string; begin if aMessage.Contacts.Count > 0 then begin vTo := aMessage.Contacts.Contact[0].WaID; if aMessage.Messages.Count > 0 then begin if aMessage.Messages._Message[0]._Type = wapmrtText then begin vText := 'ECHO ==> ' + aMessage.Messages._Message[0].Text.Body; WhatsApp.SendMessageText(vTo, vText); aMarkAsRead := True; end; end; end; end;
void OnWhatsAppMessageReceived(TObject *Sender, const TsgcWhatsApp_Receive_Message *aMessage, ref bool aMarkAsRead) { if (aMessage->Contacts->Count > 0) { string vTo = aMessage->Contacts->Contact[0]->WaID; if (aMessage->Messages->Count > 0) { if (aMessage->Messages->_Message[0]->_Type = wapmrtText) { vText = "ECHO ==> " + aMessage->Messages->_Message[0]->Text->Body; WhatsApp->SendMessageText(vTo, vText); aMarkAsRead = true; } } } }
void OnWhatsAppMessageReceived(TsgcWhatsApp_Client Sender, TsgcWhatsApp_Receive_Message Message, ref bool MarkAsRead) { DoLog("Message Received: [" + Message.From + "] " + Message.Text); MarkAsRead = true; }
In order to configure a HTTP Proxy, first you must add the proxy to telegram configuration, to do this, just call AddProxyHTTP and if successful, a message will be returned with the new proxy added. Once the proxy has been added to the list, just call EnableProxy and pass the ID of the proxy received on the confirmation message.
Telegram.AddProxyHTTP('8.8.8.8', 8080, '', '', True); // ... read the confirmation message and save the ID of the proxy. Telegram.EnableProxy(2);
Telegram->AddProxyHTTP("8.8.8.8", 8080, "", "", true); // ... read the confirmation message and save the ID of the proxy. Telegram->EnableProxy(2);
Telegram.AddProxyHTTP("8.8.8.8", 8080, "", "", true); // ... read the confirmation message and save the ID of the proxy. Telegram.EnableProxy(2);
Every external claim links back to a primary source. The online-help references decode the canonical deep-link the company maintains for this component.
Demos\05.Crypto\10.ThreeCommas
.net\demos\05.Crypto\10.ThreeCommas